change according to connection from frontend
This commit is contained in:
parent
2609ecc1bf
commit
e3db523a0e
36 changed files with 611 additions and 173 deletions
|
@ -3,20 +3,73 @@ import { damageReport } from "../../entity/unit/damageReport";
|
|||
import DatabaseActionException from "../../exceptions/databaseActionException";
|
||||
|
||||
export default abstract class DamageReportService {
|
||||
/**
|
||||
* @description get all damageReports
|
||||
* @returns {Promise<Array<damageReport>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<damageReport>> {
|
||||
return await dataSource
|
||||
private static query = () =>
|
||||
dataSource
|
||||
.getRepository(damageReport)
|
||||
.createQueryBuilder("damageReport")
|
||||
.leftJoinAndSelect("damageReport.equipment", "equipment")
|
||||
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("damageReport.wearable", "wearable")
|
||||
.leftJoinAndSelect("damageReport.maintenance", "maintenance")
|
||||
.orderBy("type", "ASC")
|
||||
.getMany()
|
||||
.leftJoinAndSelect("damageReport.maintenance", "maintenance");
|
||||
|
||||
/**
|
||||
* @description get all damageReports By done
|
||||
* @returns {Promise<[Array<damageReport>, number]>}
|
||||
*/
|
||||
static async getAll(
|
||||
done = false,
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}
|
||||
): Promise<[Array<damageReport>, number]> {
|
||||
let query = this.query().where({ done });
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("damageReport.reportedAt", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "damageReport", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all damageReports By related
|
||||
* @returns {Promise<[Array<damageReport>, number]>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string } | { wearableId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}
|
||||
): Promise<[Array<damageReport>, number]> {
|
||||
let query = this.query().where(where);
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
||||
return await query
|
||||
.orderBy("reportedAt", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
|
@ -30,13 +83,7 @@ export default abstract class DamageReportService {
|
|||
* @returns {Promise<damageReport>}
|
||||
*/
|
||||
static async getById(id: string): Promise<damageReport> {
|
||||
return await dataSource
|
||||
.getRepository(damageReport)
|
||||
.createQueryBuilder("damageReport")
|
||||
.leftJoinAndSelect("damageReport.equipment", "equipment")
|
||||
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("damageReport.wearable", "wearable")
|
||||
.leftJoinAndSelect("damageReport.maintenance", "maintenance")
|
||||
return await this.query()
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -27,11 +27,16 @@ export default abstract class EquipmentService {
|
|||
.leftJoinAndSelect("equipment.equipmentType", "equipmenttype");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
query = query
|
||||
.where({
|
||||
code: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
name: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
location: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
|
|
|
@ -13,26 +13,20 @@ export default abstract class EquipmentTypeService {
|
|||
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),
|
||||
type: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
|
|
@ -14,19 +14,63 @@ export default abstract class InspectionPlanService {
|
|||
"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)"
|
||||
? 'latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX("ivp"."createdAt") FROM "inspection_versioned_plan" "ivp" WHERE "ivp"."inspectionPlanId" = "inspectionPlan"."id")'
|
||||
: "latestVersionedPlan.inspectionPlanId = inspectionPlan.id AND latestVersionedPlan.version = (SELECT MAX(ivp.createdAt) FROM inspection_versioned_plan ivp WHERE ivp.inspectionPlanId = inspectionPlan.id)"
|
||||
)
|
||||
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
|
||||
.leftJoinAndSelect("inspectionPlan.equipment", "equipment")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicle", "vehicle");
|
||||
.leftJoinAndSelect("inspectionPlan.equipmentType", "equipmentType")
|
||||
.leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType");
|
||||
|
||||
/**
|
||||
* @description get all inspectionPlans for related
|
||||
* @returns {Promise<[Array<inspectionPlan>, number]>}
|
||||
*/
|
||||
static async getAll({
|
||||
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();
|
||||
|
||||
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("inspectionPlan.title", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "inspectionPlan", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all inspectionPlans for related
|
||||
* @returns {Promise<[Array<inspectionPlan>, number]>}
|
||||
*/
|
||||
static async getAllForRelated(
|
||||
where: { equipmentId: string } | { vehicleId: string },
|
||||
where: { equipmentTypeId: string } | { vehicleTypeId: string },
|
||||
{
|
||||
offset = 0,
|
||||
count = 25,
|
||||
|
@ -44,13 +88,13 @@ export default abstract class InspectionPlanService {
|
|||
let query = this.query().where(where);
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
title: Like(search),
|
||||
query = query.andWhere({
|
||||
title: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
query = query.andWhere({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
|
@ -58,7 +102,7 @@ export default abstract class InspectionPlanService {
|
|||
}
|
||||
|
||||
return await query
|
||||
.orderBy("title", "ASC")
|
||||
.orderBy("inspectionPlan.title", "ASC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
|
|
@ -38,7 +38,7 @@ export default abstract class InspectionService {
|
|||
}
|
||||
|
||||
return await query
|
||||
.orderBy("createdAt", "DESC")
|
||||
.orderBy("inspection.createdAt", "DESC")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
|
|
@ -27,11 +27,16 @@ export default abstract class VehicleService {
|
|||
.leftJoinAndSelect("vehicle.vehicleType", "vehicletype");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
query = query
|
||||
.where({
|
||||
code: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
name: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
location: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
|
|
|
@ -13,26 +13,20 @@ export default abstract class VehicleTypeService {
|
|||
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),
|
||||
type: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
|
|
@ -28,11 +28,16 @@ export default abstract class WearableService {
|
|||
.leftJoinAndSelect("wearable.wearer", "wearer");
|
||||
|
||||
if (search != "") {
|
||||
query = query.where({
|
||||
code: Like(search),
|
||||
name: Like(search),
|
||||
location: Like(search),
|
||||
});
|
||||
query = query
|
||||
.where({
|
||||
code: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
name: Like(`%${search}%`),
|
||||
})
|
||||
.orWhere({
|
||||
location: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
|
@ -63,6 +68,7 @@ export default abstract class WearableService {
|
|||
.getRepository(wearable)
|
||||
.createQueryBuilder("wearable")
|
||||
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
|
||||
.leftJoinAndSelect("wearable.wearer", "wearer")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
|
|
|
@ -13,26 +13,20 @@ export default abstract class WearableTypeService {
|
|||
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),
|
||||
type: Like(`%${search}%`),
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.length != 0) {
|
||||
query = query.where({ id: In(ids) });
|
||||
}
|
||||
|
||||
if (!noLimit) {
|
||||
query = query.offset(offset).limit(count);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue