@7365admin1/core 2.58.0 → 2.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +106 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2217,6 +2217,16 @@ declare function useVehicleRepo(): {
|
|
|
2217
2217
|
};
|
|
2218
2218
|
}>;
|
|
2219
2219
|
getSpecificVehicleById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document>>;
|
|
2220
|
+
getBlocklistedVehicles: ({ page, limit, search, site, }: {
|
|
2221
|
+
page?: number | undefined;
|
|
2222
|
+
limit?: number | undefined;
|
|
2223
|
+
search?: string | undefined;
|
|
2224
|
+
site?: string | undefined;
|
|
2225
|
+
}) => Promise<{
|
|
2226
|
+
items: any[];
|
|
2227
|
+
pages: number;
|
|
2228
|
+
pageRange: string;
|
|
2229
|
+
}>;
|
|
2220
2230
|
};
|
|
2221
2231
|
|
|
2222
2232
|
declare function formatDahuaDate(date: Date): string;
|
|
@@ -2264,6 +2274,7 @@ declare function useVehicleController(): {
|
|
|
2264
2274
|
getAllVehiclesByUnitId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2265
2275
|
uploadSpreadsheetVehicles: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2266
2276
|
getSpecificVehicleById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2277
|
+
getBlocklistedVehicles: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2267
2278
|
};
|
|
2268
2279
|
|
|
2269
2280
|
declare function useSiteCameraRepo(): {
|
package/dist/index.js
CHANGED
|
@@ -15243,6 +15243,74 @@ function useVehicleRepo() {
|
|
|
15243
15243
|
throw new Error("Failed to bulk upsert vehicles.");
|
|
15244
15244
|
}
|
|
15245
15245
|
}
|
|
15246
|
+
async function getBlocklistedVehicles({
|
|
15247
|
+
page = 1,
|
|
15248
|
+
limit = 10,
|
|
15249
|
+
search = "",
|
|
15250
|
+
site = ""
|
|
15251
|
+
}) {
|
|
15252
|
+
page = page > 0 ? page - 1 : 0;
|
|
15253
|
+
const baseQuery = {
|
|
15254
|
+
type: "blocklist" /* BLOCKLIST */,
|
|
15255
|
+
...site && {
|
|
15256
|
+
site: typeof site === "string" ? new import_mongodb42.ObjectId(site) : site
|
|
15257
|
+
}
|
|
15258
|
+
};
|
|
15259
|
+
let query = {
|
|
15260
|
+
...baseQuery,
|
|
15261
|
+
...search && { $text: { $search: search } }
|
|
15262
|
+
};
|
|
15263
|
+
const escapeRegex = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15264
|
+
const buildPipeline = (matchQuery) => [
|
|
15265
|
+
{ $match: matchQuery },
|
|
15266
|
+
{
|
|
15267
|
+
$addFields: {
|
|
15268
|
+
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|
|
15269
|
+
}
|
|
15270
|
+
},
|
|
15271
|
+
{ $sort: { latestDate: -1 } },
|
|
15272
|
+
{ $skip: page * limit },
|
|
15273
|
+
{ $limit: limit },
|
|
15274
|
+
{
|
|
15275
|
+
$project: {
|
|
15276
|
+
latestDate: 0
|
|
15277
|
+
}
|
|
15278
|
+
}
|
|
15279
|
+
];
|
|
15280
|
+
const buildCountPipeline = (matchQuery) => [
|
|
15281
|
+
{ $match: matchQuery },
|
|
15282
|
+
{ $count: "total" }
|
|
15283
|
+
];
|
|
15284
|
+
try {
|
|
15285
|
+
let items = [];
|
|
15286
|
+
let length = 0;
|
|
15287
|
+
items = await collection.aggregate(buildPipeline(query)).toArray();
|
|
15288
|
+
const countResult = await collection.aggregate(buildCountPipeline(query)).toArray();
|
|
15289
|
+
length = countResult[0]?.total || 0;
|
|
15290
|
+
if ((!items || items.length === 0) && search) {
|
|
15291
|
+
const escaped = escapeRegex(search);
|
|
15292
|
+
const regexQuery = {
|
|
15293
|
+
...baseQuery,
|
|
15294
|
+
$or: [
|
|
15295
|
+
{ name: { $regex: escaped, $options: "i" } },
|
|
15296
|
+
{ plateNumber: { $regex: escaped, $options: "i" } },
|
|
15297
|
+
{ company: { $regex: escaped, $options: "i" } },
|
|
15298
|
+
{ level: { $regex: escaped, $options: "i" } },
|
|
15299
|
+
{ unitName: { $regex: escaped, $options: "i" } },
|
|
15300
|
+
{ contact: { $regex: escaped, $options: "i" } },
|
|
15301
|
+
{ nric: { $regex: escaped, $options: "i" } }
|
|
15302
|
+
]
|
|
15303
|
+
};
|
|
15304
|
+
items = await collection.aggregate(buildPipeline(regexQuery)).toArray();
|
|
15305
|
+
const regexCountResult = await collection.aggregate(buildCountPipeline(regexQuery)).toArray();
|
|
15306
|
+
length = regexCountResult[0]?.total || 0;
|
|
15307
|
+
}
|
|
15308
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
15309
|
+
return data;
|
|
15310
|
+
} catch (error) {
|
|
15311
|
+
throw error;
|
|
15312
|
+
}
|
|
15313
|
+
}
|
|
15246
15314
|
return {
|
|
15247
15315
|
createIndex,
|
|
15248
15316
|
createTextIndex,
|
|
@@ -15259,7 +15327,8 @@ function useVehicleRepo() {
|
|
|
15259
15327
|
getAllVehiclesByUnitId,
|
|
15260
15328
|
getAllExpiredVehicles,
|
|
15261
15329
|
bulkUpsertVehicles,
|
|
15262
|
-
getSpecificVehicleById
|
|
15330
|
+
getSpecificVehicleById,
|
|
15331
|
+
getBlocklistedVehicles
|
|
15263
15332
|
};
|
|
15264
15333
|
}
|
|
15265
15334
|
|
|
@@ -20695,7 +20764,8 @@ function useVehicleController() {
|
|
|
20695
20764
|
getVehicleById: _getVehicleById,
|
|
20696
20765
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
20697
20766
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId,
|
|
20698
|
-
getSpecificVehicleById: _getSpecificVehicleById
|
|
20767
|
+
getSpecificVehicleById: _getSpecificVehicleById,
|
|
20768
|
+
getBlocklistedVehicles: _getBlocklistedVehicles
|
|
20699
20769
|
} = useVehicleRepo();
|
|
20700
20770
|
function normalizeRow(row) {
|
|
20701
20771
|
return Object.fromEntries(
|
|
@@ -21231,6 +21301,38 @@ function useVehicleController() {
|
|
|
21231
21301
|
return;
|
|
21232
21302
|
}
|
|
21233
21303
|
}
|
|
21304
|
+
async function getBlocklistedVehicles(req, res, next) {
|
|
21305
|
+
const schema2 = import_joi46.default.object({
|
|
21306
|
+
search: import_joi46.default.string().optional().allow("", null),
|
|
21307
|
+
page: import_joi46.default.number().integer().min(1).optional().default(1),
|
|
21308
|
+
limit: import_joi46.default.number().integer().min(1).max(100).optional().default(10),
|
|
21309
|
+
site: import_joi46.default.string().hex().length(24).optional().allow(null, "")
|
|
21310
|
+
});
|
|
21311
|
+
const { error, value } = schema2.validate(req.query, {
|
|
21312
|
+
abortEarly: false
|
|
21313
|
+
});
|
|
21314
|
+
if (error) {
|
|
21315
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
21316
|
+
import_node_server_utils87.logger.log({ level: "error", message: messages });
|
|
21317
|
+
next(new import_node_server_utils87.BadRequestError(messages));
|
|
21318
|
+
return;
|
|
21319
|
+
}
|
|
21320
|
+
const { search, page, limit, site } = value;
|
|
21321
|
+
try {
|
|
21322
|
+
const data = await _getBlocklistedVehicles({
|
|
21323
|
+
search,
|
|
21324
|
+
page,
|
|
21325
|
+
limit,
|
|
21326
|
+
site
|
|
21327
|
+
});
|
|
21328
|
+
res.json(data);
|
|
21329
|
+
return;
|
|
21330
|
+
} catch (error2) {
|
|
21331
|
+
import_node_server_utils87.logger.log({ level: "error", message: error2.message });
|
|
21332
|
+
next(error2);
|
|
21333
|
+
return;
|
|
21334
|
+
}
|
|
21335
|
+
}
|
|
21234
21336
|
return {
|
|
21235
21337
|
add,
|
|
21236
21338
|
getVehicles,
|
|
@@ -21243,7 +21345,8 @@ function useVehicleController() {
|
|
|
21243
21345
|
reactivateVehicleById,
|
|
21244
21346
|
getAllVehiclesByUnitId,
|
|
21245
21347
|
uploadSpreadsheetVehicles,
|
|
21246
|
-
getSpecificVehicleById
|
|
21348
|
+
getSpecificVehicleById,
|
|
21349
|
+
getBlocklistedVehicles
|
|
21247
21350
|
};
|
|
21248
21351
|
}
|
|
21249
21352
|
|