diff --git a/src/service/unit/damageReport.ts b/src/service/unit/damageReport.ts new file mode 100644 index 0000000..0832766 --- /dev/null +++ b/src/service/unit/damageReport.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../data-source"; +import { damageReport } from "../../entity/unit/damageReport"; +import DatabaseActionException from "../../exceptions/databaseActionException"; + +export default abstract class DamageReportService { + /** + * @description get all damageReport types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(damageReport) + .createQueryBuilder("damageReport") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "damageReport", err); + }); + } + + /** + * @description get damageReport by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(damageReport) + .createQueryBuilder("damageReport") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "damageReport", err); + }); + } +} diff --git a/src/service/unit/equipment/equipmentService.ts b/src/service/unit/equipment/equipmentService.ts new file mode 100644 index 0000000..8c28427 --- /dev/null +++ b/src/service/unit/equipment/equipmentService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { equipment } from "../../../entity/unit/equipment/equipment"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class EquipmentService { + /** + * @description get all equipment types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(equipment) + .createQueryBuilder("equipment") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "equipment", err); + }); + } + + /** + * @description get equipment by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(equipment) + .createQueryBuilder("equipment") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "equipment", err); + }); + } +} diff --git a/src/service/unit/equipment/equipmentTypeService.ts b/src/service/unit/equipment/equipmentTypeService.ts new file mode 100644 index 0000000..4617544 --- /dev/null +++ b/src/service/unit/equipment/equipmentTypeService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { equipmentType } from "../../../entity/unit/equipment/equipmentType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class EquipmentTypeService { + /** + * @description get all equipment types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(equipmentType) + .createQueryBuilder("equipmentType") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "equipmentType", err); + }); + } + + /** + * @description get equipmentType by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(equipmentType) + .createQueryBuilder("equipmentType") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "equipmentType", err); + }); + } +} diff --git a/src/service/unit/inspection/inspectionPlanService.ts b/src/service/unit/inspection/inspectionPlanService.ts new file mode 100644 index 0000000..96fbab9 --- /dev/null +++ b/src/service/unit/inspection/inspectionPlanService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { inspectionPlan } from "../../../entity/unit/inspection/inspectionPlan"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class InspectionPlanService { + /** + * @description get all inspectionPlan types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(inspectionPlan) + .createQueryBuilder("inspectionPlan") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPlan", err); + }); + } + + /** + * @description get inspectionPlan by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(inspectionPlan) + .createQueryBuilder("inspectionPlan") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPlan", err); + }); + } +} diff --git a/src/service/unit/inspection/inspectionPointResultService.ts b/src/service/unit/inspection/inspectionPointResultService.ts new file mode 100644 index 0000000..4ac3450 --- /dev/null +++ b/src/service/unit/inspection/inspectionPointResultService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { inspectionPointResult } from "../../../entity/unit/inspection/inspectionPointResult"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class InspectionPointResultService { + /** + * @description get all inspectionPointResult types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(inspectionPointResult) + .createQueryBuilder("inspectionPointResult") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPointResult", err); + }); + } + + /** + * @description get inspectionPointResult by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(inspectionPointResult) + .createQueryBuilder("inspectionPointResult") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPointResult", err); + }); + } +} diff --git a/src/service/unit/inspection/inspectionPointService.ts b/src/service/unit/inspection/inspectionPointService.ts new file mode 100644 index 0000000..4203550 --- /dev/null +++ b/src/service/unit/inspection/inspectionPointService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { inspectionPoint } from "../../../entity/unit/inspection/inspectionPoint"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class InspectionPointService { + /** + * @description get all inspectionPoint types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(inspectionPoint) + .createQueryBuilder("inspectionPoint") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPoint", err); + }); + } + + /** + * @description get inspectionPoint by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(inspectionPoint) + .createQueryBuilder("inspectionPoint") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionPoint", err); + }); + } +} diff --git a/src/service/unit/inspection/inspectionService.ts b/src/service/unit/inspection/inspectionService.ts new file mode 100644 index 0000000..cd8ba7d --- /dev/null +++ b/src/service/unit/inspection/inspectionService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { inspection } from "../../../entity/unit/inspection/inspection"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class InspectionService { + /** + * @description get all inspection types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(inspection) + .createQueryBuilder("inspection") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspection", err); + }); + } + + /** + * @description get inspection by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(inspection) + .createQueryBuilder("inspection") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspection", err); + }); + } +} diff --git a/src/service/unit/inspection/inspectionVersionedPlanService.ts b/src/service/unit/inspection/inspectionVersionedPlanService.ts new file mode 100644 index 0000000..ebaa296 --- /dev/null +++ b/src/service/unit/inspection/inspectionVersionedPlanService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { inspectionVersionedPlan } from "../../../entity/unit/inspection/inspectionVersionedPlan"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class InspectionVersionedPlanService { + /** + * @description get all inspectionVersionedPlan types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(inspectionVersionedPlan) + .createQueryBuilder("inspectionVersionedPlan") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionVersionedPlan", err); + }); + } + + /** + * @description get inspectionVersionedPlan by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(inspectionVersionedPlan) + .createQueryBuilder("inspectionVersionedPlan") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "inspectionVersionedPlan", err); + }); + } +} diff --git a/src/service/unit/vehicle/vehicleService.ts b/src/service/unit/vehicle/vehicleService.ts new file mode 100644 index 0000000..898911f --- /dev/null +++ b/src/service/unit/vehicle/vehicleService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { vehicle } from "../../../entity/unit/vehicle/vehicle"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class VehicleService { + /** + * @description get all vehicle types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(vehicle) + .createQueryBuilder("vehicle") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "vehicle", err); + }); + } + + /** + * @description get vehicle by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(vehicle) + .createQueryBuilder("vehicle") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "vehicle", err); + }); + } +} diff --git a/src/service/unit/vehicle/vehicleTypeService.ts b/src/service/unit/vehicle/vehicleTypeService.ts new file mode 100644 index 0000000..2af3acc --- /dev/null +++ b/src/service/unit/vehicle/vehicleTypeService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { vehicleType } from "../../../entity/unit/vehicle/vehicleType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class VehicleTypeService { + /** + * @description get all vehicleType types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(vehicleType) + .createQueryBuilder("vehicleType") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "vehicleType", err); + }); + } + + /** + * @description get vehicleType by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(vehicleType) + .createQueryBuilder("vehicleType") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "vehicleType", err); + }); + } +} diff --git a/src/service/unit/wearable/wearableService.ts b/src/service/unit/wearable/wearableService.ts new file mode 100644 index 0000000..77c120a --- /dev/null +++ b/src/service/unit/wearable/wearableService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { wearable } from "../../../entity/unit/wearable/wearable"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class WearableService { + /** + * @description get all wearable types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(wearable) + .createQueryBuilder("wearable") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "wearable", err); + }); + } + + /** + * @description get wearable by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(wearable) + .createQueryBuilder("wearable") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "wearable", err); + }); + } +} diff --git a/src/service/unit/wearable/wearableTypeService.ts b/src/service/unit/wearable/wearableTypeService.ts new file mode 100644 index 0000000..77f7a90 --- /dev/null +++ b/src/service/unit/wearable/wearableTypeService.ts @@ -0,0 +1,41 @@ +import { dataSource } from "../../../data-source"; +import { wearableType } from "../../../entity/unit/wearable/wearableType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; + +export default abstract class WearableTypeService { + /** + * @description get all wearableType types + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(wearableType) + .createQueryBuilder("wearableType") + .orderBy("type", "ASC") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "wearableType", err); + }); + } + + /** + * @description get wearableType by id + * @returns {Promise} + */ + static async getById(id: string): Promise { + return await dataSource + .getRepository(wearableType) + .createQueryBuilder("wearableType") + .where({ id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "wearableType", err); + }); + } +} diff --git a/src/viewmodel/admin/unit/damageReport/damageReport.models.ts b/src/viewmodel/admin/unit/damageReport/damageReport.models.ts index e1d7075..a144114 100644 --- a/src/viewmodel/admin/unit/damageReport/damageReport.models.ts +++ b/src/viewmodel/admin/unit/damageReport/damageReport.models.ts @@ -9,6 +9,7 @@ export type DamageReportViewModel = { done: boolean; description: string; providedImage: Array; + reportedBy: string; relatedId: string; } & ( | { @@ -27,6 +28,7 @@ export type DamageReportViewModel = { export interface CreateDamageReportViewModel { description: string; + reportedBy: string; affectedId: string; affected: "equipment" | "vehicle" | "wearable"; }