basic services joins
This commit is contained in:
parent
e404989a28
commit
fcbfe560c3
13 changed files with 75 additions and 26 deletions
|
@ -1,9 +1,10 @@
|
|||
import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { Column, ColumnType, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { inspectionPlan } from "./inspectionPlan";
|
||||
import { inspectionVersionedPlan } from "./inspectionVersionedPlan";
|
||||
import { getTypeByORM } from "../../../migrations/ormHelper";
|
||||
import { vehicle } from "../vehicle/vehicle";
|
||||
import { equipment } from "../equipment/equipment";
|
||||
import { inspectionPointResult } from "./inspectionPointResult";
|
||||
|
||||
@Entity()
|
||||
export class inspection {
|
||||
|
@ -61,4 +62,7 @@ export class inspection {
|
|||
onUpdate: "RESTRICT",
|
||||
})
|
||||
vehicle: vehicle;
|
||||
|
||||
@OneToMany(() => inspectionPointResult, (ipr) => ipr.inspection)
|
||||
pointResults: inspectionPointResult[];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import DatabaseActionException from "../../exceptions/databaseActionException";
|
|||
|
||||
export default abstract class DamageReportService {
|
||||
/**
|
||||
* @description get all damageReport types
|
||||
* @description get all damageReports
|
||||
* @returns {Promise<Array<damageReport>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<damageReport>> {
|
||||
|
|
|
@ -4,14 +4,15 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class EquipmentService {
|
||||
/**
|
||||
* @description get all equipment types
|
||||
* @description get all equipment
|
||||
* @returns {Promise<Array<equipment>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipment>> {
|
||||
return await dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +30,7 @@ export default abstract class EquipmentService {
|
|||
return await dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class EquipmentTypeService {
|
||||
/**
|
||||
* @description get all equipment types
|
||||
* @description get all equipmentTypes
|
||||
* @returns {Promise<Array<equipmentType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipmentType>> {
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
import { dataSource } from "../../../data-source";
|
||||
import { inspectionPlan } from "../../../entity/unit/inspection/inspectionPlan";
|
||||
import { DB_TYPE } from "../../../env.defaults";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionPlanService {
|
||||
/**
|
||||
* @description get all inspectionPlan types
|
||||
* @description get all inspectionPlans for related
|
||||
* @returns {Promise<Array<inspectionPlan>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<inspectionPlan>> {
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string }
|
||||
): Promise<Array<inspectionPlan>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPlan)
|
||||
.createQueryBuilder("inspectionPlan")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndMapOne(
|
||||
"inspectionPlan.latestVersionedPlan",
|
||||
"inspectionPlan.versionedPlans",
|
||||
"latestVersionedPlan",
|
||||
DB_TYPE == "postgres"
|
||||
? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."start") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")'
|
||||
: "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.start) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where(where)
|
||||
.orderBy("title", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +42,15 @@ export default abstract class InspectionPlanService {
|
|||
return await dataSource
|
||||
.getRepository(inspectionPlan)
|
||||
.createQueryBuilder("inspectionPlan")
|
||||
.leftJoinAndMapOne(
|
||||
"inspectionPlan.latestVersionedPlan",
|
||||
"inspectionPlan.versionedPlans",
|
||||
"latestVersionedPlan",
|
||||
DB_TYPE == "postgres"
|
||||
? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."start") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")'
|
||||
: "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.start) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,14 +4,15 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class InspectionPointResultService {
|
||||
/**
|
||||
* @description get all inspectionPointResult types
|
||||
* @description get all inspectionPointResults
|
||||
* @returns {Promise<Array<inspectionPointResult>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<inspectionPointResult>> {
|
||||
static async getAllForInspection(inspectionId: string): Promise<Array<inspectionPointResult>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPointResult)
|
||||
.createQueryBuilder("inspectionPointResult")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("inspectionPointResult.inspectionPoint", "inspectionPoint")
|
||||
.where({ inspectionId })
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +30,7 @@ export default abstract class InspectionPointResultService {
|
|||
return await dataSource
|
||||
.getRepository(inspectionPointResult)
|
||||
.createQueryBuilder("inspectionPointResult")
|
||||
.leftJoinAndSelect("inspectionPointResult.inspectionPoint", "inspectionPoint")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,14 +4,15 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class InspectionPointService {
|
||||
/**
|
||||
* @description get all inspectionPoint types
|
||||
* @description get all inspectionPoints
|
||||
* @returns {Promise<Array<inspectionPoint>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<inspectionPoint>> {
|
||||
static async getAllForVersionedPlan(versionedPlanId: string): Promise<Array<inspectionPoint>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionPoint)
|
||||
.createQueryBuilder("inspectionPoint")
|
||||
.orderBy("type", "ASC")
|
||||
.where({ versionedPlanId })
|
||||
.orderBy("sort", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
|
|
@ -4,14 +4,20 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class InspectionService {
|
||||
/**
|
||||
* @description get all inspection types
|
||||
* @description get all inspections for related
|
||||
* @returns {Promise<Array<inspection>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<inspection>> {
|
||||
static async getAllForRelated(where: { equipmentId: string } | { vehicleId: string }): Promise<Array<inspection>> {
|
||||
return await dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
||||
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.where(where)
|
||||
.orderBy("createdAt", "DESC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +35,11 @@ export default abstract class InspectionService {
|
|||
return await dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
||||
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,14 +4,16 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class InspectionVersionedPlanService {
|
||||
/**
|
||||
* @description get all inspectionVersionedPlan types
|
||||
* @description get all inspectionVersionedPlans
|
||||
* @returns {Promise<Array<inspectionVersionedPlan>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<inspectionVersionedPlan>> {
|
||||
static async getAllForInspectionPlan(inspectionPlanId: string): Promise<Array<inspectionVersionedPlan>> {
|
||||
return await dataSource
|
||||
.getRepository(inspectionVersionedPlan)
|
||||
.createQueryBuilder("inspectionVersionedPlan")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where({ inspectionPlanId })
|
||||
.orderBy("version", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +31,7 @@ export default abstract class InspectionVersionedPlanService {
|
|||
return await dataSource
|
||||
.getRepository(inspectionVersionedPlan)
|
||||
.createQueryBuilder("inspectionVersionedPlan")
|
||||
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,14 +4,15 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class VehicleService {
|
||||
/**
|
||||
* @description get all vehicle types
|
||||
* @description get all vehicles
|
||||
* @returns {Promise<Array<vehicle>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicle>> {
|
||||
return await dataSource
|
||||
.getRepository(vehicle)
|
||||
.createQueryBuilder("vehicle")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +30,7 @@ export default abstract class VehicleService {
|
|||
return await dataSource
|
||||
.getRepository(vehicle)
|
||||
.createQueryBuilder("vehicle")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class VehicleTypeService {
|
||||
/**
|
||||
* @description get all vehicleType types
|
||||
* @description get all vehicleTypes
|
||||
* @returns {Promise<Array<vehicleType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicleType>> {
|
||||
|
|
|
@ -4,14 +4,15 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class WearableService {
|
||||
/**
|
||||
* @description get all wearable types
|
||||
* @description get all wearables
|
||||
* @returns {Promise<Array<wearable>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearable>> {
|
||||
return await dataSource
|
||||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.orderBy("type", "ASC")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -29,6 +30,7 @@ export default abstract class WearableService {
|
|||
return await dataSource
|
||||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
|
||||
export default abstract class WearableTypeService {
|
||||
/**
|
||||
* @description get all wearableType types
|
||||
* @description get all wearableTypes
|
||||
* @returns {Promise<Array<wearableType>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearableType>> {
|
||||
|
|
Loading…
Add table
Reference in a new issue