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 })
|
@Column({ nullable: true, default: null })
|
||||||
equipmentId?: string;
|
equipmentId?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
|
||||||
maintenanceId?: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ nullable: true, default: null })
|
||||||
vehicleId?: string;
|
vehicleId?: string;
|
||||||
|
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ nullable: true, default: null })
|
||||||
wearableId?: string;
|
wearableId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => equipment, {
|
@Column({ nullable: true, default: null })
|
||||||
|
maintenanceId?: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => equipment, (e) => e.reports, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
equipment?: equipment;
|
equipment?: equipment;
|
||||||
|
|
||||||
@ManyToOne(() => vehicle, {
|
@ManyToOne(() => vehicle, (v) => v.reports, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
vehicle?: vehicle;
|
vehicle?: vehicle;
|
||||||
|
|
||||||
@ManyToOne(() => wearable, {
|
@ManyToOne(() => wearable, (w) => w.reports, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
wearable?: wearable;
|
wearable?: wearable;
|
||||||
|
|
||||||
@ManyToOne(() => maintenance, {
|
@ManyToOne(() => maintenance, (m) => m.reports, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "SET NULL",
|
onDelete: "SET NULL",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||||
import { equipmentType } from "./equipmentType";
|
import { equipmentType } from "./equipmentType";
|
||||||
import { damageReport } from "../damageReport";
|
import { damageReport } from "../damageReport";
|
||||||
import { inspection } from "../inspection/inspection";
|
import { inspection } from "../inspection/inspection";
|
||||||
|
import { maintenance } from "../maintenance";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class equipment {
|
export class equipment {
|
||||||
|
@ -37,6 +38,9 @@ export class equipment {
|
||||||
@OneToMany(() => damageReport, (d) => d.equipment, { cascade: ["insert"] })
|
@OneToMany(() => damageReport, (d) => d.equipment, { cascade: ["insert"] })
|
||||||
reports: damageReport[];
|
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[];
|
inspections: inspection[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class equipmentType {
|
||||||
@OneToMany(() => equipment, (e) => e.equipmentType, { cascade: ["insert"] })
|
@OneToMany(() => equipment, (e) => e.equipmentType, { cascade: ["insert"] })
|
||||||
equipment: equipment[];
|
equipment: equipment[];
|
||||||
|
|
||||||
@OneToMany(() => inspectionPlan, (ip) => ip.equipmentType)
|
@OneToMany(() => inspectionPlan, (ip) => ip.equipmentType, { cascade: ["insert"] })
|
||||||
inspectionPlans: inspectionPlan[];
|
inspectionPlans: inspectionPlan[];
|
||||||
|
|
||||||
equipmentCount: number;
|
equipmentCount: number;
|
||||||
|
|
|
@ -77,6 +77,6 @@ export class inspection {
|
||||||
})
|
})
|
||||||
wearable: wearable;
|
wearable: wearable;
|
||||||
|
|
||||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection)
|
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection, { cascade: ["insert"] })
|
||||||
pointResults: inspectionPointResult[];
|
pointResults: inspectionPointResult[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,21 +30,21 @@ export class maintenance {
|
||||||
@Column({ nullable: true, default: null })
|
@Column({ nullable: true, default: null })
|
||||||
wearableId?: string;
|
wearableId?: string;
|
||||||
|
|
||||||
@ManyToOne(() => equipment, {
|
@ManyToOne(() => equipment, (e) => e.maintenances, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
equipment?: equipment;
|
equipment?: equipment;
|
||||||
|
|
||||||
@ManyToOne(() => vehicle, {
|
@ManyToOne(() => vehicle, (v) => v.maintenances, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
})
|
})
|
||||||
vehicle?: vehicle;
|
vehicle?: vehicle;
|
||||||
|
|
||||||
@ManyToOne(() => wearable, {
|
@ManyToOne(() => wearable, (w) => w.maintenances, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||||
import { vehicleType } from "./vehicleType";
|
import { vehicleType } from "./vehicleType";
|
||||||
import { damageReport } from "../damageReport";
|
import { damageReport } from "../damageReport";
|
||||||
import { inspection } from "../inspection/inspection";
|
import { inspection } from "../inspection/inspection";
|
||||||
|
import { maintenance } from "../maintenance";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class vehicle {
|
export class vehicle {
|
||||||
|
@ -37,6 +38,9 @@ export class vehicle {
|
||||||
@OneToMany(() => damageReport, (d) => d.vehicle, { cascade: ["insert"] })
|
@OneToMany(() => damageReport, (d) => d.vehicle, { cascade: ["insert"] })
|
||||||
reports: damageReport[];
|
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[];
|
inspections: inspection[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class vehicleType {
|
||||||
@OneToMany(() => vehicle, (e) => e.vehicleType, { cascade: ["insert"] })
|
@OneToMany(() => vehicle, (e) => e.vehicleType, { cascade: ["insert"] })
|
||||||
vehicle: vehicle[];
|
vehicle: vehicle[];
|
||||||
|
|
||||||
@OneToMany(() => inspectionPlan, (ip) => ip.vehicleType)
|
@OneToMany(() => inspectionPlan, (ip) => ip.vehicleType, { cascade: ["insert"] })
|
||||||
inspectionPlans: inspectionPlan[];
|
inspectionPlans: inspectionPlan[];
|
||||||
|
|
||||||
vehicleCount: number;
|
vehicleCount: number;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { wearableType } from "./wearableType";
|
||||||
import { damageReport } from "../damageReport";
|
import { damageReport } from "../damageReport";
|
||||||
import { member } from "../../club/member/member";
|
import { member } from "../../club/member/member";
|
||||||
import { inspection } from "../inspection/inspection";
|
import { inspection } from "../inspection/inspection";
|
||||||
|
import { maintenance } from "../maintenance";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class wearable {
|
export class wearable {
|
||||||
|
@ -48,6 +49,9 @@ export class wearable {
|
||||||
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
@OneToMany(() => damageReport, (d) => d.wearable, { cascade: ["insert"] })
|
||||||
reports: damageReport[];
|
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[];
|
inspections: inspection[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class wearableType {
|
||||||
@OneToMany(() => wearable, (e) => e.wearableType, { cascade: ["insert"] })
|
@OneToMany(() => wearable, (e) => e.wearableType, { cascade: ["insert"] })
|
||||||
wearable: wearable[];
|
wearable: wearable[];
|
||||||
|
|
||||||
@OneToMany(() => inspectionPlan, (ip) => ip.wearableType)
|
@OneToMany(() => inspectionPlan, (ip) => ip.wearableType, { cascade: ["insert"] })
|
||||||
inspectionPlans: inspectionPlan[];
|
inspectionPlans: inspectionPlan[];
|
||||||
|
|
||||||
wearableCount: number;
|
wearableCount: number;
|
||||||
|
|
|
@ -8,7 +8,6 @@ import DatabaseActionException from "../exceptions/databaseActionException";
|
||||||
import { availableTemplates } from "../type/templateTypes";
|
import { availableTemplates } from "../type/templateTypes";
|
||||||
import SettingHelper from "./settingsHelper";
|
import SettingHelper from "./settingsHelper";
|
||||||
import { LoginRoutineEnum } from "../enums/loginRoutineEnum";
|
import { LoginRoutineEnum } from "../enums/loginRoutineEnum";
|
||||||
import { education } from "../entity/configuration/education";
|
|
||||||
|
|
||||||
export type BackupSection =
|
export type BackupSection =
|
||||||
| "member"
|
| "member"
|
||||||
|
@ -21,7 +20,9 @@ export type BackupSection =
|
||||||
| "template"
|
| "template"
|
||||||
| "user"
|
| "user"
|
||||||
| "webapi"
|
| "webapi"
|
||||||
| "settings";
|
| "settings"
|
||||||
|
| "unitBase"
|
||||||
|
| "unitInstances";
|
||||||
|
|
||||||
export type BackupSectionRefered = {
|
export type BackupSectionRefered = {
|
||||||
[key in BackupSection]?: Array<string>;
|
[key in BackupSection]?: Array<string>;
|
||||||
|
@ -35,7 +36,7 @@ export type BackupFileContentSection = Array<any> | { [key: string]: Array<any>
|
||||||
export default abstract class BackupHelper {
|
export default abstract class BackupHelper {
|
||||||
// ! Order matters because of foreign keys
|
// ! Order matters because of foreign keys
|
||||||
private static readonly backupSection: Array<{ type: BackupSection; orderOnInsert: number; orderOnClear: number }> = [
|
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: "memberBase", orderOnInsert: 1, orderOnClear: 3 }, // CLEAR depends on member
|
||||||
{ type: "protocol", orderOnInsert: 3, orderOnClear: 1 }, // INSERT 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
|
{ 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: "user", orderOnInsert: 1, orderOnClear: 1 },
|
||||||
{ type: "webapi", orderOnInsert: 1, orderOnClear: 1 },
|
{ type: "webapi", orderOnInsert: 1, orderOnClear: 1 },
|
||||||
{ type: "settings", 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 = {
|
private static readonly backupSectionRefered: BackupSectionRefered = {
|
||||||
|
@ -83,6 +86,8 @@ export default abstract class BackupHelper {
|
||||||
user: ["user", "user_permission", "role", "role_permission", "invite"],
|
user: ["user", "user_permission", "role", "role_permission", "invite"],
|
||||||
webapi: ["webapi", "webapi_permission"],
|
webapi: ["webapi", "webapi_permission"],
|
||||||
settings: ["setting"],
|
settings: ["setting"],
|
||||||
|
unitBase: ["equipment_type", "vehicle_type", "wearable_type"],
|
||||||
|
unitInstances: ["equipment", "vehicle", "wearable"],
|
||||||
};
|
};
|
||||||
|
|
||||||
private static transactionManager: EntityManager;
|
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))) {
|
for (const section of sections.filter((s) => Object.keys(backup).includes(s.type))) {
|
||||||
let refered = this.backupSectionRefered[section.type];
|
let refered = this.backupSectionRefered[section.type];
|
||||||
for (const ref of refered) {
|
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();
|
return await this.getWebapi();
|
||||||
case "settings":
|
case "settings":
|
||||||
return await this.getSettings();
|
return await this.getSettings();
|
||||||
|
case "unitBase":
|
||||||
|
return await this.getUnitBase();
|
||||||
|
case "unitInstances":
|
||||||
|
return await this.getUnitInstances();
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -490,6 +499,27 @@ export default abstract class BackupHelper {
|
||||||
.select(["setting.topic", "setting.key", "setting.value"])
|
.select(["setting.topic", "setting.key", "setting.value"])
|
||||||
.getMany();
|
.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(
|
private static async setSectionData(
|
||||||
section: BackupSection,
|
section: BackupSection,
|
||||||
|
@ -507,6 +537,8 @@ export default abstract class BackupHelper {
|
||||||
if (section == "user" && !Array.isArray(data)) await this.setUser(data);
|
if (section == "user" && !Array.isArray(data)) await this.setUser(data);
|
||||||
if (section == "webapi" && Array.isArray(data)) await this.setWebapi(data);
|
if (section == "webapi" && Array.isArray(data)) await this.setWebapi(data);
|
||||||
if (section == "settings" && Array.isArray(data)) await this.setSettings(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> {
|
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> {
|
private static async setSettings(data: Array<any>): Promise<void> {
|
||||||
await this.transactionManager.getRepository("setting").save(data);
|
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