default arrays and none existant data inserts
This commit is contained in:
parent
5701313228
commit
a91b723f04
1 changed files with 68 additions and 14 deletions
|
@ -20,7 +20,10 @@ export type BackupSectionRefered = {
|
|||
[key in BackupSection]?: Array<string>;
|
||||
};
|
||||
|
||||
export type BackupFileContent = { [key in BackupSection]?: BackupFileContentSection } & { collectIds: boolean };
|
||||
export type BackupFileContent = { [key in BackupSection]?: BackupFileContentSection } & {
|
||||
collectIds: boolean;
|
||||
version: 1;
|
||||
};
|
||||
export type BackupFileContentSection = Array<any> | { [key: string]: Array<any> };
|
||||
|
||||
export default abstract class BackupHelper {
|
||||
|
@ -87,7 +90,7 @@ export default abstract class BackupHelper {
|
|||
filename = new Date().toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
let json: BackupFileContent = { collectIds };
|
||||
let json: BackupFileContent = { collectIds, version: 1 };
|
||||
for (const section of this.backupSection) {
|
||||
json[section.type] = await this.getSectionData(section.type, collectIds);
|
||||
}
|
||||
|
@ -424,6 +427,30 @@ export default abstract class BackupHelper {
|
|||
}
|
||||
|
||||
private static async setMemberData(data: Array<any>): Promise<void> {
|
||||
await this.setMemberBase({
|
||||
award: data
|
||||
.map((d) => d.awards.map((c: any) => c.award))
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined })),
|
||||
communication_type: data
|
||||
.map((d) => d.communications.map((c: any) => c.type))
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined })),
|
||||
executive_position: data
|
||||
.map((d) => d.positions.map((c: any) => c.executivePosition))
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined })),
|
||||
membership_status: data
|
||||
.map((d) => d.memberships.map((c: any) => c.status))
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined })),
|
||||
salutation: data.map((d) => d.salutation).map((d) => ({ ...d, id: undefined })),
|
||||
qualification: data
|
||||
.map((d) => d.qualifications.map((c: any) => c.qualification))
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined })),
|
||||
});
|
||||
|
||||
let salutation = await this.transactionManager.getRepository("salutation").find();
|
||||
let communication = await this.transactionManager.getRepository("communication_type").find();
|
||||
let membership = await this.transactionManager.getRepository("membership_status").find();
|
||||
|
@ -479,42 +506,42 @@ export default abstract class BackupHelper {
|
|||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("award")
|
||||
.values(data["award"])
|
||||
.values(data?.["award"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("communication_type")
|
||||
.values(data["communication_type"])
|
||||
.values(data?.["communication_type"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("executive_position")
|
||||
.values(data["executive_position"])
|
||||
.values(data?.["executive_position"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("membership_status")
|
||||
.values(data["membership_status"])
|
||||
.values(data?.["membership_status"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("salutation")
|
||||
.values(data["salutation"])
|
||||
.values(data?.["salutation"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("qualification")
|
||||
.values(data["qualification"])
|
||||
.values(data?.["qualification"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
}
|
||||
|
@ -543,6 +570,8 @@ export default abstract class BackupHelper {
|
|||
await this.transactionManager.getRepository("protocol").save(dataWithMappedIds);
|
||||
}
|
||||
private static async setNewsletter(data: Array<any>, collectedIds: boolean): Promise<void> {
|
||||
await this.setQueryStore(data.map((d) => d.recipientsByQueryId).map((d) => ({ ...d, id: undefined })));
|
||||
|
||||
let queries = await this.transactionManager.getRepository("query").find();
|
||||
let members = await this.transactionManager.getRepository("member").find();
|
||||
let dataWithMappedIds = data.map((d) => ({
|
||||
|
@ -572,6 +601,10 @@ export default abstract class BackupHelper {
|
|||
await this.transactionManager.getRepository("newsletter").save(dataWithMappedIds);
|
||||
}
|
||||
private static async setNewsletterConfig(data: Array<any>): Promise<void> {
|
||||
await this.setMemberBase({
|
||||
communication_type: data.map((d) => d.comType).map((d) => ({ ...d, id: undefined })),
|
||||
});
|
||||
|
||||
let types = await this.transactionManager.getRepository("communication_type").find();
|
||||
let dataWithMappedIds = data.map((d) => ({
|
||||
...d,
|
||||
|
@ -583,9 +616,18 @@ export default abstract class BackupHelper {
|
|||
await this.transactionManager.getRepository("newsletter_config").save(dataWithMappedIds);
|
||||
}
|
||||
private static async setCalendar(data: { [key: string]: Array<any> }): Promise<void> {
|
||||
await this.transactionManager.getRepository("calendar_type").save(data["calendar_type"]);
|
||||
let usedTypes = (data?.["calendar"] ?? []).map((d) => d.type).map((d) => ({ ...d, id: undefined }));
|
||||
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("award")
|
||||
.values([...(data?.["calendar_type"] ?? []), ...usedTypes])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
let types = await this.transactionManager.getRepository("calendar_type").find();
|
||||
let dataWithMappedIds = data["calendar"].map((c) => ({
|
||||
let dataWithMappedIds = (data?.["calendar"] ?? []).map((c) => ({
|
||||
...c,
|
||||
type: {
|
||||
...c.type,
|
||||
|
@ -602,21 +644,33 @@ export default abstract class BackupHelper {
|
|||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("template")
|
||||
.values(data["template"])
|
||||
.values(data?.["template"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("template_usage")
|
||||
.values(data["template_usage"])
|
||||
.values(data?.["template_usage"] ?? [])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
}
|
||||
private static async setUser(data: { [key: string]: Array<any> }): Promise<void> {
|
||||
await this.transactionManager.createQueryBuilder().insert().into("role").values(data["role"]).orIgnore().execute();
|
||||
let usedRoles = (data?.["user"] ?? [])
|
||||
.map((d) => d.roles)
|
||||
.flat()
|
||||
.map((d) => ({ ...d, id: undefined }));
|
||||
|
||||
await this.transactionManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into("role")
|
||||
.values([...(data?.["role"] ?? []), ...usedRoles])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
let roles = await this.transactionManager.getRepository("role").find();
|
||||
let dataWithMappedIds = data["user"].map((u) => ({
|
||||
let dataWithMappedIds = (data?.["user"] ?? []).map((u) => ({
|
||||
...u,
|
||||
roles: u.roles.map((r: any) => ({
|
||||
...r,
|
||||
|
|
Loading…
Reference in a new issue