@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/dist/index.mjs
CHANGED
|
@@ -15037,6 +15037,74 @@ function useVehicleRepo() {
|
|
|
15037
15037
|
throw new Error("Failed to bulk upsert vehicles.");
|
|
15038
15038
|
}
|
|
15039
15039
|
}
|
|
15040
|
+
async function getBlocklistedVehicles({
|
|
15041
|
+
page = 1,
|
|
15042
|
+
limit = 10,
|
|
15043
|
+
search = "",
|
|
15044
|
+
site = ""
|
|
15045
|
+
}) {
|
|
15046
|
+
page = page > 0 ? page - 1 : 0;
|
|
15047
|
+
const baseQuery = {
|
|
15048
|
+
type: "blocklist" /* BLOCKLIST */,
|
|
15049
|
+
...site && {
|
|
15050
|
+
site: typeof site === "string" ? new ObjectId42(site) : site
|
|
15051
|
+
}
|
|
15052
|
+
};
|
|
15053
|
+
let query = {
|
|
15054
|
+
...baseQuery,
|
|
15055
|
+
...search && { $text: { $search: search } }
|
|
15056
|
+
};
|
|
15057
|
+
const escapeRegex = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15058
|
+
const buildPipeline = (matchQuery) => [
|
|
15059
|
+
{ $match: matchQuery },
|
|
15060
|
+
{
|
|
15061
|
+
$addFields: {
|
|
15062
|
+
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|
|
15063
|
+
}
|
|
15064
|
+
},
|
|
15065
|
+
{ $sort: { latestDate: -1 } },
|
|
15066
|
+
{ $skip: page * limit },
|
|
15067
|
+
{ $limit: limit },
|
|
15068
|
+
{
|
|
15069
|
+
$project: {
|
|
15070
|
+
latestDate: 0
|
|
15071
|
+
}
|
|
15072
|
+
}
|
|
15073
|
+
];
|
|
15074
|
+
const buildCountPipeline = (matchQuery) => [
|
|
15075
|
+
{ $match: matchQuery },
|
|
15076
|
+
{ $count: "total" }
|
|
15077
|
+
];
|
|
15078
|
+
try {
|
|
15079
|
+
let items = [];
|
|
15080
|
+
let length = 0;
|
|
15081
|
+
items = await collection.aggregate(buildPipeline(query)).toArray();
|
|
15082
|
+
const countResult = await collection.aggregate(buildCountPipeline(query)).toArray();
|
|
15083
|
+
length = countResult[0]?.total || 0;
|
|
15084
|
+
if ((!items || items.length === 0) && search) {
|
|
15085
|
+
const escaped = escapeRegex(search);
|
|
15086
|
+
const regexQuery = {
|
|
15087
|
+
...baseQuery,
|
|
15088
|
+
$or: [
|
|
15089
|
+
{ name: { $regex: escaped, $options: "i" } },
|
|
15090
|
+
{ plateNumber: { $regex: escaped, $options: "i" } },
|
|
15091
|
+
{ company: { $regex: escaped, $options: "i" } },
|
|
15092
|
+
{ level: { $regex: escaped, $options: "i" } },
|
|
15093
|
+
{ unitName: { $regex: escaped, $options: "i" } },
|
|
15094
|
+
{ contact: { $regex: escaped, $options: "i" } },
|
|
15095
|
+
{ nric: { $regex: escaped, $options: "i" } }
|
|
15096
|
+
]
|
|
15097
|
+
};
|
|
15098
|
+
items = await collection.aggregate(buildPipeline(regexQuery)).toArray();
|
|
15099
|
+
const regexCountResult = await collection.aggregate(buildCountPipeline(regexQuery)).toArray();
|
|
15100
|
+
length = regexCountResult[0]?.total || 0;
|
|
15101
|
+
}
|
|
15102
|
+
const data = paginate18(items, page, limit, length);
|
|
15103
|
+
return data;
|
|
15104
|
+
} catch (error) {
|
|
15105
|
+
throw error;
|
|
15106
|
+
}
|
|
15107
|
+
}
|
|
15040
15108
|
return {
|
|
15041
15109
|
createIndex,
|
|
15042
15110
|
createTextIndex,
|
|
@@ -15053,7 +15121,8 @@ function useVehicleRepo() {
|
|
|
15053
15121
|
getAllVehiclesByUnitId,
|
|
15054
15122
|
getAllExpiredVehicles,
|
|
15055
15123
|
bulkUpsertVehicles,
|
|
15056
|
-
getSpecificVehicleById
|
|
15124
|
+
getSpecificVehicleById,
|
|
15125
|
+
getBlocklistedVehicles
|
|
15057
15126
|
};
|
|
15058
15127
|
}
|
|
15059
15128
|
|
|
@@ -20537,7 +20606,8 @@ function useVehicleController() {
|
|
|
20537
20606
|
getVehicleById: _getVehicleById,
|
|
20538
20607
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
20539
20608
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId,
|
|
20540
|
-
getSpecificVehicleById: _getSpecificVehicleById
|
|
20609
|
+
getSpecificVehicleById: _getSpecificVehicleById,
|
|
20610
|
+
getBlocklistedVehicles: _getBlocklistedVehicles
|
|
20541
20611
|
} = useVehicleRepo();
|
|
20542
20612
|
function normalizeRow(row) {
|
|
20543
20613
|
return Object.fromEntries(
|
|
@@ -21073,6 +21143,38 @@ function useVehicleController() {
|
|
|
21073
21143
|
return;
|
|
21074
21144
|
}
|
|
21075
21145
|
}
|
|
21146
|
+
async function getBlocklistedVehicles(req, res, next) {
|
|
21147
|
+
const schema2 = Joi46.object({
|
|
21148
|
+
search: Joi46.string().optional().allow("", null),
|
|
21149
|
+
page: Joi46.number().integer().min(1).optional().default(1),
|
|
21150
|
+
limit: Joi46.number().integer().min(1).max(100).optional().default(10),
|
|
21151
|
+
site: Joi46.string().hex().length(24).optional().allow(null, "")
|
|
21152
|
+
});
|
|
21153
|
+
const { error, value } = schema2.validate(req.query, {
|
|
21154
|
+
abortEarly: false
|
|
21155
|
+
});
|
|
21156
|
+
if (error) {
|
|
21157
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
21158
|
+
logger65.log({ level: "error", message: messages });
|
|
21159
|
+
next(new BadRequestError84(messages));
|
|
21160
|
+
return;
|
|
21161
|
+
}
|
|
21162
|
+
const { search, page, limit, site } = value;
|
|
21163
|
+
try {
|
|
21164
|
+
const data = await _getBlocklistedVehicles({
|
|
21165
|
+
search,
|
|
21166
|
+
page,
|
|
21167
|
+
limit,
|
|
21168
|
+
site
|
|
21169
|
+
});
|
|
21170
|
+
res.json(data);
|
|
21171
|
+
return;
|
|
21172
|
+
} catch (error2) {
|
|
21173
|
+
logger65.log({ level: "error", message: error2.message });
|
|
21174
|
+
next(error2);
|
|
21175
|
+
return;
|
|
21176
|
+
}
|
|
21177
|
+
}
|
|
21076
21178
|
return {
|
|
21077
21179
|
add,
|
|
21078
21180
|
getVehicles,
|
|
@@ -21085,7 +21187,8 @@ function useVehicleController() {
|
|
|
21085
21187
|
reactivateVehicleById,
|
|
21086
21188
|
getAllVehiclesByUnitId,
|
|
21087
21189
|
uploadSpreadsheetVehicles,
|
|
21088
|
-
getSpecificVehicleById
|
|
21190
|
+
getSpecificVehicleById,
|
|
21191
|
+
getBlocklistedVehicles
|
|
21089
21192
|
};
|
|
21090
21193
|
}
|
|
21091
21194
|
|