add 4 new fields for expert approval

This commit is contained in:
SepehrYahyaee
2026-09-29 15:34:11 +03:30
parent b7a64596dd
commit 05e3e6a4d3
15 changed files with 1271 additions and 74 deletions
@@ -114,22 +114,35 @@ export class VehicleKindDbService {
async searchActiveByCaption(
q: string,
limit: number,
filters?: { vehicleGroupId?: number; vehicleSystemId?: number },
): Promise<VehicleKindRow[]> {
const needle = normalizeVehicleKindCaptionSearch(q);
if (!needle) return [];
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const query: FilterQuery<VehicleKindModel> = {
IsActive: 1,
captionSearch: { $regex: escaped },
};
if (filters?.vehicleGroupId != null) {
query.VehicleGroupId = filters.vehicleGroupId;
}
if (filters?.vehicleSystemId != null) {
query.VehicleSystemId = filters.vehicleSystemId;
}
return this.model
.find(
{
IsActive: 1,
captionSearch: { $regex: escaped },
},
PUBLIC_FIELDS,
)
.find(query, PUBLIC_FIELDS)
.sort({ Caption: 1 })
.limit(limit)
.lean()
.exec() as Promise<VehicleKindRow[]>;
}
async findActiveById(id: number): Promise<VehicleKindRow | null> {
return this.model
.findOne({ Id: id, IsActive: 1 }, PUBLIC_FIELDS)
.lean()
.exec() as Promise<VehicleKindRow | null>;
}
}
+20
View File
@@ -314,6 +314,16 @@ export class LookupsController {
description: "Max rows (1–100, default 50)",
example: 50,
})
@ApiQuery({
name: "vehicleGroupId",
required: false,
description: "Only return kinds belonging to this Fanavaran vehicle group",
})
@ApiQuery({
name: "vehicleSystemId",
required: false,
description: "Only return kinds belonging to this Fanavaran vehicle system",
})
@ApiOkResponse({
description: "Matched active vehicle kinds with echoed query",
schema: {
@@ -338,10 +348,20 @@ export class LookupsController {
async getVehicleList(
@Query("q") q?: string,
@Query("limit") limit?: string,
@Query("vehicleGroupId") vehicleGroupId?: string,
@Query("vehicleSystemId") vehicleSystemId?: string,
) {
return await this.lookupsService.searchVehicleKindsList({
q,
limit: limit != null && limit !== "" ? Number(limit) : undefined,
vehicleGroupId:
vehicleGroupId != null && vehicleGroupId !== ""
? Number(vehicleGroupId)
: undefined,
vehicleSystemId:
vehicleSystemId != null && vehicleSystemId !== ""
? Number(vehicleSystemId)
: undefined,
});
}
+15
View File
@@ -232,6 +232,8 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
async searchVehicleKindsList(input: {
q?: string | null;
limit?: number | null;
vehicleGroupId?: number | null;
vehicleSystemId?: number | null;
}): Promise<{
q: string;
count: number;
@@ -252,6 +254,14 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
const items = await this.vehicleKindDbService.searchActiveByCaption(
q,
limit,
{
...(input.vehicleGroupId != null
? { vehicleGroupId: Number(input.vehicleGroupId) }
: {}),
...(input.vehicleSystemId != null
? { vehicleSystemId: Number(input.vehicleSystemId) }
: {}),
},
);
return {
q,
@@ -260,6 +270,11 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
};
}
async getActiveVehicleKindById(id: number) {
await this.ensureVehicleKindsSynced(false);
return this.vehicleKindDbService.findActiveById(id);
}
/**
* Ensure `vehicle-kinds` Mongo collection is populated and not older than 1 week.
* Concurrent callers share one in-flight sync.
@@ -31,7 +31,7 @@ describe("LookupsService.searchVehicleKindsList", () => {
},
],
});
expect(searchActiveByCaption).toHaveBeenCalledWith("ول", 20);
expect(searchActiveByCaption).toHaveBeenCalledWith("ول", 20, {});
});
it("returns empty items for blank q without searching", async () => {