unit/#102-base-management #121
10 changed files with 85 additions and 21 deletions
|
@ -30,37 +30,37 @@ export class damageReport {
|
|||
@Column({ nullable: true, default: null })
|
||||
equipmentId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
maintenanceId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
vehicleId?: string;
|
||||
|
||||
@Column({ nullable: true, default: null })
|
||||
wearableId?: string;
|
||||
|
||||
@ManyToOne(() => equipment, {
|
||||
@Column({ nullable: true, default: null })
|
||||
maintenanceId?: string;
|
||||
|
||||
@ManyToOne(() => equipment, (e) => e.reports, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
equipment?: equipment;
|
||||
|
||||
@ManyToOne(() => vehicle, {
|
||||
@ManyToOne(() => vehicle, (v) => v.reports, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle?: vehicle;
|
||||
|
||||
@ManyToOne(() => wearable, {
|
||||
@ManyToOne(() => wearable, (w) => w.reports, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
wearable?: wearable;
|
||||
|
||||
@ManyToOne(() => maintenance, {
|
||||
@ManyToOne(() => maintenance, (m) => m.reports, {
|
||||
nullable: true,
|
||||
onDelete: "SET NULL",
|
||||
onUpdate: "RESTRICT",
|
||||
|
|
|
@ -3,6 +3,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
|||
import { equipmentType } from "./equipmentType";
|
||||
import { damageReport } from "../damageReport";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
import { maintenance } from "../maintenance";
|
||||
|
||||
@Entity()
|
||||
export class equipment {
|
||||
|
@ -37,6 +38,9 @@ export class equipment {
|
|||
@OneToMany(() => damageReport, (d) => d.equipment, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.equipment)
|
||||
@OneToMany(() => maintenance, (m) => m.equipment, { cascade: ["insert"] })
|
||||
maintenances: maintenance[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.equipment, { cascade: ["insert"] })
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ export class equipmentType {
|
|||
@OneToMany(() => equipment, (e) => e.equipmentType, { cascade: ["insert"] })
|
||||
equipment: equipment[];
|
||||
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.equipmentType)
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.equipmentType, { cascade: ["insert"] })
|
||||
inspectionPlans: inspectionPlan[];
|
||||
|
||||
equipmentCount: number;
|
||||
|
|
|
@ -77,6 +77,6 @@ export class inspection {
|
|||
})
|
||||
wearable: wearable;
|
||||
|
||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection)
|
||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection, { cascade: ["insert"] })
|
||||
pointResults: inspectionPointResult[];
|
||||
}
|
||||
|
|
|
@ -30,21 +30,21 @@ export class maintenance {
|
|||
@Column({ nullable: true, default: null })
|
||||
wearableId?: string;
|
||||
|
||||
@ManyToOne(() => equipment, {
|
||||
@ManyToOne(() => equipment, (e) => e.maintenances, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
equipment?: equipment;
|
||||
|
||||
@ManyToOne(() => vehicle, {
|
||||
@ManyToOne(() => vehicle, (v) => v.maintenances, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle?: vehicle;
|
||||
|
||||
@ManyToOne(() => wearable, {
|
||||
@ManyToOne(() => wearable, (w) => w.maintenances, {
|
||||
nullable: true,
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
|
|
|
@ -3,6 +3,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
|||
import { vehicleType } from "./vehicleType";
|
||||
import { damageReport } from "../damageReport";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
import { maintenance } from "../maintenance";
|
||||
|
||||
@Entity()
|
||||
export class vehicle {
|
||||
|
@ -37,6 +38,9 @@ export class vehicle {
|
|||
@OneToMany(() => damageReport, (d) => d.vehicle, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.vehicle)
|
||||
@OneToMany(() => maintenance, (m) => m.vehicle, { cascade: ["insert"] })
|
||||
maintenances: maintenance[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.vehicle, { cascade: ["insert"] })
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ export class vehicleType {
|
|||
@OneToMany(() => vehicle, (e) => e.vehicleType, { cascade: ["insert"] })
|
||||
vehicle: vehicle[];
|
||||
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.vehicleType)
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.vehicleType, { cascade: ["insert"] })
|
||||
inspectionPlans: inspectionPlan[];
|
||||
|
||||
vehicleCount: number;
|
||||
|
|
|
@ -4,6 +4,7 @@ import { wearableType } from "./wearableType";
|
|||
import { damageReport } from "../damageReport";
|
||||
import { member } from "../../club/member/member";
|
||||
import { inspection } from "../inspection/inspection";
|
||||
import { maintenance } from "../maintenance";
|
||||
|
||||
@Entity()
|
||||
export class wearable {
|
||||
|
@ -48,6 +49,9 @@ export class wearable {
|
|||
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
||||
reports: damageReport[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.wearable)
|
||||
@OneToMany(() => maintenance, (m) => m.wearable, { cascade: ["insert"] })
|
||||
maintenances: maintenance[];
|
||||
|
||||
@OneToMany(() => inspection, (i) => i.wearable, { cascade: ["insert"] })
|
||||
inspections: inspection[];
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ export class wearableType {
|
|||
@OneToMany(() => wearable, (e) => e.wearableType, { cascade: ["insert"] })
|
||||
wearable: wearable[];
|
||||
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.wearableType)
|
||||
@OneToMany(() => inspectionPlan, (ip) => ip.wearableType, { cascade: ["insert"] })
|
||||
inspectionPlans: inspectionPlan[];
|
||||
|
||||
wearableCount: number;
|
||||
|
|
|
@ -8,7 +8,6 @@ import DatabaseActionException from "../exceptions/databaseActionException";
|
|||
import { availableTemplates } from "../type/templateTypes";
|
||||
import SettingHelper from "./settingsHelper";
|
||||
import { LoginRoutineEnum } from "../enums/loginRoutineEnum";
|
||||
import { education } from "../entity/configuration/education";
|
||||
|
||||
export type BackupSection =
|
||||
| "member"
|
||||
|
@ -21,7 +20,9 @@ export type BackupSection =
|
|||
| "template"
|
||||
| "user"
|
||||
| "webapi"
|
||||
| "settings";
|
||||
| "settings"
|
||||
| "unitBase"
|
||||
| "unitInstances";
|
||||
|
||||
export type BackupSectionRefered = {
|
||||
[key in BackupSection]?: Array<string>;
|
||||
|
@ -35,7 +36,7 @@ export type BackupFileContentSection = Array<any> | { [key: string]: Array<any>
|
|||
export default abstract class BackupHelper {
|
||||
// ! Order matters because of foreign keys
|
||||
private static readonly backupSection: Array<{ type: BackupSection; orderOnInsert: number; orderOnClear: number }> = [
|
||||
{ type: "member", orderOnInsert: 2, orderOnClear: 2 }, // CLEAR depends on protcol INSERT depends on Base
|
||||
{ type: "member", orderOnInsert: 2, orderOnClear: 2 }, // CLEAR depends on protcol and wearables INSERT depends on Base
|
||||
{ type: "memberBase", orderOnInsert: 1, orderOnClear: 3 }, // CLEAR depends on member
|
||||
{ type: "protocol", orderOnInsert: 3, orderOnClear: 1 }, // INSERT depends on member
|
||||
{ type: "newsletter", orderOnInsert: 3, orderOnClear: 1 }, // INSERT depends on member & query & calendar
|
||||
|
@ -46,6 +47,8 @@ export default abstract class BackupHelper {
|
|||
{ type: "user", orderOnInsert: 1, orderOnClear: 1 },
|
||||
{ type: "webapi", orderOnInsert: 1, orderOnClear: 1 },
|
||||
{ type: "settings", orderOnInsert: 1, orderOnClear: 1 },
|
||||
{ type: "unitBase", orderOnInsert: 1, orderOnClear: 2 },
|
||||
{ type: "unitInstances", orderOnInsert: 3, orderOnClear: 1 }, // INSERT depends on member in wearable
|
||||
];
|
||||
|
||||
private static readonly backupSectionRefered: BackupSectionRefered = {
|
||||
|
@ -83,6 +86,8 @@ export default abstract class BackupHelper {
|
|||
user: ["user", "user_permission", "role", "role_permission", "invite"],
|
||||
webapi: ["webapi", "webapi_permission"],
|
||||
settings: ["setting"],
|
||||
unitBase: ["equipment_type", "vehicle_type", "wearable_type"],
|
||||
unitInstances: ["equipment", "vehicle", "wearable"],
|
||||
};
|
||||
|
||||
private static transactionManager: EntityManager;
|
||||
|
@ -162,7 +167,7 @@ export default abstract class BackupHelper {
|
|||
for (const section of sections.filter((s) => Object.keys(backup).includes(s.type))) {
|
||||
let refered = this.backupSectionRefered[section.type];
|
||||
for (const ref of refered) {
|
||||
await this.transactionManager.getRepository(ref).delete({});
|
||||
await this.transactionManager.getRepository(ref).deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,6 +234,10 @@ export default abstract class BackupHelper {
|
|||
return await this.getWebapi();
|
||||
case "settings":
|
||||
return await this.getSettings();
|
||||
case "unitBase":
|
||||
return await this.getUnitBase();
|
||||
case "unitInstances":
|
||||
return await this.getUnitInstances();
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
@ -490,6 +499,27 @@ export default abstract class BackupHelper {
|
|||
.select(["setting.topic", "setting.key", "setting.value"])
|
||||
.getMany();
|
||||
}
|
||||
private static async getUnitBase(): Promise<{ [key: string]: Array<any> }> {
|
||||
return {
|
||||
equipment_type: await dataSource.getRepository("equipment_type").find(),
|
||||
vehicle_type: await dataSource.getRepository("vehicle_type").find(),
|
||||
wearable_type: await dataSource.getRepository("wearable_type").find(),
|
||||
inspection_plan: await dataSource.getRepository("inspection_plan").find(),
|
||||
inspection_versioned_plan: await dataSource.getRepository("inspection_versioned_plan").find(),
|
||||
inspection_point: await dataSource.getRepository("inspection_point").find(),
|
||||
};
|
||||
}
|
||||
private static async getUnitInstances(): Promise<{ [key: string]: Array<any> }> {
|
||||
return {
|
||||
equipment: await dataSource.getRepository("equipment").find(),
|
||||
vehicle: await dataSource.getRepository("vehicle").find(),
|
||||
wearable: await dataSource.getRepository("wearable").find(),
|
||||
maintenance: await dataSource.getRepository("maintenance").find(),
|
||||
damage_report: await dataSource.getRepository("damage_report").find(),
|
||||
inspection: await dataSource.getRepository("inspection").find(),
|
||||
inspection_point_result: await dataSource.getRepository("inspection_point_result").find(),
|
||||
};
|
||||
}
|
||||
|
||||
private static async setSectionData(
|
||||
section: BackupSection,
|
||||
|
@ -507,6 +537,8 @@ export default abstract class BackupHelper {
|
|||
if (section == "user" && !Array.isArray(data)) await this.setUser(data);
|
||||
if (section == "webapi" && Array.isArray(data)) await this.setWebapi(data);
|
||||
if (section == "settings" && Array.isArray(data)) await this.setSettings(data);
|
||||
if (section == "unitBase" && !Array.isArray(data)) await this.setUnitBase(data);
|
||||
if (section == "unitInstances" && !Array.isArray(data)) await this.setUnitInstances(data);
|
||||
}
|
||||
|
||||
private static async setMemberData(data: Array<any>): Promise<void> {
|
||||
|
@ -870,4 +902,24 @@ export default abstract class BackupHelper {
|
|||
private static async setSettings(data: Array<any>): Promise<void> {
|
||||
await this.transactionManager.getRepository("setting").save(data);
|
||||
}
|
||||
private static async setUnitBase(data: { [key: string]: Array<any> }): Promise<void> {
|
||||
await this.transactionManager.getRepository("equipment_type").save(data["equipment_type"]);
|
||||
await this.transactionManager.getRepository("vehicle_type").save(data["vehicle_type"]);
|
||||
await this.transactionManager.getRepository("wearable_type").save(data["wearable_type"]);
|
||||
|
||||
await this.transactionManager.getRepository("inspection_plan").save(data["inspection_plan"]);
|
||||
await this.transactionManager.getRepository("inspection_versioned_plan").save(data["inspection_versioned_plan"]);
|
||||
await this.transactionManager.getRepository("inspection_point").save(data["inspection_point"]);
|
||||
}
|
||||
private static async setUnitInstances(data: { [key: string]: Array<any> }): Promise<void> {
|
||||
await this.transactionManager.getRepository("equipment").save(data["equipment"]);
|
||||
await this.transactionManager.getRepository("vehicle").save(data["vehicle"]);
|
||||
await this.transactionManager.getRepository("wearable").save(data["wearable"]);
|
||||
|
||||
await this.transactionManager.getRepository("damage_report").save(data["damage_report"]);
|
||||
await this.transactionManager.getRepository("maintenance").save(data["maintenance"]);
|
||||
|
||||
await this.transactionManager.getRepository("inspection").save(data["inspection"]);
|
||||
await this.transactionManager.getRepository("inspection_point_result").save(data["inspection_point_result"]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue