controller
This commit is contained in:
parent
9f2a08ccc9
commit
2609ecc1bf
17 changed files with 320 additions and 95 deletions
|
@ -1,3 +1,4 @@
|
|||
import { In, Like } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { equipment } from "../../../entity/unit/equipment/equipment";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,15 +6,45 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class EquipmentService {
|
||||
/**
|
||||
* @description get all equipment
|
||||
* @returns {Promise<Array<equipment>>}
|
||||
* @returns {Promise<[Array<equipment>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipment>> {
|
||||
return await dataSource
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<equipment>, number]> {
|
||||
let query = dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype")
|
||||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Like, In } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { equipmentType } from "../../../entity/unit/equipment/equipmentType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,14 +6,40 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class EquipmentTypeService {
|
||||
/**
|
||||
* @description get all equipmentTypes
|
||||
* @returns {Promise<Array<equipmentType>>}
|
||||
* @returns {Promise<[Array<equipmentType>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipmentType>> {
|
||||
return await dataSource
|
||||
.getRepository(equipmentType)
|
||||
.createQueryBuilder("equipmentType")
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<equipmentType>, number]> {
|
||||
let query = dataSource.getRepository(equipmentType).createQueryBuilder("equipmentType");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
type: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
import { Like, In } from "typeorm";
|
||||
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 inspectionPlans for related
|
||||
* @returns {Promise<Array<inspectionPlan>>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string }
|
||||
): Promise<Array<inspectionPlan>> {
|
||||
return await dataSource
|
||||
private static query = () =>
|
||||
dataSource
|
||||
.getRepository(inspectionPlan)
|
||||
.createQueryBuilder("inspectionPlan")
|
||||
.leftJoinAndMapOne(
|
||||
|
@ -24,10 +19,47 @@ export default abstract class InspectionPlanService {
|
|||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
.where(where)
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle");
|
||||
|
||||
/**
|
||||
* @description get all inspectionPlans for related
|
||||
* @returns {Promise<[Array<inspectionPlan>, number]>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}
|
||||
): Promise<[Array<inspectionPlan>, number]> {
|
||||
let query = this.query().where(where);
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
title: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("title", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
@ -41,20 +73,7 @@ export default abstract class InspectionPlanService {
|
|||
* @returns {Promise<inspectionPlan>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspectionPlan> {
|
||||
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")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle")
|
||||
return await this.query()
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -3,12 +3,8 @@ import { inspection } from "../../../entity/unit/inspection/inspection";
|
|||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class InspectionService {
|
||||
/**
|
||||
* @description get all inspections for related
|
||||
* @returns {Promise<Array<inspection>>}
|
||||
*/
|
||||
static async getAllForRelated(where: { equipmentId: string } | { vehicleId: string }): Promise<Array<inspection>> {
|
||||
return await dataSource
|
||||
private static query = () =>
|
||||
dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
||||
|
@ -17,10 +13,33 @@ export default abstract class InspectionService {
|
|||
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
||||
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
||||
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||
.where(where)
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle");
|
||||
|
||||
/**
|
||||
* @description get all inspections for related
|
||||
* @returns {Promise<Array<inspection>>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}
|
||||
): Promise<[Array<inspection>, number]> {
|
||||
let query = this.query().where(where);
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("createdAt", "DESC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
@ -34,16 +53,7 @@ export default abstract class InspectionService {
|
|||
* @returns {Promise<inspection>}
|
||||
*/
|
||||
static async getById(id: string): Promise<inspection> {
|
||||
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")
|
||||
.leftJoinAndSelect("inspection.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
||||
return await this.query()
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Like, In } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { vehicle } from "../../../entity/unit/vehicle/vehicle";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,15 +6,45 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class VehicleService {
|
||||
/**
|
||||
* @description get all vehicles
|
||||
* @returns {Promise<Array<vehicle>>}
|
||||
* @returns {Promise<[Array<vehicle>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicle>> {
|
||||
return await dataSource
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<vehicle>, number]> {
|
||||
let query = dataSource
|
||||
.getRepository(vehicle)
|
||||
.createQueryBuilder("vehicle")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype")
|
||||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Like, In } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { vehicleType } from "../../../entity/unit/vehicle/vehicleType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,14 +6,40 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class VehicleTypeService {
|
||||
/**
|
||||
* @description get all vehicleTypes
|
||||
* @returns {Promise<Array<vehicleType>>}
|
||||
* @returns {Promise<[Array<vehicleType>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<vehicleType>> {
|
||||
return await dataSource
|
||||
.getRepository(vehicleType)
|
||||
.createQueryBuilder("vehicleType")
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<vehicleType>, number]> {
|
||||
let query = dataSource.getRepository(vehicleType).createQueryBuilder("vehicleType");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
type: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Like, In } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { wearable } from "../../../entity/unit/wearable/wearable";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,16 +6,46 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class WearableService {
|
||||
/**
|
||||
* @description get all wearables
|
||||
* @returns {Promise<Array<wearable>>}
|
||||
* @returns {Promise<[Array<wearable>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearable>> {
|
||||
return await dataSource
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<wearable>, number]> {
|
||||
let query = dataSource
|
||||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.leftJoinAndSelect("wearable.wearer", "wearer")
|
||||
.leftJoinAndSelect("wearable.wearer", "wearer");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("name", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { In, Like } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { wearableType } from "../../../entity/unit/wearable/wearableType";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -5,14 +6,40 @@ import DatabaseActionException from "../../../exceptions/databaseActionException
|
|||
export default abstract class WearableTypeService {
|
||||
/**
|
||||
* @description get all wearableTypes
|
||||
* @returns {Promise<Array<wearableType>>}
|
||||
* @returns {Promise<[Array<wearableType>, number]>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<wearableType>> {
|
||||
return await dataSource
|
||||
.getRepository(wearableType)
|
||||
.createQueryBuilder("wearableType")
|
||||
static async getAll({
|
||||
offset = 0,
|
||||
count = 25,
|
||||
search = "",
|
||||
noLimit = false,
|
||||
ids = [],
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
search?: string;
|
||||
noLimit?: boolean;
|
||||
ids?: Array<string>;
|
||||
}): Promise<[Array<wearableType>, number]> {
|
||||
let query = dataSource.getRepository(wearableType).createQueryBuilder("wearableType");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
type: Like(search),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue