This commit is contained in:
wayanrivan
2026-04-15 17:37:33 +07:00
parent 48ef4b7ea2
commit 043858d790

View File

@ -54,10 +54,22 @@ export class ServiceFareController {
"Service.id", "Service.id",
"Service.name", "Service.name",
]) ])
.leftJoin("Service.servicefare", "servicefare") .leftJoin(
.addSelect("MIN(servicefare.fare)", "min_fare") qb => {
.addSelect("MAX(servicefare.fare)", "max_fare") return qb
.groupBy("Service.id") .select('sf."serviceId"', "serviceId")
.addSelect("COALESCE(MIN(sf.fare), 0)", "min")
.addSelect("COALESCE(MAX(sf.fare), 0)", "max")
.from("service_fares", "sf")
.innerJoin("fare_type", "ft", 'sf."faretypeId" = ft.id AND ft.deleted_at IS NULL')
.innerJoin("service_classes", "sc", 'sf."serviceClassId" = sc.id AND sc.deleted_at IS NULL')
.groupBy('sf."serviceId"');
},
"sfa",
'sfa."serviceId" = Service.id'
)
.addSelect('COALESCE(sfa.min, 0)', "min_fare")
.addSelect('COALESCE(sfa.max, 0)', "max_fare")
.orderBy("Service." + param.order_field, param.order_direction) .orderBy("Service." + param.order_field, param.order_direction)
.skip(offset) .skip(offset)
.take(limit); .take(limit);
@ -207,11 +219,11 @@ export class ServiceFareController {
serviceFare.service = service; serviceFare.service = service;
serviceFare.faretype = ft.faretype_id; serviceFare.faretype = ft.faretype_id;
serviceFare.serviceClass = serviceClass; serviceFare.serviceClass = serviceClass;
serviceFare.created_by = req.auth.data.name; serviceFare.created_by = req.auth?.data.name;
} }
serviceFare.fare = String(sc.fare ?? 0); serviceFare.fare = String(sc.fare ?? 0);
serviceFare.updated_by = req.auth.data.name; serviceFare.updated_by = req.auth?.data.name;
const saved = await queryRunner.manager.save(serviceFare); const saved = await queryRunner.manager.save(serviceFare);
savedServiceFares.push(saved); savedServiceFares.push(saved);
@ -301,7 +313,7 @@ export class ServiceFareController {
// Update fare saja // Update fare saja
serviceFare.fare = String(param.fare); serviceFare.fare = String(param.fare);
serviceFare.updated_by = req.auth.data.name; serviceFare.updated_by = req.auth?.data.name;
await queryRunner.manager.save(serviceFare); await queryRunner.manager.save(serviceFare);
await queryRunner.commitTransaction(); await queryRunner.commitTransaction();
@ -339,7 +351,7 @@ export class ServiceFareController {
if (!serviceFare) throw { message: "Service Fare " + Language.lang.failed_not_found }; if (!serviceFare) throw { message: "Service Fare " + Language.lang.failed_not_found };
serviceFare.deleted_by = req.auth.data.name; serviceFare.deleted_by = req.auth?.data.name;
serviceFare.deleted_at = moment().toDate(); serviceFare.deleted_at = moment().toDate();
await OrmHelper.DB.manager.save(serviceFare); await OrmHelper.DB.manager.save(serviceFare);
affected = 1; affected = 1;