schema update

This commit is contained in:
Julian Krauser 2025-07-25 11:04:53 +02:00
parent 922c6b7df3
commit 9b38c6a5e9
29 changed files with 184 additions and 43 deletions

View file

@ -13,6 +13,7 @@ export interface UpdateDamageReportCommand {
id: string; id: string;
status: string; status: string;
noteByWorker: string; noteByWorker: string;
user: { id: string; firstname: string; lastname: string };
done: boolean; done: boolean;
} }

View file

@ -54,7 +54,11 @@ export default abstract class DamageReportCommandHandler {
.set({ .set({
status: updateDamageReport.status, status: updateDamageReport.status,
noteByWorker: updateDamageReport.noteByWorker, noteByWorker: updateDamageReport.noteByWorker,
done: updateDamageReport.done, closedAt: updateDamageReport.done ? new Date() : null,
closedById: updateDamageReport.done ? updateDamageReport.user.id : null,
closedByString: updateDamageReport.done
? `${updateDamageReport.user.firstname} ${updateDamageReport.user.lastname}`
: null,
}) })
.where("id = :id", { id: updateDamageReport.id }) .where("id = :id", { id: updateDamageReport.id })
.execute() .execute()

View file

@ -14,6 +14,7 @@ export interface UpdateInspectionCommand {
export interface FinishInspectionCommand { export interface FinishInspectionCommand {
id: string; id: string;
user: { id: string; firstname: string; lastname: string };
} }
export interface DeleteInspectionCommand { export interface DeleteInspectionCommand {

View file

@ -96,6 +96,8 @@ export default abstract class InspectionCommandHandler {
.update(inspection) .update(inspection)
.set({ .set({
finishedAt: new Date(), finishedAt: new Date(),
finishedById: finishInspection.user.id,
finishedByString: `${finishInspection.user.firstname} ${finishInspection.user.lastname}`,
}) })
.where("id = :id", { id: finishInspection.id }) .where("id = :id", { id: finishInspection.id })
.execute() .execute()

View file

@ -17,6 +17,7 @@ export interface UpdateRepairCommand {
export interface UpdateRepairStatusCommand { export interface UpdateRepairStatusCommand {
id: string; id: string;
status: string; status: string;
user: { id: string; firstname: string; lastname: string };
done: boolean; done: boolean;
} }

View file

@ -86,6 +86,8 @@ export default abstract class RepairCommandHandler {
.set({ .set({
status: updateRepair.status, status: updateRepair.status,
finishedAt: updateRepair.done ? new Date() : null, finishedAt: updateRepair.done ? new Date() : null,
finishedById: updateRepair.done ? updateRepair.user.id : null,
finishedByString: updateRepair.done ? `${updateRepair.user.firstname} ${updateRepair.user.lastname}` : null,
}) })
.where("id = :id", { id: updateRepair.id }) .where("id = :id", { id: updateRepair.id })
.execute() .execute()

View file

@ -157,6 +157,11 @@ export async function updateDamageReportById(req: Request, res: Response): Promi
status, status,
noteByWorker, noteByWorker,
done, done,
user: {
id: req.userId,
firstname: req.firstname,
lastname: req.lastname,
},
}; };
await DamageReportCommandHandler.update(updateDamageReport); await DamageReportCommandHandler.update(updateDamageReport);

View file

@ -13,12 +13,10 @@ import ForbiddenRequestException from "../../../exceptions/forbiddenRequestExcep
import { CreateOrUpdateInspectionPointResultCommand } from "../../../command/unit/inspection/inspectionPointResultCommand"; import { CreateOrUpdateInspectionPointResultCommand } from "../../../command/unit/inspection/inspectionPointResultCommand";
import InspectionPointResultCommandHandler from "../../../command/unit/inspection/inspectionPointResultCommandHandler"; import InspectionPointResultCommandHandler from "../../../command/unit/inspection/inspectionPointResultCommandHandler";
import { InspectionPointEnum } from "../../../enums/inspectionEnum"; import { InspectionPointEnum } from "../../../enums/inspectionEnum";
import multer from "multer";
import { FileSystemHelper } from "../../../helpers/fileSystemHelper"; import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
import { PdfExport } from "../../../helpers/pdfExport"; import { PdfExport } from "../../../helpers/pdfExport";
import { PDFDocument } from "pdf-lib"; import { PDFDocument } from "pdf-lib";
import sharp from "sharp"; import sharp from "sharp";
import InspectionPointService from "../../../service/unit/inspection/inspectionPointService";
import InspectionPointResultService from "../../../service/unit/inspection/inspectionPointResultService"; import InspectionPointResultService from "../../../service/unit/inspection/inspectionPointResultService";
/** /**
@ -270,7 +268,7 @@ export async function finishInspection(req: Request, res: Response): Promise<any
let formattedInspection = InspectionFactory.mapToSingle(inspection); let formattedInspection = InspectionFactory.mapToSingle(inspection);
let title = `Prüf-Ausdruck_${[formattedInspection.related.code ?? "", formattedInspection.related.name].join("_")}_${ let title = `Prüf-Ausdruck_${[formattedInspection.related.code ?? "", formattedInspection.related.name].join("_")}_${
formattedInspection.inspectionPlan.title formattedInspection.inspectionPlan.title
}_${new Date(formattedInspection.finished ?? "").toLocaleDateString("de-de")}`; }_${new Date(formattedInspection.finishedAt ?? "").toLocaleDateString("de-de")}`;
let inspectionPoints = []; let inspectionPoints = [];
for (const ip of formattedInspection.inspectionVersionedPlan.inspectionPoints.sort( for (const ip of formattedInspection.inspectionVersionedPlan.inspectionPoints.sort(
@ -305,7 +303,7 @@ export async function finishInspection(req: Request, res: Response): Promise<any
inspector: `${req.lastname}, ${req.firstname}`, inspector: `${req.lastname}, ${req.firstname}`,
context: formattedInspection.context || "---", context: formattedInspection.context || "---",
createdAt: formattedInspection.created, createdAt: formattedInspection.created,
finishedAt: formattedInspection.finished ?? new Date(), finishedAt: formattedInspection.finishedAt ?? new Date(),
nextInspection: formattedInspection.nextInspection, nextInspection: formattedInspection.nextInspection,
related: formattedInspection.related, related: formattedInspection.related,
plan: formattedInspection.inspectionPlan, plan: formattedInspection.inspectionPlan,
@ -363,6 +361,11 @@ export async function finishInspection(req: Request, res: Response): Promise<any
let finish: FinishInspectionCommand = { let finish: FinishInspectionCommand = {
id: inspectionId, id: inspectionId,
user: {
id: req.userId,
firstname: req.firstname,
lastname: req.lastname,
},
}; };
await InspectionCommandHandler.finish(finish); await InspectionCommandHandler.finish(finish);

View file

@ -17,7 +17,7 @@ export async function getAllMaintenancesByStatus(req: Request, res: Response): P
let count = parseInt((req.query.count as string) ?? "25"); let count = parseInt((req.query.count as string) ?? "25");
let noLimit = req.query.noLimit === "true"; let noLimit = req.query.noLimit === "true";
let [maintenances, total] = await MaintenanceService.getAll(done, { offset, count, noLimit }); let [maintenances, total] = await MaintenanceService.getAllByDone(done, { offset, count, noLimit });
res.json({ res.json({
maintenances: MaintenanceFactory.mapToBase(maintenances), maintenances: MaintenanceFactory.mapToBase(maintenances),

View file

@ -24,7 +24,7 @@ export async function getAllRepairsByStatus(req: Request, res: Response): Promis
let count = parseInt((req.query.count as string) ?? "25"); let count = parseInt((req.query.count as string) ?? "25");
let noLimit = req.query.noLimit === "true"; let noLimit = req.query.noLimit === "true";
let [repairs, total] = await RepairService.getAll(done, { offset, count, noLimit }); let [repairs, total] = await RepairService.getAllByDone(done, { offset, count, noLimit });
res.json({ res.json({
repairs: RepairFactory.mapToBase(repairs), repairs: RepairFactory.mapToBase(repairs),
@ -161,6 +161,11 @@ export async function updateRepairStatusById(req: Request, res: Response): Promi
id: repairId, id: repairId,
status, status,
done, done,
user: {
id: req.userId,
firstname: req.firstname,
lastname: req.lastname,
},
}; };
await RepairCommandHandler.updateStatus(updateRepair); await RepairCommandHandler.updateStatus(updateRepair);

View file

@ -1,8 +1,10 @@
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { equipment } from "./equipment/equipment"; import { equipment } from "./equipment/equipment";
import { wearable } from "./wearable/wearable"; import { wearable } from "./wearable/wearable";
import { vehicle } from "./vehicle/vehicle"; import { vehicle } from "./vehicle/vehicle";
import { repair } from "./repair"; import { repair } from "./repair";
import { getTypeByORM } from "../../migrations/ormHelper";
import { user } from "../management/user";
@Entity() @Entity()
export class damageReport { export class damageReport {
@ -12,29 +14,40 @@ export class damageReport {
@CreateDateColumn() @CreateDateColumn()
reportedAt: Date; reportedAt: Date;
@Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null })
closedAt?: Date;
@Column({ nullable: true, default: null })
closedById?: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
closedByString?: string;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
status: string; status: string;
@Column({ type: "boolean", default: false })
done: boolean;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
title: string; title: string;
@Column({ type: "text" }) @Column({ type: "text" })
description: string; description: string;
@Column({ type: "text" }) @Column({ type: "text", nullable: true, default: null })
location: string; location: string;
@Column({ type: "text" }) @Column({ type: "varchar", length: 255, nullable: true, default: null })
reportedBy: string;
@Column({ type: "text", nullable: true, default: null })
noteByReporter: string; noteByReporter: string;
@Column({ type: "text" }) @Column({ type: "text", nullable: true, default: null })
noteByWorker: string; noteByWorker: string;
@Column({ @Column({
type: "text", type: "text",
nullable: true,
default: null,
transformer: { transformer: {
from(value: string): Array<string> { from(value: string): Array<string> {
return (value ?? "").split(",").filter((i) => !!i); return (value ?? "").split(",").filter((i) => !!i);
@ -46,9 +59,6 @@ export class damageReport {
}) })
images: string[]; images: string[];
@Column({ type: "varchar", length: 255 })
reportedBy: string;
@Column({ nullable: true, default: null }) @Column({ nullable: true, default: null })
equipmentId?: string; equipmentId?: string;
@ -61,6 +71,13 @@ export class damageReport {
@Column({ nullable: true, default: null }) @Column({ nullable: true, default: null })
repairId?: string; repairId?: string;
@ManyToOne(() => user, {
nullable: true,
onDelete: "SET NULL",
onUpdate: "RESTRICT",
})
closedBy?: user;
@ManyToOne(() => equipment, (e) => e.reports, { @ManyToOne(() => equipment, (e) => e.reports, {
nullable: true, nullable: true,
onDelete: "CASCADE", onDelete: "CASCADE",

View file

@ -6,6 +6,7 @@ import { vehicle } from "../vehicle/vehicle";
import { equipment } from "../equipment/equipment"; import { equipment } from "../equipment/equipment";
import { inspectionPointResult } from "./inspectionPointResult"; import { inspectionPointResult } from "./inspectionPointResult";
import { wearable } from "../wearable/wearable"; import { wearable } from "../wearable/wearable";
import { user } from "../../management/user";
@Entity() @Entity()
export class inspection { export class inspection {
@ -18,9 +19,15 @@ export class inspection {
@CreateDateColumn() @CreateDateColumn()
createdAt: Date; createdAt: Date;
@Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null }) @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null })
finishedAt?: Date; finishedAt?: Date;
@Column({ nullable: true, default: null })
finishedById?: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
finishedByString?: string;
@Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null }) @Column({ type: getTypeByORM("date").type as ColumnType, nullable: true, default: null })
nextInspection?: Date; nextInspection?: Date;
@ -42,6 +49,13 @@ export class inspection {
@Column({ nullable: true, default: null }) @Column({ nullable: true, default: null })
wearableId?: string; wearableId?: string;
@ManyToOne(() => user, {
nullable: true,
onDelete: "SET NULL",
onUpdate: "RESTRICT",
})
finishedBy?: user;
@ManyToOne(() => inspectionPlan, { @ManyToOne(() => inspectionPlan, {
nullable: false, nullable: false,
onDelete: "RESTRICT", onDelete: "RESTRICT",

View file

@ -4,6 +4,7 @@ import { wearable } from "./wearable/wearable";
import { vehicle } from "./vehicle/vehicle"; import { vehicle } from "./vehicle/vehicle";
import { damageReport } from "./damageReport"; import { damageReport } from "./damageReport";
import { getTypeByORM } from "../../migrations/ormHelper"; import { getTypeByORM } from "../../migrations/ormHelper";
import { user } from "../management/user";
@Entity() @Entity()
export class maintenance { export class maintenance {
@ -16,6 +17,12 @@ export class maintenance {
@Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null }) @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null })
finishedAt?: Date; finishedAt?: Date;
@Column({ nullable: true, default: null })
finishedById?: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
finishedByString?: string;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
status: string; status: string;
@ -31,6 +38,13 @@ export class maintenance {
@Column({ nullable: true, default: null }) @Column({ nullable: true, default: null })
wearableId?: string; wearableId?: string;
@ManyToOne(() => user, {
nullable: true,
onDelete: "SET NULL",
onUpdate: "RESTRICT",
})
finishedBy?: user;
@ManyToOne(() => equipment, (e) => e.maintenances, { @ManyToOne(() => equipment, (e) => e.maintenances, {
nullable: true, nullable: true,
onDelete: "CASCADE", onDelete: "CASCADE",

View file

@ -4,6 +4,7 @@ import { wearable } from "./wearable/wearable";
import { vehicle } from "./vehicle/vehicle"; import { vehicle } from "./vehicle/vehicle";
import { damageReport } from "./damageReport"; import { damageReport } from "./damageReport";
import { getTypeByORM } from "../../migrations/ormHelper"; import { getTypeByORM } from "../../migrations/ormHelper";
import { user } from "../management/user";
@Entity() @Entity()
export class repair { export class repair {
@ -16,11 +17,14 @@ export class repair {
@Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null }) @Column({ type: getTypeByORM("datetime").type as ColumnType, nullable: true, default: null })
finishedAt?: Date; finishedAt?: Date;
@Column({ type: "varchar", length: 255 }) @Column({ nullable: true, default: null })
status: string; finishedById?: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
finishedByString?: string;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
responsible: string; status: string;
@Column({ type: "varchar", length: 255 }) @Column({ type: "varchar", length: 255 })
title: string; title: string;
@ -28,8 +32,13 @@ export class repair {
@Column({ type: "text" }) @Column({ type: "text" })
description: string; description: string;
@Column({ type: "varchar", length: 255, nullable: true, default: null })
responsible: string;
@Column({ @Column({
type: "text", type: "text",
nullable: true,
default: null,
transformer: { transformer: {
from(value: string): Array<string> { from(value: string): Array<string> {
return (value ?? "").split(",").filter((i) => !!i); return (value ?? "").split(",").filter((i) => !!i);
@ -53,6 +62,13 @@ export class repair {
@Column({ nullable: true, default: null }) @Column({ nullable: true, default: null })
wearableId?: string; wearableId?: string;
@ManyToOne(() => user, {
nullable: true,
onDelete: "SET NULL",
onUpdate: "RESTRICT",
})
finishedBy?: user;
@ManyToOne(() => equipment, (e) => e.maintenances, { @ManyToOne(() => equipment, (e) => e.maintenances, {
nullable: true, nullable: true,
onDelete: "CASCADE", onDelete: "CASCADE",

View file

@ -44,7 +44,8 @@ export default abstract class DamageReportFactory {
id: record.id, id: record.id,
reportedAt: record.reportedAt, reportedAt: record.reportedAt,
status: record.status, status: record.status,
done: record.done, closedAt: record.closedAt,
closedBy: record?.closedBy ? record.closedBy.firstname + " " + record.closedBy.lastname : record.closedByString,
title: record.title, title: record.title,
description: record.description, description: record.description,
location: record.location, location: record.location,

View file

@ -64,7 +64,10 @@ export default abstract class InspectionFactory {
inspectionVersionedPlan: InspectionVersionedPlanFactory.mapToSingle(record.inspectionVersionedPlan), inspectionVersionedPlan: InspectionVersionedPlanFactory.mapToSingle(record.inspectionVersionedPlan),
context: record.context, context: record.context,
created: record.createdAt, created: record.createdAt,
finished: record?.finishedAt, finishedAt: record?.finishedAt,
finishedBy: record?.finishedBy
? record.finishedBy.firstname + " " + record.finishedBy.lastname
: record.finishedByString,
isOpen: record?.finishedAt == undefined, isOpen: record?.finishedAt == undefined,
nextInspection: record?.nextInspection, nextInspection: record?.nextInspection,
checks: InspectionPointResultFactory.mapToBase(record.pointResults), checks: InspectionPointResultFactory.mapToBase(record.pointResults),

View file

@ -43,6 +43,9 @@ export default abstract class RepairFactory {
id: record.id, id: record.id,
createdAt: record.createdAt, createdAt: record.createdAt,
finishedAt: record.finishedAt, finishedAt: record.finishedAt,
finishedBy: record?.finishedBy
? record.finishedBy.firstname + " " + record.finishedBy.lastname
: record.finishedByString,
status: record.status, status: record.status,
responsible: record.responsible, responsible: record.responsible,
title: record.title, title: record.title,

View file

@ -93,7 +93,9 @@ export const inspection_table = new Table({
{ name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary }, { name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary },
{ name: "context", ...getTypeByORM("text") }, { name: "context", ...getTypeByORM("text") },
{ name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") }, { name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") },
{ name: "finishedAt", ...getTypeByORM("date", true) }, { name: "finishedAt", ...getTypeByORM("datetime", true) },
{ name: "finishedById", ...getTypeByORM("uuid", true) },
{ name: "finishedByString", ...getTypeByORM("varchar", true) },
{ name: "nextInspection", ...getTypeByORM("date", true) }, { name: "nextInspection", ...getTypeByORM("date", true) },
{ name: "hasNewer", ...getTypeByORM("boolean"), default: getDefaultByORM("boolean", false) }, { name: "hasNewer", ...getTypeByORM("boolean"), default: getDefaultByORM("boolean", false) },
{ name: "inspectionPlanId", ...getTypeByORM("uuid") }, { name: "inspectionPlanId", ...getTypeByORM("uuid") },
@ -103,6 +105,13 @@ export const inspection_table = new Table({
{ name: "wearableId", ...getTypeByORM("uuid", true) }, { name: "wearableId", ...getTypeByORM("uuid", true) },
], ],
foreignKeys: [ foreignKeys: [
new TableForeignKey({
columnNames: ["finishedById"],
referencedColumnNames: ["id"],
referencedTableName: "user",
onDelete: "SET NULL",
onUpdate: "RESTRICT",
}),
new TableForeignKey({ new TableForeignKey({
columnNames: ["inspectionPlanId"], columnNames: ["inspectionPlanId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],

View file

@ -6,21 +6,30 @@ export const damage_report_table = new Table({
columns: [ columns: [
{ name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary }, { name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary },
{ name: "reportedAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") }, { name: "reportedAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") },
{ name: "closedAt", ...getTypeByORM("datetime", true) },
{ name: "closedById", ...getTypeByORM("uuid", true) },
{ name: "closedByString", ...getTypeByORM("varchar", true) },
{ name: "status", ...getTypeByORM("varchar") }, { name: "status", ...getTypeByORM("varchar") },
{ name: "done", ...getTypeByORM("boolean"), default: getDefaultByORM("boolean", false) },
{ name: "title", ...getTypeByORM("varchar") }, { name: "title", ...getTypeByORM("varchar") },
{ name: "description", ...getTypeByORM("text") }, { name: "description", ...getTypeByORM("text") },
{ name: "location", ...getTypeByORM("text") }, { name: "location", ...getTypeByORM("text", true) },
{ name: "noteByReporter", ...getTypeByORM("text") }, { name: "noteByReporter", ...getTypeByORM("text", true) },
{ name: "noteByWorker", ...getTypeByORM("text") }, { name: "noteByWorker", ...getTypeByORM("text", true) },
{ name: "reportedBy", ...getTypeByORM("varchar") }, { name: "reportedBy", ...getTypeByORM("varchar", true) },
{ name: "images", ...getTypeByORM("text") }, { name: "images", ...getTypeByORM("text", true) },
{ name: "equipmentId", ...getTypeByORM("uuid", true) }, { name: "equipmentId", ...getTypeByORM("uuid", true) },
{ name: "vehicleId", ...getTypeByORM("uuid", true) }, { name: "vehicleId", ...getTypeByORM("uuid", true) },
{ name: "wearableId", ...getTypeByORM("uuid", true) }, { name: "wearableId", ...getTypeByORM("uuid", true) },
{ name: "repairId", ...getTypeByORM("uuid", true) }, { name: "repairId", ...getTypeByORM("uuid", true) },
], ],
foreignKeys: [ foreignKeys: [
new TableForeignKey({
columnNames: ["closedById"],
referencedColumnNames: ["id"],
referencedTableName: "user",
onDelete: "SET NULL",
onUpdate: "RESTRICT",
}),
new TableForeignKey({ new TableForeignKey({
columnNames: ["equipmentId"], columnNames: ["equipmentId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
@ -58,6 +67,8 @@ export const maintenance_table = new Table({
{ name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary }, { name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary },
{ name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") }, { name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") },
{ name: "finishedAt", ...getTypeByORM("datetime", true) }, { name: "finishedAt", ...getTypeByORM("datetime", true) },
{ name: "finishedById", ...getTypeByORM("uuid", true) },
{ name: "finishedByString", ...getTypeByORM("varchar", true) },
{ name: "status", ...getTypeByORM("varchar") }, { name: "status", ...getTypeByORM("varchar") },
{ name: "description", ...getTypeByORM("text") }, { name: "description", ...getTypeByORM("text") },
{ name: "equipmentId", ...getTypeByORM("uuid", true) }, { name: "equipmentId", ...getTypeByORM("uuid", true) },
@ -65,6 +76,13 @@ export const maintenance_table = new Table({
{ name: "wearableId", ...getTypeByORM("uuid", true) }, { name: "wearableId", ...getTypeByORM("uuid", true) },
], ],
foreignKeys: [ foreignKeys: [
new TableForeignKey({
columnNames: ["finishedById"],
referencedColumnNames: ["id"],
referencedTableName: "user",
onDelete: "SET NULL",
onUpdate: "RESTRICT",
}),
new TableForeignKey({ new TableForeignKey({
columnNames: ["equipmentId"], columnNames: ["equipmentId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
@ -95,17 +113,26 @@ export const repair_table = new Table({
{ name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary }, { name: "id", ...getTypeByORM("uuid"), ...isUUIDPrimary },
{ name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") }, { name: "createdAt", ...getTypeByORM("datetime"), default: getDefaultByORM("currentTimestamp") },
{ name: "finishedAt", ...getTypeByORM("datetime", true) }, { name: "finishedAt", ...getTypeByORM("datetime", true) },
{ name: "finishedById", ...getTypeByORM("uuid", true) },
{ name: "finishedByString", ...getTypeByORM("varchar", true) },
{ name: "status", ...getTypeByORM("varchar") }, { name: "status", ...getTypeByORM("varchar") },
{ name: "responsible", ...getTypeByORM("varchar") },
{ name: "title", ...getTypeByORM("varchar") }, { name: "title", ...getTypeByORM("varchar") },
{ name: "description", ...getTypeByORM("text") }, { name: "description", ...getTypeByORM("text") },
{ name: "images", ...getTypeByORM("text") }, { name: "responsible", ...getTypeByORM("varchar", true) },
{ name: "images", ...getTypeByORM("text", true) },
{ name: "reportDocument", ...getTypeByORM("varchar", true) }, { name: "reportDocument", ...getTypeByORM("varchar", true) },
{ name: "equipmentId", ...getTypeByORM("uuid", true) }, { name: "equipmentId", ...getTypeByORM("uuid", true) },
{ name: "vehicleId", ...getTypeByORM("uuid", true) }, { name: "vehicleId", ...getTypeByORM("uuid", true) },
{ name: "wearableId", ...getTypeByORM("uuid", true) }, { name: "wearableId", ...getTypeByORM("uuid", true) },
], ],
foreignKeys: [ foreignKeys: [
new TableForeignKey({
columnNames: ["finishedById"],
referencedColumnNames: ["id"],
referencedTableName: "user",
onDelete: "SET NULL",
onUpdate: "RESTRICT",
}),
new TableForeignKey({ new TableForeignKey({
columnNames: ["equipmentId"], columnNames: ["equipmentId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],

View file

@ -15,6 +15,7 @@ import {
provideDamageReportImageUpload, provideDamageReportImageUpload,
updateDamageReportById, updateDamageReportById,
} from "../../../controller/admin/unit/damageReportController"; } from "../../../controller/admin/unit/damageReportController";
import preventWebapiAccess from "../../../middleware/preventWebApiAccess";
var router = express.Router({ mergeParams: true }); var router = express.Router({ mergeParams: true });
@ -51,6 +52,7 @@ router.get("/:id/:filename", async (req: Request, res: Response) => {
router.patch( router.patch(
"/:id", "/:id",
preventWebapiAccess,
PermissionHelper.passCheckMiddleware("update", "unit", "damage_report"), PermissionHelper.passCheckMiddleware("update", "unit", "damage_report"),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
await updateDamageReportById(req, res); await updateDamageReportById(req, res);

View file

@ -14,6 +14,7 @@ import {
getInspectionPointUpload, getInspectionPointUpload,
} from "../../../controller/admin/unit/inspectionController"; } from "../../../controller/admin/unit/inspectionController";
import { inspectionFileUpload } from "../../../middleware/multer"; import { inspectionFileUpload } from "../../../middleware/multer";
import preventWebapiAccess from "../../../middleware/preventWebApiAccess";
var router = express.Router({ mergeParams: true }); var router = express.Router({ mergeParams: true });
@ -79,6 +80,7 @@ router.patch(
router.patch( router.patch(
"/:id/finish", "/:id/finish",
preventWebapiAccess,
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"), PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
await finishInspection(req, res); await finishInspection(req, res);

View file

@ -9,6 +9,7 @@ import {
updateRepairReportsById, updateRepairReportsById,
updateRepairStatusById, updateRepairStatusById,
} from "../../../controller/admin/unit/repairController"; } from "../../../controller/admin/unit/repairController";
import preventWebapiAccess from "../../../middleware/preventWebApiAccess";
var router = express.Router({ mergeParams: true }); var router = express.Router({ mergeParams: true });
@ -61,6 +62,7 @@ router.patch(
router.patch( router.patch(
"/:id/status", "/:id/status",
preventWebapiAccess,
PermissionHelper.passCheckMiddleware("update", "unit", "repair"), PermissionHelper.passCheckMiddleware("update", "unit", "repair"),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
await updateRepairStatusById(req, res); await updateRepairStatusById(req, res);

View file

@ -1,4 +1,4 @@
import { In } from "typeorm"; import { In, IsNull, Not } from "typeorm";
import { dataSource } from "../../data-source"; import { dataSource } from "../../data-source";
import { damageReport } from "../../entity/unit/damageReport"; import { damageReport } from "../../entity/unit/damageReport";
import DatabaseActionException from "../../exceptions/databaseActionException"; import DatabaseActionException from "../../exceptions/databaseActionException";
@ -11,7 +11,9 @@ export default abstract class DamageReportService {
.leftJoinAndSelect("damageReport.equipment", "equipment") .leftJoinAndSelect("damageReport.equipment", "equipment")
.leftJoinAndSelect("damageReport.vehicle", "vehicle") .leftJoinAndSelect("damageReport.vehicle", "vehicle")
.leftJoinAndSelect("damageReport.wearable", "wearable") .leftJoinAndSelect("damageReport.wearable", "wearable")
.leftJoinAndSelect("damageReport.repair", "repair"); .leftJoinAndSelect("damageReport.repair", "repair")
.leftJoinAndSelect("damageReport.closedBy", "user");
/** /**
* @description get all damageReports By done * @description get all damageReports By done
* @returns {Promise<[Array<damageReport>, number]>} * @returns {Promise<[Array<damageReport>, number]>}
@ -64,7 +66,7 @@ export default abstract class DamageReportService {
noLimit?: boolean; noLimit?: boolean;
} }
): Promise<[Array<damageReport>, number]> { ): Promise<[Array<damageReport>, number]> {
let query = this.query().where({ done }); let query = this.query().where({ closedAt: done ? Not(IsNull()) : IsNull() });
if (!noLimit) { if (!noLimit) {
query = query.offset(offset).limit(count); query = query.offset(offset).limit(count);

View file

@ -18,7 +18,8 @@ export default abstract class InspectionService {
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint") .leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
.leftJoinAndSelect("inspection.equipment", "equipment") .leftJoinAndSelect("inspection.equipment", "equipment")
.leftJoinAndSelect("inspection.vehicle", "vehicle") .leftJoinAndSelect("inspection.vehicle", "vehicle")
.leftJoinAndSelect("inspection.wearable", "wearable"); .leftJoinAndSelect("inspection.wearable", "wearable")
.leftJoinAndSelect("inspection.finishedBy", "user");
private static minifiedQuery = () => private static minifiedQuery = () =>
dataSource dataSource

View file

@ -10,13 +10,14 @@ export default abstract class MaintenanceService {
.createQueryBuilder("maintenance") .createQueryBuilder("maintenance")
.leftJoinAndSelect("maintenance.equipment", "equipment") .leftJoinAndSelect("maintenance.equipment", "equipment")
.leftJoinAndSelect("maintenance.vehicle", "vehicle") .leftJoinAndSelect("maintenance.vehicle", "vehicle")
.leftJoinAndSelect("maintenance.wearable", "wearable"); .leftJoinAndSelect("maintenance.wearable", "wearable")
.leftJoinAndSelect("maintenance.finishedBy", "user");
/** /**
* @description get all maintenances * @description get all maintenances
* @returns {Promise<[Array<maintenance>, number]>} * @returns {Promise<[Array<maintenance>, number]>}
*/ */
static async getAll( static async getAllByDone(
done = false, done = false,
{ {
offset = 0, offset = 0,

View file

@ -11,13 +11,14 @@ export default abstract class RepairService {
.leftJoinAndSelect("repair.equipment", "equipment") .leftJoinAndSelect("repair.equipment", "equipment")
.leftJoinAndSelect("repair.vehicle", "vehicle") .leftJoinAndSelect("repair.vehicle", "vehicle")
.leftJoinAndSelect("repair.wearable", "wearable") .leftJoinAndSelect("repair.wearable", "wearable")
.leftJoinAndSelect("repair.reports", "reports"); .leftJoinAndSelect("repair.reports", "reports")
.leftJoinAndSelect("repair.finishedBy", "user");
/** /**
* @description get all repairs * @description get all repairs
* @returns {Promise<[Array<repair>, number]>} * @returns {Promise<[Array<repair>, number]>}
*/ */
static async getAll( static async getAllByDone(
done = false, done = false,
{ {
offset = 0, offset = 0,

View file

@ -1,5 +1,4 @@
import { EquipmentViewModel } from "./equipment/equipment.models"; import { EquipmentViewModel } from "./equipment/equipment.models";
import { MaintenanceViewModel } from "./maintenance.models";
import { RepairViewModel } from "./repair.models"; import { RepairViewModel } from "./repair.models";
import { VehicleViewModel } from "./vehicle/vehicle.models"; import { VehicleViewModel } from "./vehicle/vehicle.models";
import { WearableViewModel } from "./wearable/wearable.models"; import { WearableViewModel } from "./wearable/wearable.models";
@ -25,8 +24,9 @@ export type DamageReportViewModel = {
id: string; id: string;
title: string; title: string;
reportedAt: Date; reportedAt: Date;
closedAt?: Date;
closedBy?: string;
status: string; status: string;
done: boolean;
description: string; description: string;
location: string; location: string;
noteByReporter: string; noteByReporter: string;

View file

@ -32,7 +32,8 @@ export type InspectionViewModel = {
inspectionVersionedPlan: InspectionVersionedPlanViewModel; inspectionVersionedPlan: InspectionVersionedPlanViewModel;
context: string; context: string;
created: Date; created: Date;
finished?: Date; finishedAt?: Date;
finishedBy?: string;
isOpen: boolean; isOpen: boolean;
nextInspection?: Date; nextInspection?: Date;
checks: Array<InspectionPointResultViewModel>; checks: Array<InspectionPointResultViewModel>;

View file

@ -24,6 +24,7 @@ export type RepairViewModel = {
id: string; id: string;
createdAt: Date; createdAt: Date;
finishedAt?: Date; finishedAt?: Date;
finishedBy?: string;
status: string; status: string;
responsible: string; responsible: string;
title: string; title: string;