@7365admin1/core 3.41.0 → 3.42.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 +33 -0
- package/dist/index.d.ts +22 -1
- package/dist/index.js +333 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +579 -272
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/site-name.util.test.mjs +146 -0
package/dist/index.mjs
CHANGED
|
@@ -537,13 +537,13 @@ var require_logger = __commonJS({
|
|
|
537
537
|
"use strict";
|
|
538
538
|
exports.__esModule = true;
|
|
539
539
|
var _utils = require_utils();
|
|
540
|
-
var
|
|
540
|
+
var logger202 = {
|
|
541
541
|
methodMap: ["debug", "info", "warn", "error"],
|
|
542
542
|
level: "info",
|
|
543
543
|
// Maps a given level value to the `methodMap` indexes above.
|
|
544
544
|
lookupLevel: function lookupLevel(level) {
|
|
545
545
|
if (typeof level === "string") {
|
|
546
|
-
var levelMap = _utils.indexOf(
|
|
546
|
+
var levelMap = _utils.indexOf(logger202.methodMap, level.toLowerCase());
|
|
547
547
|
if (levelMap >= 0) {
|
|
548
548
|
level = levelMap;
|
|
549
549
|
} else {
|
|
@@ -554,9 +554,9 @@ var require_logger = __commonJS({
|
|
|
554
554
|
},
|
|
555
555
|
// Can be overridden in the host environment
|
|
556
556
|
log: function log(level) {
|
|
557
|
-
level =
|
|
558
|
-
if (typeof console !== "undefined" &&
|
|
559
|
-
var method =
|
|
557
|
+
level = logger202.lookupLevel(level);
|
|
558
|
+
if (typeof console !== "undefined" && logger202.lookupLevel(logger202.level) <= level) {
|
|
559
|
+
var method = logger202.methodMap[level];
|
|
560
560
|
if (!console[method]) {
|
|
561
561
|
method = "log";
|
|
562
562
|
}
|
|
@@ -567,7 +567,7 @@ var require_logger = __commonJS({
|
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
|
-
exports["default"] =
|
|
570
|
+
exports["default"] = logger202;
|
|
571
571
|
module.exports = exports["default"];
|
|
572
572
|
}
|
|
573
573
|
});
|
|
@@ -11249,8 +11249,9 @@ function useSiteRepo() {
|
|
|
11249
11249
|
} catch (error2) {
|
|
11250
11250
|
throw new BadRequestError18("Invalid org ID format.");
|
|
11251
11251
|
}
|
|
11252
|
+
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11252
11253
|
const query = {
|
|
11253
|
-
name: { $regex: new RegExp(`^${
|
|
11254
|
+
name: { $regex: new RegExp(`^${escapedName}$`, "i") },
|
|
11254
11255
|
// Case-insensitive exact match
|
|
11255
11256
|
orgId,
|
|
11256
11257
|
status: { $ne: "deleted" }
|
|
@@ -32346,7 +32347,57 @@ import {
|
|
|
32346
32347
|
useAtlas as useAtlas46,
|
|
32347
32348
|
NotFoundError as NotFoundError20
|
|
32348
32349
|
} from "@7365admin1/node-server-utils";
|
|
32350
|
+
|
|
32351
|
+
// src/utils/site-name.util.ts
|
|
32349
32352
|
import levenshtein from "fast-levenshtein";
|
|
32353
|
+
var ROMAN = /^(?=[ivx])(x{0,3})(ix|iv|v?i{0,3})$/;
|
|
32354
|
+
var ROMAN_VALUE = { i: 1, v: 5, x: 10 };
|
|
32355
|
+
function normalizeSiteName(name) {
|
|
32356
|
+
return String(name ?? "").normalize("NFKC").toLowerCase().replace(/[‘’']/g, "").replace(/[^a-z0-9]+/g, " ").trim();
|
|
32357
|
+
}
|
|
32358
|
+
function romanToNumber(token) {
|
|
32359
|
+
let total = 0;
|
|
32360
|
+
for (let i = 0; i < token.length; i++) {
|
|
32361
|
+
const value = ROMAN_VALUE[token[i]];
|
|
32362
|
+
const next = ROMAN_VALUE[token[i + 1]];
|
|
32363
|
+
total += next && next > value ? -value : value;
|
|
32364
|
+
}
|
|
32365
|
+
return total;
|
|
32366
|
+
}
|
|
32367
|
+
function distinguishingTokens(normalized) {
|
|
32368
|
+
if (!normalized)
|
|
32369
|
+
return [];
|
|
32370
|
+
return normalized.split(" ").filter((t) => /^\d+$/.test(t) || ROMAN.test(t) || /^[a-z]$/.test(t)).map((t) => ROMAN.test(t) ? String(romanToNumber(t)) : t);
|
|
32371
|
+
}
|
|
32372
|
+
function matchSiteName(candidate, existing) {
|
|
32373
|
+
const a = normalizeSiteName(candidate);
|
|
32374
|
+
const b = normalizeSiteName(existing);
|
|
32375
|
+
if (!a || !b)
|
|
32376
|
+
return null;
|
|
32377
|
+
if (a === b)
|
|
32378
|
+
return "duplicate";
|
|
32379
|
+
const tokensA = distinguishingTokens(a).join(" ");
|
|
32380
|
+
const tokensB = distinguishingTokens(b).join(" ");
|
|
32381
|
+
if (tokensA !== tokensB)
|
|
32382
|
+
return null;
|
|
32383
|
+
return levenshtein.get(a, b) <= 2 ? "near-duplicate" : null;
|
|
32384
|
+
}
|
|
32385
|
+
function findSiteNameClash(candidate, existingNames) {
|
|
32386
|
+
for (const name of existingNames) {
|
|
32387
|
+
const match = matchSiteName(candidate, name);
|
|
32388
|
+
if (match)
|
|
32389
|
+
return { name, match };
|
|
32390
|
+
}
|
|
32391
|
+
return null;
|
|
32392
|
+
}
|
|
32393
|
+
function siteNameClashMessage(existingName, match) {
|
|
32394
|
+
if (match === "duplicate") {
|
|
32395
|
+
return `A site called "${existingName}" already exists in this organisation. Give the new site a different name, or edit "${existingName}" instead.`;
|
|
32396
|
+
}
|
|
32397
|
+
return `This name is within a character or two of "${existingName}", which already exists in this organisation. If it is the same property, edit "${existingName}" instead. If it is a different one, include what tells them apart \u2014 the block, tower, phase, or number \u2014 and save again.`;
|
|
32398
|
+
}
|
|
32399
|
+
|
|
32400
|
+
// src/services/customer-site.service.ts
|
|
32350
32401
|
function useCustomerSiteService() {
|
|
32351
32402
|
const { add: _add, updateCustomerSiteById, getById: _getById } = useCustomerSiteRepo();
|
|
32352
32403
|
const {
|
|
@@ -32368,20 +32419,18 @@ function useCustomerSiteService() {
|
|
|
32368
32419
|
const exactMatches = await getSiteByExactName(value.name, value.siteOrg);
|
|
32369
32420
|
if (exactMatches && exactMatches.length > 0) {
|
|
32370
32421
|
throw new BadRequestError91(
|
|
32371
|
-
|
|
32422
|
+
siteNameClashMessage(exactMatches[0].name, "duplicate")
|
|
32372
32423
|
);
|
|
32373
32424
|
}
|
|
32374
|
-
const threshold = 2;
|
|
32375
32425
|
const sites = await getSiteByName(value.name);
|
|
32376
|
-
|
|
32377
|
-
|
|
32378
|
-
|
|
32379
|
-
|
|
32380
|
-
|
|
32381
|
-
|
|
32382
|
-
|
|
32383
|
-
|
|
32384
|
-
}
|
|
32426
|
+
const candidates = (sites ?? []).filter(
|
|
32427
|
+
(doc) => doc.orgId && doc.name && doc.orgId.toString() === value.siteOrg.toString()
|
|
32428
|
+
).map((doc) => doc.name);
|
|
32429
|
+
const clash = findSiteNameClash(value.name, candidates);
|
|
32430
|
+
if (clash) {
|
|
32431
|
+
throw new BadRequestError91(
|
|
32432
|
+
siteNameClashMessage(clash.name, clash.match)
|
|
32433
|
+
);
|
|
32385
32434
|
}
|
|
32386
32435
|
const siteId = await createSite(
|
|
32387
32436
|
{
|
|
@@ -65017,9 +65066,19 @@ import { ObjectId as ObjectId135 } from "mongodb";
|
|
|
65017
65066
|
import { BadRequestError as BadRequestError199, logger as logger178 } from "@7365admin1/node-server-utils";
|
|
65018
65067
|
import { ObjectId as ObjectId134 } from "mongodb";
|
|
65019
65068
|
import Joi126 from "joi";
|
|
65069
|
+
var BillingPaymentStatus = /* @__PURE__ */ ((BillingPaymentStatus2) => {
|
|
65070
|
+
BillingPaymentStatus2["PENDING"] = "pending";
|
|
65071
|
+
BillingPaymentStatus2["SUCCESS"] = "success";
|
|
65072
|
+
BillingPaymentStatus2["FAILED"] = "failed";
|
|
65073
|
+
BillingPaymentStatus2["PARTIAL"] = "partial";
|
|
65074
|
+
BillingPaymentStatus2["CANCELLED"] = "cancelled";
|
|
65075
|
+
return BillingPaymentStatus2;
|
|
65076
|
+
})(BillingPaymentStatus || {});
|
|
65020
65077
|
var schemaBillingItems = Joi126.object({
|
|
65021
65078
|
_id: Joi126.string().hex().optional(),
|
|
65022
|
-
name: Joi126.string().optional().allow(null, "")
|
|
65079
|
+
name: Joi126.string().optional().allow(null, ""),
|
|
65080
|
+
amount: Joi126.number().optional().allow(null, ""),
|
|
65081
|
+
referenceNumber: Joi126.string().optional().allow(null, "")
|
|
65023
65082
|
});
|
|
65024
65083
|
var schemaBillingPayments = Joi126.object({
|
|
65025
65084
|
_id: Joi126.string().hex().optional(),
|
|
@@ -65110,7 +65169,9 @@ import {
|
|
|
65110
65169
|
useAtlas as useAtlas114,
|
|
65111
65170
|
logger as logger179,
|
|
65112
65171
|
BadRequestError as BadRequestError200,
|
|
65113
|
-
|
|
65172
|
+
NotFoundError as NotFoundError53,
|
|
65173
|
+
AppError as AppError28,
|
|
65174
|
+
paginate as paginate60
|
|
65114
65175
|
} from "@7365admin1/node-server-utils";
|
|
65115
65176
|
var useRedDotPaymentRepo = () => {
|
|
65116
65177
|
const getDB2 = () => {
|
|
@@ -65132,12 +65193,60 @@ var useRedDotPaymentRepo = () => {
|
|
|
65132
65193
|
const redDotMerchantCollection = () => {
|
|
65133
65194
|
return getDB2().collection("payment-gateways");
|
|
65134
65195
|
};
|
|
65196
|
+
async function createIndexes() {
|
|
65197
|
+
try {
|
|
65198
|
+
await paymentCollection().createIndexes([
|
|
65199
|
+
// A referenceNumber-prefixed compound index serves both the lookup by
|
|
65200
|
+
// reference alone and the { referenceNumber, status } lookups used by
|
|
65201
|
+
// the pay single / pay multiple flows.
|
|
65202
|
+
{
|
|
65203
|
+
key: { referenceNumber: 1, status: 1 },
|
|
65204
|
+
name: "referenceNumber_1_status_1"
|
|
65205
|
+
}
|
|
65206
|
+
]);
|
|
65207
|
+
} catch (error) {
|
|
65208
|
+
logger179.log({
|
|
65209
|
+
level: "error",
|
|
65210
|
+
message: error.message
|
|
65211
|
+
});
|
|
65212
|
+
throw new InternalServerError68(
|
|
65213
|
+
"Failed to create index on billing payments."
|
|
65214
|
+
);
|
|
65215
|
+
}
|
|
65216
|
+
}
|
|
65217
|
+
async function getPaymentByReference(referenceNumber, session) {
|
|
65218
|
+
const reference = typeof referenceNumber === "string" ? referenceNumber.trim() : "";
|
|
65219
|
+
if (!reference) {
|
|
65220
|
+
throw new BadRequestError200("Reference number is required.");
|
|
65221
|
+
}
|
|
65222
|
+
try {
|
|
65223
|
+
const payment = await paymentCollection().findOne(
|
|
65224
|
+
{
|
|
65225
|
+
referenceNumber: reference
|
|
65226
|
+
},
|
|
65227
|
+
{ session }
|
|
65228
|
+
);
|
|
65229
|
+
if (!payment) {
|
|
65230
|
+
throw new NotFoundError53("Payment not found.");
|
|
65231
|
+
}
|
|
65232
|
+
return payment;
|
|
65233
|
+
} catch (error) {
|
|
65234
|
+
if (error instanceof AppError28) {
|
|
65235
|
+
throw error;
|
|
65236
|
+
}
|
|
65237
|
+
logger179.log({
|
|
65238
|
+
level: "error",
|
|
65239
|
+
message: error.message
|
|
65240
|
+
});
|
|
65241
|
+
throw new InternalServerError68("Failed to get payment.");
|
|
65242
|
+
}
|
|
65243
|
+
}
|
|
65135
65244
|
async function createPayment(type, payload, session) {
|
|
65136
65245
|
if (type == "single") {
|
|
65137
65246
|
try {
|
|
65138
65247
|
payload = MBillingItems(payload);
|
|
65139
|
-
|
|
65140
|
-
return
|
|
65248
|
+
await paymentCollection().insertOne(payload, { session });
|
|
65249
|
+
return payload.referenceNumber;
|
|
65141
65250
|
} catch (error) {
|
|
65142
65251
|
logger179.log({
|
|
65143
65252
|
level: "error",
|
|
@@ -65166,7 +65275,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
65166
65275
|
{ $set: { referenceNumber } },
|
|
65167
65276
|
{ session }
|
|
65168
65277
|
);
|
|
65169
|
-
return
|
|
65278
|
+
return referenceNumber;
|
|
65170
65279
|
} catch (error) {
|
|
65171
65280
|
logger179.log({
|
|
65172
65281
|
level: "error",
|
|
@@ -65184,6 +65293,76 @@ var useRedDotPaymentRepo = () => {
|
|
|
65184
65293
|
}
|
|
65185
65294
|
}
|
|
65186
65295
|
}
|
|
65296
|
+
async function getPaidBills({
|
|
65297
|
+
search = "",
|
|
65298
|
+
page = 1,
|
|
65299
|
+
limit = 10,
|
|
65300
|
+
sort = {},
|
|
65301
|
+
month,
|
|
65302
|
+
year,
|
|
65303
|
+
unitId
|
|
65304
|
+
}, session) {
|
|
65305
|
+
let _unitId;
|
|
65306
|
+
try {
|
|
65307
|
+
_unitId = new ObjectId135(unitId);
|
|
65308
|
+
} catch {
|
|
65309
|
+
throw new BadRequestError200("Invalid unit ID format.");
|
|
65310
|
+
}
|
|
65311
|
+
page = page > 0 ? page - 1 : 0;
|
|
65312
|
+
let dateExpr = {};
|
|
65313
|
+
const datePaidRange = buildDatePaidRange(month, year);
|
|
65314
|
+
if (datePaidRange) {
|
|
65315
|
+
dateExpr.datePaid = datePaidRange;
|
|
65316
|
+
}
|
|
65317
|
+
const query = {
|
|
65318
|
+
unitId: _unitId,
|
|
65319
|
+
status: "success",
|
|
65320
|
+
...search && {
|
|
65321
|
+
$or: [
|
|
65322
|
+
{ referenceNumber: { $regex: search, $options: "i" } },
|
|
65323
|
+
{ unitOwner: { $regex: search, $options: "i" } },
|
|
65324
|
+
{ method: { $regex: search, $options: "i" } },
|
|
65325
|
+
{ transaction_id: { $regex: search, $options: "i" } },
|
|
65326
|
+
{ "unitBillingItems.name": { $regex: search, $options: "i" } },
|
|
65327
|
+
{
|
|
65328
|
+
$expr: {
|
|
65329
|
+
$regexMatch: {
|
|
65330
|
+
input: { $toString: "$totalAmount" },
|
|
65331
|
+
regex: search,
|
|
65332
|
+
options: "i"
|
|
65333
|
+
}
|
|
65334
|
+
}
|
|
65335
|
+
}
|
|
65336
|
+
]
|
|
65337
|
+
},
|
|
65338
|
+
...dateExpr
|
|
65339
|
+
};
|
|
65340
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
65341
|
+
try {
|
|
65342
|
+
const basePipeline = [
|
|
65343
|
+
{ $match: query },
|
|
65344
|
+
{ $sort: sort },
|
|
65345
|
+
{ $skip: page * limit },
|
|
65346
|
+
{ $limit: limit }
|
|
65347
|
+
];
|
|
65348
|
+
const [items, countResult] = await Promise.all([
|
|
65349
|
+
paymentCollection().aggregate(basePipeline, { session }).toArray(),
|
|
65350
|
+
paymentCollection().aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
65351
|
+
]);
|
|
65352
|
+
const totalCount = countResult[0]?.total || 0;
|
|
65353
|
+
const data = paginate60(items, page, limit, totalCount);
|
|
65354
|
+
return data;
|
|
65355
|
+
} catch (error) {
|
|
65356
|
+
if (error instanceof AppError28) {
|
|
65357
|
+
throw error;
|
|
65358
|
+
}
|
|
65359
|
+
logger179.log({
|
|
65360
|
+
level: "error",
|
|
65361
|
+
message: error.message
|
|
65362
|
+
});
|
|
65363
|
+
throw new InternalServerError68("Failed to retrieve paid bills.");
|
|
65364
|
+
}
|
|
65365
|
+
}
|
|
65187
65366
|
async function paySingleUnitBill(refId, payload) {
|
|
65188
65367
|
const session = useAtlas114.getClient()?.startSession();
|
|
65189
65368
|
try {
|
|
@@ -65346,6 +65525,52 @@ var useRedDotPaymentRepo = () => {
|
|
|
65346
65525
|
session?.endSession();
|
|
65347
65526
|
}
|
|
65348
65527
|
}
|
|
65528
|
+
function buildDatePaidRange(month, year) {
|
|
65529
|
+
if (!year)
|
|
65530
|
+
return null;
|
|
65531
|
+
const yearNum = Number(year);
|
|
65532
|
+
if (!Number.isInteger(yearNum) || yearNum < 1970 || yearNum > 9999) {
|
|
65533
|
+
throw new BadRequestError200("Invalid year filter.");
|
|
65534
|
+
}
|
|
65535
|
+
if (month) {
|
|
65536
|
+
const monthNum = Number(month);
|
|
65537
|
+
if (!Number.isInteger(monthNum) || monthNum < 1 || monthNum > 12) {
|
|
65538
|
+
throw new BadRequestError200("Invalid month filter.");
|
|
65539
|
+
}
|
|
65540
|
+
return {
|
|
65541
|
+
$gte: new Date(yearNum, monthNum - 1, 1),
|
|
65542
|
+
$lt: new Date(yearNum, monthNum, 1)
|
|
65543
|
+
};
|
|
65544
|
+
}
|
|
65545
|
+
return {
|
|
65546
|
+
$gte: new Date(yearNum, 0, 1),
|
|
65547
|
+
$lt: new Date(yearNum + 1, 0, 1)
|
|
65548
|
+
};
|
|
65549
|
+
}
|
|
65550
|
+
async function updateStatus(referenceNumber, status, session) {
|
|
65551
|
+
const reference = typeof referenceNumber === "string" ? referenceNumber.trim() : "";
|
|
65552
|
+
if (!reference) {
|
|
65553
|
+
throw new BadRequestError200("Reference number is required.");
|
|
65554
|
+
}
|
|
65555
|
+
try {
|
|
65556
|
+
const res = await paymentCollection().updateOne(
|
|
65557
|
+
{ referenceNumber: reference, status: "pending" },
|
|
65558
|
+
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
65559
|
+
{ session }
|
|
65560
|
+
);
|
|
65561
|
+
if (res.matchedCount === 0) {
|
|
65562
|
+
throw new NotFoundError53(
|
|
65563
|
+
"Payment not found or is no longer pending."
|
|
65564
|
+
);
|
|
65565
|
+
}
|
|
65566
|
+
return res;
|
|
65567
|
+
} catch (error) {
|
|
65568
|
+
if (error instanceof AppError28) {
|
|
65569
|
+
throw error;
|
|
65570
|
+
}
|
|
65571
|
+
throw new InternalServerError68("Failed to update payment status.");
|
|
65572
|
+
}
|
|
65573
|
+
}
|
|
65349
65574
|
function formatDateString(today) {
|
|
65350
65575
|
today = typeof today === "string" ? new Date(today) : today;
|
|
65351
65576
|
let month = today.getMonth() + 1;
|
|
@@ -65354,7 +65579,15 @@ var useRedDotPaymentRepo = () => {
|
|
|
65354
65579
|
const formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
65355
65580
|
return formattedDate;
|
|
65356
65581
|
}
|
|
65357
|
-
return {
|
|
65582
|
+
return {
|
|
65583
|
+
paySingleUnitBill,
|
|
65584
|
+
createPayment,
|
|
65585
|
+
payMultipleUnitBill,
|
|
65586
|
+
getPaidBills,
|
|
65587
|
+
createIndexes,
|
|
65588
|
+
getPaymentByReference,
|
|
65589
|
+
updateStatus
|
|
65590
|
+
};
|
|
65358
65591
|
};
|
|
65359
65592
|
|
|
65360
65593
|
// src/services/reddot-payment.service.ts
|
|
@@ -65464,7 +65697,7 @@ var useRedDotPaymentSvc = () => {
|
|
|
65464
65697
|
const success = {
|
|
65465
65698
|
...basePayload,
|
|
65466
65699
|
paymentStatus: "paid" /* PAID */,
|
|
65467
|
-
amountPaid:
|
|
65700
|
+
amountPaid: Number(amount)
|
|
65468
65701
|
};
|
|
65469
65702
|
if (isBulk) {
|
|
65470
65703
|
await payMultipleUnitBill(refId, success);
|
|
@@ -65496,9 +65729,14 @@ var useRedDotPaymentSvc = () => {
|
|
|
65496
65729
|
|
|
65497
65730
|
// src/controllers/reddot-payment.controller.ts
|
|
65498
65731
|
import Joi127 from "joi";
|
|
65499
|
-
import { BadRequestError as BadRequestError201 } from "@7365admin1/node-server-utils";
|
|
65732
|
+
import { BadRequestError as BadRequestError201, logger as logger180 } from "@7365admin1/node-server-utils";
|
|
65500
65733
|
function useRedDotPaymentController() {
|
|
65501
|
-
const {
|
|
65734
|
+
const {
|
|
65735
|
+
createPayment: _createPayment,
|
|
65736
|
+
updateStatus: _updateStatus,
|
|
65737
|
+
getPaymentByReference: _getPaymentByReference,
|
|
65738
|
+
getPaidBills: _getPaidBills
|
|
65739
|
+
} = useRedDotPaymentRepo();
|
|
65502
65740
|
const redirectPaymentTransaction = async (req, res) => {
|
|
65503
65741
|
try {
|
|
65504
65742
|
const data = req.body;
|
|
@@ -65562,17 +65800,86 @@ function useRedDotPaymentController() {
|
|
|
65562
65800
|
try {
|
|
65563
65801
|
const payment = await _createPayment(type, value);
|
|
65564
65802
|
res.status(201).json({
|
|
65565
|
-
message: "
|
|
65803
|
+
message: "success",
|
|
65566
65804
|
data: payment
|
|
65567
65805
|
});
|
|
65568
65806
|
} catch (error) {
|
|
65569
|
-
|
|
65807
|
+
const status = error?.statusCode ?? 500;
|
|
65808
|
+
res.status(status).json({ message: "failed" });
|
|
65809
|
+
}
|
|
65810
|
+
}
|
|
65811
|
+
async function updateStatus(req, res, next) {
|
|
65812
|
+
const schema2 = Joi127.object({
|
|
65813
|
+
referenceNumber: Joi127.string().required(),
|
|
65814
|
+
status: Joi127.string().valid(...Object.values(BillingPaymentStatus)).required()
|
|
65815
|
+
});
|
|
65816
|
+
const { error, value } = schema2.validate({
|
|
65817
|
+
referenceNumber: req.params.id,
|
|
65818
|
+
status: req.body.status
|
|
65819
|
+
});
|
|
65820
|
+
if (error) {
|
|
65821
|
+
logger180.log({ level: "error", message: error.message });
|
|
65822
|
+
next(new BadRequestError201(error.message));
|
|
65823
|
+
return;
|
|
65824
|
+
}
|
|
65825
|
+
try {
|
|
65826
|
+
const data = await _updateStatus(value.referenceNumber, value.status);
|
|
65827
|
+
res.status(200).json({ message: "success", data });
|
|
65828
|
+
return;
|
|
65829
|
+
} catch (error2) {
|
|
65830
|
+
logger180.log({ level: "error", message: error2.message });
|
|
65831
|
+
next(error2);
|
|
65832
|
+
return;
|
|
65833
|
+
}
|
|
65834
|
+
}
|
|
65835
|
+
async function getPaymentByReference(req, res, next) {
|
|
65836
|
+
const schema2 = Joi127.object({
|
|
65837
|
+
referenceNumber: Joi127.string().required()
|
|
65838
|
+
});
|
|
65839
|
+
const { error, value } = schema2.validate(req.params);
|
|
65840
|
+
if (error) {
|
|
65841
|
+
next(new BadRequestError201(error.message));
|
|
65842
|
+
return;
|
|
65843
|
+
}
|
|
65844
|
+
try {
|
|
65845
|
+
const payment = await _getPaymentByReference(value.referenceNumber);
|
|
65846
|
+
res.json({ data: payment });
|
|
65847
|
+
return;
|
|
65848
|
+
} catch (error2) {
|
|
65849
|
+
next(error2);
|
|
65850
|
+
return;
|
|
65851
|
+
}
|
|
65852
|
+
}
|
|
65853
|
+
async function getPaidBills(req, res, next) {
|
|
65854
|
+
const schema2 = Joi127.object({
|
|
65855
|
+
unitId: Joi127.string().hex().length(24).required(),
|
|
65856
|
+
page: Joi127.number().integer().min(1).default(1),
|
|
65857
|
+
limit: Joi127.number().integer().min(1).max(100).default(10),
|
|
65858
|
+
search: Joi127.string().trim().allow("").default(""),
|
|
65859
|
+
month: Joi127.string().pattern(/^(0?[1-9]|1[0-2])$/).allow("").optional(),
|
|
65860
|
+
year: Joi127.string().pattern(/^\d{4}$/).allow("").optional()
|
|
65861
|
+
});
|
|
65862
|
+
const { error, value } = schema2.validate({ ...req.params, ...req.query });
|
|
65863
|
+
if (error) {
|
|
65864
|
+
next(new BadRequestError201(error.message));
|
|
65865
|
+
return;
|
|
65866
|
+
}
|
|
65867
|
+
try {
|
|
65868
|
+
const bills = await _getPaidBills(value);
|
|
65869
|
+
res.json({ data: bills });
|
|
65870
|
+
return;
|
|
65871
|
+
} catch (error2) {
|
|
65872
|
+
next(error2);
|
|
65873
|
+
return;
|
|
65570
65874
|
}
|
|
65571
65875
|
}
|
|
65572
65876
|
return {
|
|
65573
65877
|
redirectPaymentTransaction,
|
|
65574
65878
|
enquirePaymentTransaction,
|
|
65575
|
-
createPayment
|
|
65879
|
+
createPayment,
|
|
65880
|
+
getPaymentByReference,
|
|
65881
|
+
updateStatus,
|
|
65882
|
+
getPaidBills
|
|
65576
65883
|
};
|
|
65577
65884
|
}
|
|
65578
65885
|
|
|
@@ -65580,10 +65887,10 @@ function useRedDotPaymentController() {
|
|
|
65580
65887
|
import {
|
|
65581
65888
|
useMailer as useMailer5,
|
|
65582
65889
|
compileHandlebar as compileHandlebar5,
|
|
65583
|
-
logger as
|
|
65890
|
+
logger as logger181,
|
|
65584
65891
|
getDirectory as getDirectory5,
|
|
65585
65892
|
BadRequestError as BadRequestError202,
|
|
65586
|
-
NotFoundError as
|
|
65893
|
+
NotFoundError as NotFoundError54,
|
|
65587
65894
|
InternalServerError as InternalServerError70,
|
|
65588
65895
|
useAtlas as useAtlas116,
|
|
65589
65896
|
hashPassword as hashPassword4
|
|
@@ -65695,7 +66002,7 @@ function useVerificationServiceV2() {
|
|
|
65695
66002
|
html: emailContent,
|
|
65696
66003
|
sender: "iService365" /* ISERVICE365 */
|
|
65697
66004
|
}).catch((error) => {
|
|
65698
|
-
|
|
66005
|
+
logger181.log({
|
|
65699
66006
|
level: "error",
|
|
65700
66007
|
message: `Error sending user invite email: ${error}`
|
|
65701
66008
|
});
|
|
@@ -65715,7 +66022,7 @@ function useVerificationServiceV2() {
|
|
|
65715
66022
|
session?.startTransaction();
|
|
65716
66023
|
const item = await _getByVerificationCode(verificationCode);
|
|
65717
66024
|
if (!item) {
|
|
65718
|
-
throw new
|
|
66025
|
+
throw new NotFoundError54("Verification not found.");
|
|
65719
66026
|
}
|
|
65720
66027
|
switch (item.status) {
|
|
65721
66028
|
case "expired" /* EXPIRED */:
|
|
@@ -65740,7 +66047,7 @@ function useVerificationServiceV2() {
|
|
|
65740
66047
|
return { _id, type, email, status, expireAt };
|
|
65741
66048
|
} catch (error) {
|
|
65742
66049
|
await session?.abortTransaction();
|
|
65743
|
-
|
|
66050
|
+
logger181.log({
|
|
65744
66051
|
level: "info",
|
|
65745
66052
|
message: `Error verifying user invitation: ${error}`
|
|
65746
66053
|
});
|
|
@@ -65795,7 +66102,7 @@ function useVerificationServiceV2() {
|
|
|
65795
66102
|
html: emailContent,
|
|
65796
66103
|
sender: "iService365" /* ISERVICE365 */
|
|
65797
66104
|
}).catch((error) => {
|
|
65798
|
-
|
|
66105
|
+
logger181.log({
|
|
65799
66106
|
level: "error",
|
|
65800
66107
|
message: `Error sending user ${type} email: ${error}`
|
|
65801
66108
|
});
|
|
@@ -65825,7 +66132,7 @@ function useVerificationServiceV2() {
|
|
|
65825
66132
|
});
|
|
65826
66133
|
if (error) {
|
|
65827
66134
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
65828
|
-
|
|
66135
|
+
logger181.log({ level: "error", message: messages });
|
|
65829
66136
|
throw new BadRequestError202(`Invalid input: ${error.message}`);
|
|
65830
66137
|
}
|
|
65831
66138
|
let subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
@@ -65931,7 +66238,7 @@ function useVerificationServiceV2() {
|
|
|
65931
66238
|
sender: "iService365" /* ISERVICE365 */,
|
|
65932
66239
|
html: emailContent
|
|
65933
66240
|
}).catch((error) => {
|
|
65934
|
-
|
|
66241
|
+
logger181.log({
|
|
65935
66242
|
level: "error",
|
|
65936
66243
|
message: `Error sending forget password email: ${error}`
|
|
65937
66244
|
});
|
|
@@ -65953,7 +66260,7 @@ function useVerificationServiceV2() {
|
|
|
65953
66260
|
async function resendSignUpVerification(email) {
|
|
65954
66261
|
const item = await _getPendingVerificationByEmail(email);
|
|
65955
66262
|
if (!item) {
|
|
65956
|
-
throw new
|
|
66263
|
+
throw new NotFoundError54(
|
|
65957
66264
|
"Pending verification not found."
|
|
65958
66265
|
);
|
|
65959
66266
|
}
|
|
@@ -66007,7 +66314,7 @@ function useVerificationServiceV2() {
|
|
|
66007
66314
|
}
|
|
66008
66315
|
|
|
66009
66316
|
// src/controllers/verification-v2.controller.ts
|
|
66010
|
-
import { BadRequestError as BadRequestError203, logger as
|
|
66317
|
+
import { BadRequestError as BadRequestError203, logger as logger182 } from "@7365admin1/node-server-utils";
|
|
66011
66318
|
import Joi129 from "joi";
|
|
66012
66319
|
function useVerificationControllerV2() {
|
|
66013
66320
|
const {
|
|
@@ -66031,7 +66338,7 @@ function useVerificationControllerV2() {
|
|
|
66031
66338
|
);
|
|
66032
66339
|
if (error) {
|
|
66033
66340
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66034
|
-
|
|
66341
|
+
logger182.log({ level: "error", message: messages });
|
|
66035
66342
|
next(new BadRequestError203(messages));
|
|
66036
66343
|
return;
|
|
66037
66344
|
}
|
|
@@ -66039,7 +66346,7 @@ function useVerificationControllerV2() {
|
|
|
66039
66346
|
res.json(message);
|
|
66040
66347
|
return;
|
|
66041
66348
|
} catch (error) {
|
|
66042
|
-
|
|
66349
|
+
logger182.log({ level: "error", message: `${error.message}` });
|
|
66043
66350
|
next(error);
|
|
66044
66351
|
return;
|
|
66045
66352
|
}
|
|
@@ -66057,7 +66364,7 @@ function useVerificationControllerV2() {
|
|
|
66057
66364
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
66058
66365
|
if (error) {
|
|
66059
66366
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66060
|
-
|
|
66367
|
+
logger182.log({ level: "error", message: messages });
|
|
66061
66368
|
next(new BadRequestError203(messages));
|
|
66062
66369
|
return;
|
|
66063
66370
|
}
|
|
@@ -66077,7 +66384,7 @@ function useVerificationControllerV2() {
|
|
|
66077
66384
|
res.status(201).json({ message: "Successfully invited user." });
|
|
66078
66385
|
return;
|
|
66079
66386
|
} catch (error2) {
|
|
66080
|
-
|
|
66387
|
+
logger182.log({ level: "error", message: `${error2.message}` });
|
|
66081
66388
|
next(error2);
|
|
66082
66389
|
return;
|
|
66083
66390
|
}
|
|
@@ -66092,7 +66399,7 @@ function useVerificationControllerV2() {
|
|
|
66092
66399
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
66093
66400
|
if (error) {
|
|
66094
66401
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66095
|
-
|
|
66402
|
+
logger182.log({ level: "error", message: messages });
|
|
66096
66403
|
next(new BadRequestError203(messages));
|
|
66097
66404
|
return;
|
|
66098
66405
|
}
|
|
@@ -66106,7 +66413,7 @@ function useVerificationControllerV2() {
|
|
|
66106
66413
|
res.cookie("service-provider-email", value.email, cookieOptions).json({ message: "Successfully invited service provider." });
|
|
66107
66414
|
return;
|
|
66108
66415
|
} catch (error2) {
|
|
66109
|
-
|
|
66416
|
+
logger182.log({ level: "error", message: `controller - ${error2.message}` });
|
|
66110
66417
|
next(error2);
|
|
66111
66418
|
return;
|
|
66112
66419
|
}
|
|
@@ -66124,7 +66431,7 @@ function useVerificationControllerV2() {
|
|
|
66124
66431
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
66125
66432
|
if (error) {
|
|
66126
66433
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66127
|
-
|
|
66434
|
+
logger182.log({ level: "error", message: messages });
|
|
66128
66435
|
next(new BadRequestError203(messages));
|
|
66129
66436
|
return;
|
|
66130
66437
|
}
|
|
@@ -66144,7 +66451,7 @@ function useVerificationControllerV2() {
|
|
|
66144
66451
|
res.status(201).json({ message: "Successfully invited user." });
|
|
66145
66452
|
return;
|
|
66146
66453
|
} catch (error2) {
|
|
66147
|
-
|
|
66454
|
+
logger182.log({ level: "error", message: `${error2.message}` });
|
|
66148
66455
|
next(error2);
|
|
66149
66456
|
return;
|
|
66150
66457
|
}
|
|
@@ -66156,7 +66463,7 @@ function useVerificationControllerV2() {
|
|
|
66156
66463
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
66157
66464
|
if (error) {
|
|
66158
66465
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66159
|
-
|
|
66466
|
+
logger182.log({ level: "error", message: messages });
|
|
66160
66467
|
next(new BadRequestError203(messages));
|
|
66161
66468
|
return;
|
|
66162
66469
|
}
|
|
@@ -66168,7 +66475,7 @@ function useVerificationControllerV2() {
|
|
|
66168
66475
|
});
|
|
66169
66476
|
return;
|
|
66170
66477
|
} catch (error2) {
|
|
66171
|
-
|
|
66478
|
+
logger182.log({ level: "error", message: `${error2.message}` });
|
|
66172
66479
|
next(error2);
|
|
66173
66480
|
return;
|
|
66174
66481
|
}
|
|
@@ -66188,7 +66495,7 @@ function useVerificationControllerV2() {
|
|
|
66188
66495
|
const { error, value } = schema2.validate(req.query);
|
|
66189
66496
|
if (error) {
|
|
66190
66497
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66191
|
-
|
|
66498
|
+
logger182.log({ level: "error", message: messages });
|
|
66192
66499
|
next(new BadRequestError203(messages));
|
|
66193
66500
|
return;
|
|
66194
66501
|
}
|
|
@@ -66205,7 +66512,7 @@ function useVerificationControllerV2() {
|
|
|
66205
66512
|
res.json(data);
|
|
66206
66513
|
return;
|
|
66207
66514
|
} catch (error2) {
|
|
66208
|
-
|
|
66515
|
+
logger182.log({ level: "error", message: `${error2.message}` });
|
|
66209
66516
|
next(error2);
|
|
66210
66517
|
return;
|
|
66211
66518
|
}
|
|
@@ -66215,7 +66522,7 @@ function useVerificationControllerV2() {
|
|
|
66215
66522
|
const otpId = req.params.id;
|
|
66216
66523
|
const { error } = validation.validate(otpId);
|
|
66217
66524
|
if (error) {
|
|
66218
|
-
|
|
66525
|
+
logger182.log({ level: "error", message: `${error.message}` });
|
|
66219
66526
|
next(new BadRequestError203(error.message));
|
|
66220
66527
|
return;
|
|
66221
66528
|
}
|
|
@@ -66226,7 +66533,7 @@ function useVerificationControllerV2() {
|
|
|
66226
66533
|
});
|
|
66227
66534
|
return;
|
|
66228
66535
|
} catch (error2) {
|
|
66229
|
-
|
|
66536
|
+
logger182.log({ level: "error", message: `${error2.message}` });
|
|
66230
66537
|
next(error2);
|
|
66231
66538
|
return;
|
|
66232
66539
|
}
|
|
@@ -66266,14 +66573,14 @@ function useVerificationControllerV2() {
|
|
|
66266
66573
|
|
|
66267
66574
|
// src/controllers/auth-v2.controller.ts
|
|
66268
66575
|
import Joi130 from "joi";
|
|
66269
|
-
import { BadRequestError as BadRequestError207, logger as
|
|
66576
|
+
import { BadRequestError as BadRequestError207, logger as logger185 } from "@7365admin1/node-server-utils";
|
|
66270
66577
|
|
|
66271
66578
|
// src/services/auth-v2.service.ts
|
|
66272
66579
|
import {
|
|
66273
66580
|
BadRequestError as BadRequestError205,
|
|
66274
66581
|
comparePassword as comparePassword3,
|
|
66275
66582
|
InternalServerError as InternalServerError72,
|
|
66276
|
-
NotFoundError as
|
|
66583
|
+
NotFoundError as NotFoundError56,
|
|
66277
66584
|
useAtlas as useAtlas118,
|
|
66278
66585
|
useCache as useCache68
|
|
66279
66586
|
} from "@7365admin1/node-server-utils";
|
|
@@ -66284,10 +66591,10 @@ import { ObjectId as ObjectId136 } from "mongodb";
|
|
|
66284
66591
|
import {
|
|
66285
66592
|
useAtlas as useAtlas117,
|
|
66286
66593
|
InternalServerError as InternalServerError71,
|
|
66287
|
-
logger as
|
|
66594
|
+
logger as logger183,
|
|
66288
66595
|
BadRequestError as BadRequestError204,
|
|
66289
|
-
paginate as
|
|
66290
|
-
NotFoundError as
|
|
66596
|
+
paginate as paginate61,
|
|
66597
|
+
NotFoundError as NotFoundError55,
|
|
66291
66598
|
AppError as AppError29,
|
|
66292
66599
|
useCache as useCache67,
|
|
66293
66600
|
makeCacheKey as makeCacheKey64,
|
|
@@ -66333,16 +66640,16 @@ function useUserRepoV2() {
|
|
|
66333
66640
|
value = MUser(value);
|
|
66334
66641
|
const res = await collection.insertOne(value, { session });
|
|
66335
66642
|
delNamespace().then(
|
|
66336
|
-
() =>
|
|
66643
|
+
() => logger183.info(`Cache cleared for namespace: ${namespace_collection}`)
|
|
66337
66644
|
).catch(
|
|
66338
|
-
(err) =>
|
|
66645
|
+
(err) => logger183.error(
|
|
66339
66646
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
66340
66647
|
err
|
|
66341
66648
|
)
|
|
66342
66649
|
);
|
|
66343
66650
|
return res.insertedId;
|
|
66344
66651
|
} catch (error) {
|
|
66345
|
-
|
|
66652
|
+
logger183.log({ level: "error", message: `${error}` });
|
|
66346
66653
|
if (error.message.includes("duplicate")) {
|
|
66347
66654
|
throw new BadRequestError204("User already exists.");
|
|
66348
66655
|
}
|
|
@@ -66354,14 +66661,14 @@ function useUserRepoV2() {
|
|
|
66354
66661
|
const cacheKey = makeCacheKey64(namespace_collection, { email });
|
|
66355
66662
|
const cachedData = await getCache(cacheKey);
|
|
66356
66663
|
if (cachedData) {
|
|
66357
|
-
|
|
66664
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66358
66665
|
return cachedData;
|
|
66359
66666
|
}
|
|
66360
66667
|
const data = await collection.findOne({
|
|
66361
66668
|
email: { $regex: `^${email}$`, $options: "i" }
|
|
66362
66669
|
});
|
|
66363
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66364
|
-
(err) =>
|
|
66670
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66671
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66365
66672
|
);
|
|
66366
66673
|
return data;
|
|
66367
66674
|
} catch (error) {
|
|
@@ -66376,15 +66683,15 @@ function useUserRepoV2() {
|
|
|
66376
66683
|
});
|
|
66377
66684
|
const cachedData = await getCache(cacheKey);
|
|
66378
66685
|
if (cachedData) {
|
|
66379
|
-
|
|
66686
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66380
66687
|
return cachedData;
|
|
66381
66688
|
}
|
|
66382
66689
|
const data = await collection.findOne({
|
|
66383
66690
|
email: { $regex: `^${email}$`, $options: "i" },
|
|
66384
66691
|
status: "complete" /* COMPLETE */
|
|
66385
66692
|
});
|
|
66386
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66387
|
-
(err) =>
|
|
66693
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66694
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66388
66695
|
);
|
|
66389
66696
|
return data;
|
|
66390
66697
|
} catch (error) {
|
|
@@ -66397,7 +66704,7 @@ function useUserRepoV2() {
|
|
|
66397
66704
|
const cacheKey = makeCacheKey64(namespace_collection, { id });
|
|
66398
66705
|
const cachedData = await getCache(cacheKey);
|
|
66399
66706
|
if (cachedData) {
|
|
66400
|
-
|
|
66707
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66401
66708
|
return cachedData;
|
|
66402
66709
|
}
|
|
66403
66710
|
const results = await collection.aggregate([
|
|
@@ -66420,9 +66727,9 @@ function useUserRepoV2() {
|
|
|
66420
66727
|
]).toArray();
|
|
66421
66728
|
const data = results.length > 0 ? results[0] : null;
|
|
66422
66729
|
if (!data)
|
|
66423
|
-
throw new
|
|
66424
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66425
|
-
(err) =>
|
|
66730
|
+
throw new NotFoundError55("User not found.");
|
|
66731
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66732
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66426
66733
|
);
|
|
66427
66734
|
return data;
|
|
66428
66735
|
} catch (error) {
|
|
@@ -66436,12 +66743,12 @@ function useUserRepoV2() {
|
|
|
66436
66743
|
const cacheKey = makeCacheKey64(namespace_collection, { referralCode });
|
|
66437
66744
|
const cachedData = await getCache(cacheKey);
|
|
66438
66745
|
if (cachedData) {
|
|
66439
|
-
|
|
66746
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66440
66747
|
return cachedData;
|
|
66441
66748
|
}
|
|
66442
66749
|
const data = await collection.findOne({ referralCode });
|
|
66443
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66444
|
-
(err) =>
|
|
66750
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66751
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66445
66752
|
);
|
|
66446
66753
|
return data;
|
|
66447
66754
|
} catch (error) {
|
|
@@ -66453,15 +66760,15 @@ function useUserRepoV2() {
|
|
|
66453
66760
|
const cacheKey = makeCacheKey64(namespace_collection, { email, app });
|
|
66454
66761
|
const cachedData = await getCache(cacheKey);
|
|
66455
66762
|
if (cachedData) {
|
|
66456
|
-
|
|
66763
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66457
66764
|
return cachedData;
|
|
66458
66765
|
}
|
|
66459
66766
|
const data = await collection.findOne({
|
|
66460
66767
|
email,
|
|
66461
66768
|
"roles.app": app
|
|
66462
66769
|
});
|
|
66463
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66464
|
-
(err) =>
|
|
66770
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66771
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66465
66772
|
);
|
|
66466
66773
|
return data;
|
|
66467
66774
|
} catch (error) {
|
|
@@ -66499,9 +66806,9 @@ function useUserRepoV2() {
|
|
|
66499
66806
|
}
|
|
66500
66807
|
}
|
|
66501
66808
|
delNamespace().then(() => {
|
|
66502
|
-
|
|
66809
|
+
logger183.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
66503
66810
|
}).catch((err) => {
|
|
66504
|
-
|
|
66811
|
+
logger183.error(
|
|
66505
66812
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
66506
66813
|
err
|
|
66507
66814
|
);
|
|
@@ -66509,7 +66816,7 @@ function useUserRepoV2() {
|
|
|
66509
66816
|
const cacheKey = makeCacheKey64(namespace_collection, cacheOptions);
|
|
66510
66817
|
const cachedData = await getCache(cacheKey);
|
|
66511
66818
|
if (cachedData) {
|
|
66512
|
-
|
|
66819
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66513
66820
|
return cachedData;
|
|
66514
66821
|
}
|
|
66515
66822
|
try {
|
|
@@ -66529,15 +66836,15 @@ function useUserRepoV2() {
|
|
|
66529
66836
|
}
|
|
66530
66837
|
]).toArray();
|
|
66531
66838
|
const length = await collection.countDocuments(query);
|
|
66532
|
-
const data =
|
|
66839
|
+
const data = paginate61(items, page, limit, length);
|
|
66533
66840
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
66534
|
-
|
|
66841
|
+
logger183.info(`Cache set for key: ${cacheKey}`);
|
|
66535
66842
|
}).catch((err) => {
|
|
66536
|
-
|
|
66843
|
+
logger183.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
66537
66844
|
});
|
|
66538
66845
|
return data;
|
|
66539
66846
|
} catch (error) {
|
|
66540
|
-
|
|
66847
|
+
logger183.log({ level: "error", message: `${error}` });
|
|
66541
66848
|
throw error;
|
|
66542
66849
|
}
|
|
66543
66850
|
}
|
|
@@ -66563,9 +66870,9 @@ function useUserRepoV2() {
|
|
|
66563
66870
|
cacheOptions.type = type;
|
|
66564
66871
|
}
|
|
66565
66872
|
delNamespace().then(
|
|
66566
|
-
() =>
|
|
66873
|
+
() => logger183.info(`Cache cleared for namespace: ${namespace_collection}`)
|
|
66567
66874
|
).catch(
|
|
66568
|
-
(err) =>
|
|
66875
|
+
(err) => logger183.error(
|
|
66569
66876
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
66570
66877
|
err
|
|
66571
66878
|
)
|
|
@@ -66573,7 +66880,7 @@ function useUserRepoV2() {
|
|
|
66573
66880
|
const cacheKey = makeCacheKey64(namespace_collection, cacheOptions);
|
|
66574
66881
|
const cachedData = await getCache(cacheKey);
|
|
66575
66882
|
if (cachedData) {
|
|
66576
|
-
|
|
66883
|
+
logger183.info(`Cache hit for key: ${cacheKey}`);
|
|
66577
66884
|
return cachedData;
|
|
66578
66885
|
}
|
|
66579
66886
|
try {
|
|
@@ -66585,13 +66892,13 @@ function useUserRepoV2() {
|
|
|
66585
66892
|
{ $project: { _id: 1, name: 1, email: 1, type: 1, status: 1 } }
|
|
66586
66893
|
]).toArray();
|
|
66587
66894
|
const length = await collection.countDocuments(query);
|
|
66588
|
-
const data =
|
|
66589
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
66590
|
-
(err) =>
|
|
66895
|
+
const data = paginate61(items, page, limit, length);
|
|
66896
|
+
setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66897
|
+
(err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66591
66898
|
);
|
|
66592
66899
|
return data;
|
|
66593
66900
|
} catch (error) {
|
|
66594
|
-
|
|
66901
|
+
logger183.log({ level: "error", message: `${error}` });
|
|
66595
66902
|
throw error;
|
|
66596
66903
|
}
|
|
66597
66904
|
}
|
|
@@ -66605,9 +66912,9 @@ function useUserRepoV2() {
|
|
|
66605
66912
|
{ session }
|
|
66606
66913
|
);
|
|
66607
66914
|
delCache(cacheKey).then(() => {
|
|
66608
|
-
|
|
66915
|
+
logger183.info(`Cache deleted for key: ${cacheKey}`);
|
|
66609
66916
|
}).catch((err) => {
|
|
66610
|
-
|
|
66917
|
+
logger183.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
66611
66918
|
});
|
|
66612
66919
|
return result;
|
|
66613
66920
|
} catch (error) {
|
|
@@ -66662,9 +66969,9 @@ function useUserRepoV2() {
|
|
|
66662
66969
|
);
|
|
66663
66970
|
const cacheKey = makeCacheKey64(namespace_collection, { _id });
|
|
66664
66971
|
delCache(cacheKey).then(() => {
|
|
66665
|
-
|
|
66972
|
+
logger183.info(`Cache deleted for key: ${cacheKey}`);
|
|
66666
66973
|
}).catch((err) => {
|
|
66667
|
-
|
|
66974
|
+
logger183.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
66668
66975
|
});
|
|
66669
66976
|
return `Successfully updated user ${field}.`;
|
|
66670
66977
|
} catch (error) {
|
|
@@ -66697,9 +67004,9 @@ function useUserRepoV2() {
|
|
|
66697
67004
|
);
|
|
66698
67005
|
const cacheKey = makeCacheKey64(namespace_collection, { _id });
|
|
66699
67006
|
delCache(cacheKey).then(() => {
|
|
66700
|
-
|
|
67007
|
+
logger183.info(`Cache deleted for key: ${cacheKey}`);
|
|
66701
67008
|
}).catch((err) => {
|
|
66702
|
-
|
|
67009
|
+
logger183.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
66703
67010
|
});
|
|
66704
67011
|
return "Successfully updated user birthday.";
|
|
66705
67012
|
} catch (error) {
|
|
@@ -66720,9 +67027,9 @@ function useUserRepoV2() {
|
|
|
66720
67027
|
);
|
|
66721
67028
|
const cacheKey = makeCacheKey64(namespace_collection, { _id });
|
|
66722
67029
|
delCache(cacheKey).then(() => {
|
|
66723
|
-
|
|
67030
|
+
logger183.info(`Cache deleted for key: ${cacheKey}`);
|
|
66724
67031
|
}).catch((err) => {
|
|
66725
|
-
|
|
67032
|
+
logger183.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
66726
67033
|
});
|
|
66727
67034
|
return result;
|
|
66728
67035
|
} catch (error) {
|
|
@@ -66780,7 +67087,7 @@ function useAuthServiceV2() {
|
|
|
66780
67087
|
try {
|
|
66781
67088
|
const user = await getUserByEmail(email);
|
|
66782
67089
|
if (!user) {
|
|
66783
|
-
throw new
|
|
67090
|
+
throw new NotFoundError56(
|
|
66784
67091
|
"Invalid user email. Please check your email and try again."
|
|
66785
67092
|
);
|
|
66786
67093
|
}
|
|
@@ -66910,7 +67217,7 @@ import {
|
|
|
66910
67217
|
comparePassword as comparePassword4,
|
|
66911
67218
|
hashPassword as hashPassword5,
|
|
66912
67219
|
InternalServerError as InternalServerError73,
|
|
66913
|
-
NotFoundError as
|
|
67220
|
+
NotFoundError as NotFoundError57,
|
|
66914
67221
|
useAtlas as useAtlas119,
|
|
66915
67222
|
useS3 as useS33
|
|
66916
67223
|
} from "@7365admin1/node-server-utils";
|
|
@@ -67014,14 +67321,14 @@ function useUserServiceV2() {
|
|
|
67014
67321
|
try {
|
|
67015
67322
|
const otpDoc = await _getVerificationById(id);
|
|
67016
67323
|
if (!otpDoc) {
|
|
67017
|
-
throw new
|
|
67324
|
+
throw new NotFoundError57("You are using an invalid reset link.");
|
|
67018
67325
|
}
|
|
67019
67326
|
if (otpDoc.status === "complete" /* COMPLETE */) {
|
|
67020
67327
|
throw new BadRequestError206("This link has already been invalidated.");
|
|
67021
67328
|
}
|
|
67022
67329
|
const user = await _getUserByEmail(otpDoc.email);
|
|
67023
67330
|
if (!user) {
|
|
67024
|
-
throw new
|
|
67331
|
+
throw new NotFoundError57("User not found.");
|
|
67025
67332
|
}
|
|
67026
67333
|
if (!user._id) {
|
|
67027
67334
|
throw new InternalServerError73("Invalid user ID.");
|
|
@@ -67136,7 +67443,7 @@ function useAuthControllerV2() {
|
|
|
67136
67443
|
});
|
|
67137
67444
|
if (error) {
|
|
67138
67445
|
const messages = error.details.map((d) => d.message);
|
|
67139
|
-
|
|
67446
|
+
logger185.log({ level: "error", message: messages.join(", ") });
|
|
67140
67447
|
next(new BadRequestError207(messages.join(", ")));
|
|
67141
67448
|
return;
|
|
67142
67449
|
}
|
|
@@ -67153,7 +67460,7 @@ function useAuthControllerV2() {
|
|
|
67153
67460
|
return;
|
|
67154
67461
|
} catch (error) {
|
|
67155
67462
|
console.log(error);
|
|
67156
|
-
|
|
67463
|
+
logger185.log({ level: "error", message: error.message });
|
|
67157
67464
|
next(error);
|
|
67158
67465
|
return;
|
|
67159
67466
|
}
|
|
@@ -67171,7 +67478,7 @@ function useAuthControllerV2() {
|
|
|
67171
67478
|
});
|
|
67172
67479
|
if (error) {
|
|
67173
67480
|
const messages = error.details.map((d) => d.message);
|
|
67174
|
-
|
|
67481
|
+
logger185.log({ level: "error", message: messages.join(", ") });
|
|
67175
67482
|
next(new BadRequestError207(messages.join(", ")));
|
|
67176
67483
|
return;
|
|
67177
67484
|
}
|
|
@@ -67184,7 +67491,7 @@ function useAuthControllerV2() {
|
|
|
67184
67491
|
res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json(session);
|
|
67185
67492
|
return;
|
|
67186
67493
|
} catch (error) {
|
|
67187
|
-
|
|
67494
|
+
logger185.log({ level: "error", message: error.message });
|
|
67188
67495
|
next(error);
|
|
67189
67496
|
return;
|
|
67190
67497
|
}
|
|
@@ -67195,7 +67502,7 @@ function useAuthControllerV2() {
|
|
|
67195
67502
|
});
|
|
67196
67503
|
const { error, value } = validation.validate(req.body);
|
|
67197
67504
|
if (error) {
|
|
67198
|
-
|
|
67505
|
+
logger185.log({ level: "error", message: error.message });
|
|
67199
67506
|
next(new BadRequestError207(error.message));
|
|
67200
67507
|
return;
|
|
67201
67508
|
}
|
|
@@ -67204,7 +67511,7 @@ function useAuthControllerV2() {
|
|
|
67204
67511
|
res.json(session);
|
|
67205
67512
|
return;
|
|
67206
67513
|
} catch (error2) {
|
|
67207
|
-
|
|
67514
|
+
logger185.log({ level: "error", message: error2.message });
|
|
67208
67515
|
next(error2);
|
|
67209
67516
|
return;
|
|
67210
67517
|
}
|
|
@@ -67221,7 +67528,7 @@ function useAuthControllerV2() {
|
|
|
67221
67528
|
res.json({ message: "Logged out successfully" });
|
|
67222
67529
|
return;
|
|
67223
67530
|
} catch (error) {
|
|
67224
|
-
|
|
67531
|
+
logger185.log({ level: "error", message: error.message });
|
|
67225
67532
|
next(error);
|
|
67226
67533
|
return;
|
|
67227
67534
|
}
|
|
@@ -67237,7 +67544,7 @@ function useAuthControllerV2() {
|
|
|
67237
67544
|
});
|
|
67238
67545
|
if (error) {
|
|
67239
67546
|
const messages = error.details.map((d) => d.message);
|
|
67240
|
-
|
|
67547
|
+
logger185.log({ level: "error", message: messages.join(", ") });
|
|
67241
67548
|
next(new BadRequestError207(messages.join(", ")));
|
|
67242
67549
|
return;
|
|
67243
67550
|
}
|
|
@@ -67251,7 +67558,7 @@ function useAuthControllerV2() {
|
|
|
67251
67558
|
res.json({ message });
|
|
67252
67559
|
return;
|
|
67253
67560
|
} catch (error2) {
|
|
67254
|
-
|
|
67561
|
+
logger185.log({ level: "error", message: error2.message });
|
|
67255
67562
|
next(error2);
|
|
67256
67563
|
return;
|
|
67257
67564
|
}
|
|
@@ -67267,7 +67574,7 @@ function useAuthControllerV2() {
|
|
|
67267
67574
|
);
|
|
67268
67575
|
if (error) {
|
|
67269
67576
|
const messages = error.details.map((d) => d.message);
|
|
67270
|
-
|
|
67577
|
+
logger185.log({ level: "error", message: messages.join(", ") });
|
|
67271
67578
|
next(new BadRequestError207(messages.join(", ")));
|
|
67272
67579
|
return;
|
|
67273
67580
|
}
|
|
@@ -67277,7 +67584,7 @@ function useAuthControllerV2() {
|
|
|
67277
67584
|
res.json({ message });
|
|
67278
67585
|
return;
|
|
67279
67586
|
} catch (error2) {
|
|
67280
|
-
|
|
67587
|
+
logger185.log({ level: "error", message: error2.message });
|
|
67281
67588
|
next(error2);
|
|
67282
67589
|
return;
|
|
67283
67590
|
}
|
|
@@ -67295,7 +67602,7 @@ function useAuthControllerV2() {
|
|
|
67295
67602
|
// src/controllers/user-v2.controller.ts
|
|
67296
67603
|
import Joi131 from "joi";
|
|
67297
67604
|
import "multer";
|
|
67298
|
-
import { BadRequestError as BadRequestError208, logger as
|
|
67605
|
+
import { BadRequestError as BadRequestError208, logger as logger186 } from "@7365admin1/node-server-utils";
|
|
67299
67606
|
function useUserControllerV2() {
|
|
67300
67607
|
const {
|
|
67301
67608
|
updateBirthday: _updateBirthday,
|
|
@@ -67309,7 +67616,7 @@ function useUserControllerV2() {
|
|
|
67309
67616
|
const { createUserBySignUp, updateUserProfile: _updateUserProfile, updatePasswordById: _updatePasswordById } = useUserServiceV2();
|
|
67310
67617
|
function rejectValidation(error, next) {
|
|
67311
67618
|
const message = error.details.map((d) => d.message).join(", ");
|
|
67312
|
-
|
|
67619
|
+
logger186.log({ level: "error", message });
|
|
67313
67620
|
next(new BadRequestError208(message));
|
|
67314
67621
|
}
|
|
67315
67622
|
async function getById(req, res, next) {
|
|
@@ -67317,7 +67624,7 @@ function useUserControllerV2() {
|
|
|
67317
67624
|
const _id = req.params.id;
|
|
67318
67625
|
const { error, value } = validation.validate(_id);
|
|
67319
67626
|
if (error) {
|
|
67320
|
-
|
|
67627
|
+
logger186.log({ level: "error", message: `${error.message}` });
|
|
67321
67628
|
next(new BadRequestError208(error.message));
|
|
67322
67629
|
return;
|
|
67323
67630
|
}
|
|
@@ -67326,7 +67633,7 @@ function useUserControllerV2() {
|
|
|
67326
67633
|
res.json(user);
|
|
67327
67634
|
return;
|
|
67328
67635
|
} catch (error2) {
|
|
67329
|
-
|
|
67636
|
+
logger186.log({ level: "error", message: `${error2.message}` });
|
|
67330
67637
|
next(error2);
|
|
67331
67638
|
return;
|
|
67332
67639
|
}
|
|
@@ -67340,7 +67647,7 @@ function useUserControllerV2() {
|
|
|
67340
67647
|
res.json(user);
|
|
67341
67648
|
return;
|
|
67342
67649
|
} catch (err) {
|
|
67343
|
-
|
|
67650
|
+
logger186.log({ level: "error", message: `${err.message}` });
|
|
67344
67651
|
next(err);
|
|
67345
67652
|
return;
|
|
67346
67653
|
}
|
|
@@ -67407,7 +67714,7 @@ function useUserControllerV2() {
|
|
|
67407
67714
|
const payload = { ...req.body };
|
|
67408
67715
|
const { error, value } = validation.validate({ id, ...payload });
|
|
67409
67716
|
if (error) {
|
|
67410
|
-
|
|
67717
|
+
logger186.log({ level: "error", message: `${error.message}` });
|
|
67411
67718
|
next(new BadRequestError208(error.message));
|
|
67412
67719
|
return;
|
|
67413
67720
|
}
|
|
@@ -67416,7 +67723,7 @@ function useUserControllerV2() {
|
|
|
67416
67723
|
res.status(201).json({ message: "Successfully created account." });
|
|
67417
67724
|
return;
|
|
67418
67725
|
} catch (error2) {
|
|
67419
|
-
|
|
67726
|
+
logger186.log({ level: "error", message: `${error2.message}` });
|
|
67420
67727
|
next(error2);
|
|
67421
67728
|
return;
|
|
67422
67729
|
}
|
|
@@ -67432,7 +67739,7 @@ function useUserControllerV2() {
|
|
|
67432
67739
|
const payload = { ...req.body };
|
|
67433
67740
|
const { error, value } = validation.validate(payload);
|
|
67434
67741
|
if (error) {
|
|
67435
|
-
|
|
67742
|
+
logger186.log({ level: "error", message: `${error.message}` });
|
|
67436
67743
|
next(new BadRequestError208(error.message));
|
|
67437
67744
|
return;
|
|
67438
67745
|
}
|
|
@@ -67446,7 +67753,7 @@ function useUserControllerV2() {
|
|
|
67446
67753
|
res.json({ message: "Successfully updated profile picture." });
|
|
67447
67754
|
return;
|
|
67448
67755
|
} catch (error2) {
|
|
67449
|
-
|
|
67756
|
+
logger186.log({ level: "error", message: `${error2.message}` });
|
|
67450
67757
|
next(error2);
|
|
67451
67758
|
return;
|
|
67452
67759
|
}
|
|
@@ -67476,7 +67783,7 @@ function useUserControllerV2() {
|
|
|
67476
67783
|
const payload = { ...req.body };
|
|
67477
67784
|
const { error } = validation.validate({ _id, ...payload });
|
|
67478
67785
|
if (error) {
|
|
67479
|
-
|
|
67786
|
+
logger186.log({ level: "error", message: `${error.message}` });
|
|
67480
67787
|
next(new BadRequestError208(error.message));
|
|
67481
67788
|
return;
|
|
67482
67789
|
}
|
|
@@ -67485,7 +67792,7 @@ function useUserControllerV2() {
|
|
|
67485
67792
|
res.json({ message });
|
|
67486
67793
|
return;
|
|
67487
67794
|
} catch (error2) {
|
|
67488
|
-
|
|
67795
|
+
logger186.log({ level: "error", message: `${error2.message}` });
|
|
67489
67796
|
next(error2);
|
|
67490
67797
|
return;
|
|
67491
67798
|
}
|
|
@@ -67507,7 +67814,7 @@ function useUserControllerV2() {
|
|
|
67507
67814
|
const payload = { ...req.body };
|
|
67508
67815
|
const { error } = validation.validate({ _id, ...payload });
|
|
67509
67816
|
if (error) {
|
|
67510
|
-
|
|
67817
|
+
logger186.log({ level: "error", message: `${error.message}` });
|
|
67511
67818
|
next(new BadRequestError208(error.message));
|
|
67512
67819
|
return;
|
|
67513
67820
|
}
|
|
@@ -67516,7 +67823,7 @@ function useUserControllerV2() {
|
|
|
67516
67823
|
res.json({ message });
|
|
67517
67824
|
return;
|
|
67518
67825
|
} catch (error2) {
|
|
67519
|
-
|
|
67826
|
+
logger186.log({ level: "error", message: `${error2.message}` });
|
|
67520
67827
|
next(error2);
|
|
67521
67828
|
return;
|
|
67522
67829
|
}
|
|
@@ -67619,7 +67926,7 @@ import {
|
|
|
67619
67926
|
BadRequestError as BadRequestError210,
|
|
67620
67927
|
InternalServerError as InternalServerError74,
|
|
67621
67928
|
useAtlas as useAtlas120,
|
|
67622
|
-
logger as
|
|
67929
|
+
logger as logger187,
|
|
67623
67930
|
useCache as useCache69
|
|
67624
67931
|
} from "@7365admin1/node-server-utils";
|
|
67625
67932
|
function useRoleRepoV2() {
|
|
@@ -67663,16 +67970,16 @@ function useRoleRepoV2() {
|
|
|
67663
67970
|
try {
|
|
67664
67971
|
const res = await collection.insertOne(value, { session });
|
|
67665
67972
|
delNamespace().then(() => {
|
|
67666
|
-
|
|
67973
|
+
logger187.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
67667
67974
|
}).catch((err) => {
|
|
67668
|
-
|
|
67975
|
+
logger187.error(
|
|
67669
67976
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
67670
67977
|
err
|
|
67671
67978
|
);
|
|
67672
67979
|
});
|
|
67673
67980
|
return res.insertedId;
|
|
67674
67981
|
} catch (error) {
|
|
67675
|
-
|
|
67982
|
+
logger187.log({ level: "error", message: `${error}` });
|
|
67676
67983
|
const isDuplicated = error.message.includes("duplicate");
|
|
67677
67984
|
if (isDuplicated) {
|
|
67678
67985
|
throw new BadRequestError210("Role already exists.");
|
|
@@ -67703,7 +68010,7 @@ function useRoleServiceV2() {
|
|
|
67703
68010
|
|
|
67704
68011
|
// src/controllers/role-v2.controller.ts
|
|
67705
68012
|
import Joi132 from "joi";
|
|
67706
|
-
import { BadRequestError as BadRequestError211, logger as
|
|
68013
|
+
import { BadRequestError as BadRequestError211, logger as logger188 } from "@7365admin1/node-server-utils";
|
|
67707
68014
|
function useRoleControllerV2() {
|
|
67708
68015
|
const { createRole: _createRole } = useRoleServiceV2();
|
|
67709
68016
|
async function createRole(req, res, next) {
|
|
@@ -67719,7 +68026,7 @@ function useRoleControllerV2() {
|
|
|
67719
68026
|
const { error, value } = validation.validate(payload, { abortEarly: false });
|
|
67720
68027
|
if (error) {
|
|
67721
68028
|
const message = error.details.map((item) => item.message).join(", ");
|
|
67722
|
-
|
|
68029
|
+
logger188.log({ level: "error", message });
|
|
67723
68030
|
next(new BadRequestError211(message));
|
|
67724
68031
|
return;
|
|
67725
68032
|
}
|
|
@@ -67728,7 +68035,7 @@ function useRoleControllerV2() {
|
|
|
67728
68035
|
res.status(201).json({ message: "Successfully created role.", data: { role } });
|
|
67729
68036
|
return;
|
|
67730
68037
|
} catch (error2) {
|
|
67731
|
-
|
|
68038
|
+
logger188.log({ level: "error", message: error2.message });
|
|
67732
68039
|
next(error2);
|
|
67733
68040
|
return;
|
|
67734
68041
|
}
|
|
@@ -67871,8 +68178,8 @@ function MPost(value) {
|
|
|
67871
68178
|
import {
|
|
67872
68179
|
BadRequestError as BadRequestError212,
|
|
67873
68180
|
InternalServerError as InternalServerError75,
|
|
67874
|
-
NotFoundError as
|
|
67875
|
-
paginate as
|
|
68181
|
+
NotFoundError as NotFoundError58,
|
|
68182
|
+
paginate as paginate62,
|
|
67876
68183
|
useAtlas as useAtlas121
|
|
67877
68184
|
} from "@7365admin1/node-server-utils";
|
|
67878
68185
|
import { ObjectId as ObjectId140 } from "mongodb";
|
|
@@ -68094,7 +68401,7 @@ function usePostPrelovedRepo() {
|
|
|
68094
68401
|
]).toArray();
|
|
68095
68402
|
const data = result[0] ?? null;
|
|
68096
68403
|
if (!data)
|
|
68097
|
-
throw new
|
|
68404
|
+
throw new NotFoundError58("Post not found.");
|
|
68098
68405
|
return data;
|
|
68099
68406
|
} catch (error) {
|
|
68100
68407
|
throw error;
|
|
@@ -68222,7 +68529,7 @@ function usePostPrelovedRepo() {
|
|
|
68222
68529
|
{ session }
|
|
68223
68530
|
).toArray();
|
|
68224
68531
|
const length = await collection.countDocuments(query, { session });
|
|
68225
|
-
return
|
|
68532
|
+
return paginate62(items, page, limit, length);
|
|
68226
68533
|
} catch (error) {
|
|
68227
68534
|
throw error;
|
|
68228
68535
|
}
|
|
@@ -68290,7 +68597,7 @@ function usePostPrelovedRepo() {
|
|
|
68290
68597
|
{ session }
|
|
68291
68598
|
).toArray();
|
|
68292
68599
|
const length = await collection.countDocuments(query, { session });
|
|
68293
|
-
return
|
|
68600
|
+
return paginate62(items, page, limit, length);
|
|
68294
68601
|
} catch (error) {
|
|
68295
68602
|
throw error;
|
|
68296
68603
|
}
|
|
@@ -68374,7 +68681,7 @@ function usePostPrelovedRepo() {
|
|
|
68374
68681
|
}
|
|
68375
68682
|
|
|
68376
68683
|
// src/controllers/post-preloved.controller.ts
|
|
68377
|
-
import { BadRequestError as BadRequestError214, logger as
|
|
68684
|
+
import { BadRequestError as BadRequestError214, logger as logger189 } from "@7365admin1/node-server-utils";
|
|
68378
68685
|
import Joi136 from "joi";
|
|
68379
68686
|
|
|
68380
68687
|
// src/services/post-preloved.service.ts
|
|
@@ -68384,7 +68691,7 @@ import { useAtlas as useAtlas123 } from "@7365admin1/node-server-utils";
|
|
|
68384
68691
|
import {
|
|
68385
68692
|
BadRequestError as BadRequestError213,
|
|
68386
68693
|
InternalServerError as InternalServerError76,
|
|
68387
|
-
NotFoundError as
|
|
68694
|
+
NotFoundError as NotFoundError59,
|
|
68388
68695
|
useAtlas as useAtlas122
|
|
68389
68696
|
} from "@7365admin1/node-server-utils";
|
|
68390
68697
|
import { ObjectId as ObjectId142 } from "mongodb";
|
|
@@ -68480,7 +68787,7 @@ function usePostFavoriteRepo() {
|
|
|
68480
68787
|
}
|
|
68481
68788
|
const result = await collection.findOne({ _id });
|
|
68482
68789
|
if (!result)
|
|
68483
|
-
throw new
|
|
68790
|
+
throw new NotFoundError59("Favorite not found.");
|
|
68484
68791
|
return result;
|
|
68485
68792
|
}
|
|
68486
68793
|
async function getByPostId(postId) {
|
|
@@ -68491,7 +68798,7 @@ function usePostFavoriteRepo() {
|
|
|
68491
68798
|
}
|
|
68492
68799
|
const result = await collection.findOne({ postId });
|
|
68493
68800
|
if (!result)
|
|
68494
|
-
throw new
|
|
68801
|
+
throw new NotFoundError59("Favorite not found.");
|
|
68495
68802
|
return result;
|
|
68496
68803
|
}
|
|
68497
68804
|
async function updateById(_id, userId, session) {
|
|
@@ -68603,7 +68910,7 @@ function usePostPrelovedController() {
|
|
|
68603
68910
|
});
|
|
68604
68911
|
if (error) {
|
|
68605
68912
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68606
|
-
|
|
68913
|
+
logger189.log({ level: "error", message: messages });
|
|
68607
68914
|
next(new BadRequestError214(messages));
|
|
68608
68915
|
return;
|
|
68609
68916
|
}
|
|
@@ -68612,7 +68919,7 @@ function usePostPrelovedController() {
|
|
|
68612
68919
|
res.status(201).json(data);
|
|
68613
68920
|
return;
|
|
68614
68921
|
} catch (error2) {
|
|
68615
|
-
|
|
68922
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68616
68923
|
next(error2);
|
|
68617
68924
|
return;
|
|
68618
68925
|
}
|
|
@@ -68627,7 +68934,7 @@ function usePostPrelovedController() {
|
|
|
68627
68934
|
userId: req.query.userId
|
|
68628
68935
|
});
|
|
68629
68936
|
if (error) {
|
|
68630
|
-
|
|
68937
|
+
logger189.log({ level: "error", message: error.message });
|
|
68631
68938
|
next(new BadRequestError214(error.message));
|
|
68632
68939
|
return;
|
|
68633
68940
|
}
|
|
@@ -68636,7 +68943,7 @@ function usePostPrelovedController() {
|
|
|
68636
68943
|
res.status(200).json(data);
|
|
68637
68944
|
return;
|
|
68638
68945
|
} catch (error2) {
|
|
68639
|
-
|
|
68946
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68640
68947
|
next(error2);
|
|
68641
68948
|
return;
|
|
68642
68949
|
}
|
|
@@ -68661,7 +68968,7 @@ function usePostPrelovedController() {
|
|
|
68661
68968
|
});
|
|
68662
68969
|
if (error) {
|
|
68663
68970
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68664
|
-
|
|
68971
|
+
logger189.log({ level: "error", message: messages });
|
|
68665
68972
|
next(new BadRequestError214(messages));
|
|
68666
68973
|
return;
|
|
68667
68974
|
}
|
|
@@ -68691,7 +68998,7 @@ function usePostPrelovedController() {
|
|
|
68691
68998
|
res.status(200).json(data);
|
|
68692
68999
|
return;
|
|
68693
69000
|
} catch (error2) {
|
|
68694
|
-
|
|
69001
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68695
69002
|
next(error2);
|
|
68696
69003
|
return;
|
|
68697
69004
|
}
|
|
@@ -68716,7 +69023,7 @@ function usePostPrelovedController() {
|
|
|
68716
69023
|
);
|
|
68717
69024
|
if (error) {
|
|
68718
69025
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68719
|
-
|
|
69026
|
+
logger189.log({ level: "error", message: messages });
|
|
68720
69027
|
next(new BadRequestError214(messages));
|
|
68721
69028
|
return;
|
|
68722
69029
|
}
|
|
@@ -68734,7 +69041,7 @@ function usePostPrelovedController() {
|
|
|
68734
69041
|
res.status(200).json(data);
|
|
68735
69042
|
return;
|
|
68736
69043
|
} catch (error2) {
|
|
68737
|
-
|
|
69044
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68738
69045
|
next(error2);
|
|
68739
69046
|
return;
|
|
68740
69047
|
}
|
|
@@ -68747,7 +69054,7 @@ function usePostPrelovedController() {
|
|
|
68747
69054
|
});
|
|
68748
69055
|
if (error) {
|
|
68749
69056
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68750
|
-
|
|
69057
|
+
logger189.log({ level: "error", message: messages });
|
|
68751
69058
|
next(new BadRequestError214(messages));
|
|
68752
69059
|
return;
|
|
68753
69060
|
}
|
|
@@ -68756,7 +69063,7 @@ function usePostPrelovedController() {
|
|
|
68756
69063
|
res.status(200).json(data);
|
|
68757
69064
|
return;
|
|
68758
69065
|
} catch (error2) {
|
|
68759
|
-
|
|
69066
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68760
69067
|
next(error2);
|
|
68761
69068
|
return;
|
|
68762
69069
|
}
|
|
@@ -68767,7 +69074,7 @@ function usePostPrelovedController() {
|
|
|
68767
69074
|
});
|
|
68768
69075
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
68769
69076
|
if (error) {
|
|
68770
|
-
|
|
69077
|
+
logger189.log({ level: "error", message: error.message });
|
|
68771
69078
|
next(new BadRequestError214(error.message));
|
|
68772
69079
|
return;
|
|
68773
69080
|
}
|
|
@@ -68776,7 +69083,7 @@ function usePostPrelovedController() {
|
|
|
68776
69083
|
res.status(200).json({ message: "Successfully deleted post." });
|
|
68777
69084
|
return;
|
|
68778
69085
|
} catch (error2) {
|
|
68779
|
-
|
|
69086
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68780
69087
|
next(error2);
|
|
68781
69088
|
return;
|
|
68782
69089
|
}
|
|
@@ -68791,7 +69098,7 @@ function usePostPrelovedController() {
|
|
|
68791
69098
|
status: req.body.status
|
|
68792
69099
|
});
|
|
68793
69100
|
if (error) {
|
|
68794
|
-
|
|
69101
|
+
logger189.log({ level: "error", message: error.message });
|
|
68795
69102
|
next(new BadRequestError214(error.message));
|
|
68796
69103
|
return;
|
|
68797
69104
|
}
|
|
@@ -68800,7 +69107,7 @@ function usePostPrelovedController() {
|
|
|
68800
69107
|
res.status(200).json(data);
|
|
68801
69108
|
return;
|
|
68802
69109
|
} catch (error2) {
|
|
68803
|
-
|
|
69110
|
+
logger189.log({ level: "error", message: error2.message });
|
|
68804
69111
|
next(error2);
|
|
68805
69112
|
return;
|
|
68806
69113
|
}
|
|
@@ -68855,7 +69162,7 @@ function usePostFavoriteService2() {
|
|
|
68855
69162
|
}
|
|
68856
69163
|
|
|
68857
69164
|
// src/controllers/post-favorite.controller.ts
|
|
68858
|
-
import { BadRequestError as BadRequestError215, logger as
|
|
69165
|
+
import { BadRequestError as BadRequestError215, logger as logger190 } from "@7365admin1/node-server-utils";
|
|
68859
69166
|
import Joi137 from "joi";
|
|
68860
69167
|
function usePostFavoriteController() {
|
|
68861
69168
|
const { addFavorite: _addFavorite, toggleFavorite: _toggleFavorite } = usePostFavoriteService2();
|
|
@@ -68866,7 +69173,7 @@ function usePostFavoriteController() {
|
|
|
68866
69173
|
});
|
|
68867
69174
|
if (error) {
|
|
68868
69175
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68869
|
-
|
|
69176
|
+
logger190.log({ level: "error", message: messages });
|
|
68870
69177
|
next(new BadRequestError215(messages));
|
|
68871
69178
|
return;
|
|
68872
69179
|
}
|
|
@@ -68875,7 +69182,7 @@ function usePostFavoriteController() {
|
|
|
68875
69182
|
res.status(201).json(data);
|
|
68876
69183
|
return;
|
|
68877
69184
|
} catch (error2) {
|
|
68878
|
-
|
|
69185
|
+
logger190.log({ level: "error", message: error2.message });
|
|
68879
69186
|
next(error2);
|
|
68880
69187
|
return;
|
|
68881
69188
|
}
|
|
@@ -68886,7 +69193,7 @@ function usePostFavoriteController() {
|
|
|
68886
69193
|
});
|
|
68887
69194
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
68888
69195
|
if (error) {
|
|
68889
|
-
|
|
69196
|
+
logger190.log({ level: "error", message: error.message });
|
|
68890
69197
|
next(new BadRequestError215(error.message));
|
|
68891
69198
|
return;
|
|
68892
69199
|
}
|
|
@@ -68895,7 +69202,7 @@ function usePostFavoriteController() {
|
|
|
68895
69202
|
res.status(200).json(data);
|
|
68896
69203
|
return;
|
|
68897
69204
|
} catch (error2) {
|
|
68898
|
-
|
|
69205
|
+
logger190.log({ level: "error", message: error2.message });
|
|
68899
69206
|
next(error2);
|
|
68900
69207
|
return;
|
|
68901
69208
|
}
|
|
@@ -68906,7 +69213,7 @@ function usePostFavoriteController() {
|
|
|
68906
69213
|
});
|
|
68907
69214
|
const { error, value } = schema2.validate({ postId: req.params.postId });
|
|
68908
69215
|
if (error) {
|
|
68909
|
-
|
|
69216
|
+
logger190.log({ level: "error", message: error.message });
|
|
68910
69217
|
next(new BadRequestError215(error.message));
|
|
68911
69218
|
return;
|
|
68912
69219
|
}
|
|
@@ -68915,7 +69222,7 @@ function usePostFavoriteController() {
|
|
|
68915
69222
|
res.status(200).json(data);
|
|
68916
69223
|
return;
|
|
68917
69224
|
} catch (error2) {
|
|
68918
|
-
|
|
69225
|
+
logger190.log({ level: "error", message: error2.message });
|
|
68919
69226
|
next(error2);
|
|
68920
69227
|
return;
|
|
68921
69228
|
}
|
|
@@ -68934,7 +69241,7 @@ function usePostFavoriteController() {
|
|
|
68934
69241
|
const { error: bodyError, value: bodyValue } = schemaUpdatePostFavorite.validate(req.body, { abortEarly: false });
|
|
68935
69242
|
if (bodyError) {
|
|
68936
69243
|
const messages = bodyError.details.map((d) => d.message).join(", ");
|
|
68937
|
-
|
|
69244
|
+
logger190.log({ level: "error", message: messages });
|
|
68938
69245
|
next(new BadRequestError215(messages));
|
|
68939
69246
|
return;
|
|
68940
69247
|
}
|
|
@@ -68942,7 +69249,7 @@ function usePostFavoriteController() {
|
|
|
68942
69249
|
const data = await _toggleFavorite(paramsValue._id, bodyValue.userId);
|
|
68943
69250
|
res.status(200).json(data);
|
|
68944
69251
|
} catch (error) {
|
|
68945
|
-
|
|
69252
|
+
logger190.log({ level: "error", message: error.message });
|
|
68946
69253
|
next(error);
|
|
68947
69254
|
}
|
|
68948
69255
|
}
|
|
@@ -68998,7 +69305,7 @@ function MCategoryPreloved(value) {
|
|
|
68998
69305
|
import {
|
|
68999
69306
|
BadRequestError as BadRequestError216,
|
|
69000
69307
|
InternalServerError as InternalServerError77,
|
|
69001
|
-
NotFoundError as
|
|
69308
|
+
NotFoundError as NotFoundError60,
|
|
69002
69309
|
useAtlas as useAtlas125
|
|
69003
69310
|
} from "@7365admin1/node-server-utils";
|
|
69004
69311
|
import { ObjectId as ObjectId145 } from "mongodb";
|
|
@@ -69041,7 +69348,7 @@ function useCategoryPrelovedRepo() {
|
|
|
69041
69348
|
try {
|
|
69042
69349
|
const data = await collection.findOne({ _id: objectId2 });
|
|
69043
69350
|
if (!data) {
|
|
69044
|
-
throw new
|
|
69351
|
+
throw new NotFoundError60("Category not found.");
|
|
69045
69352
|
}
|
|
69046
69353
|
return data;
|
|
69047
69354
|
} catch (error) {
|
|
@@ -69070,7 +69377,7 @@ function useCategoryPrelovedRepo() {
|
|
|
69070
69377
|
}
|
|
69071
69378
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
69072
69379
|
if (!existing)
|
|
69073
|
-
throw new
|
|
69380
|
+
throw new NotFoundError60("Category not found.");
|
|
69074
69381
|
const res = await collection.updateOne(
|
|
69075
69382
|
{ _id: objectId2 },
|
|
69076
69383
|
{ $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
@@ -69088,7 +69395,7 @@ function useCategoryPrelovedRepo() {
|
|
|
69088
69395
|
}
|
|
69089
69396
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
69090
69397
|
if (!existing)
|
|
69091
|
-
throw new
|
|
69398
|
+
throw new NotFoundError60("Category not found.");
|
|
69092
69399
|
const res = await collection.deleteOne({ _id: objectId2 });
|
|
69093
69400
|
if (res.deletedCount === 0)
|
|
69094
69401
|
throw new InternalServerError77("Unable to delete category.");
|
|
@@ -69098,7 +69405,7 @@ function useCategoryPrelovedRepo() {
|
|
|
69098
69405
|
}
|
|
69099
69406
|
|
|
69100
69407
|
// src/controllers/category-preloved.controller.ts
|
|
69101
|
-
import { BadRequestError as BadRequestError217, logger as
|
|
69408
|
+
import { BadRequestError as BadRequestError217, logger as logger191 } from "@7365admin1/node-server-utils";
|
|
69102
69409
|
import Joi139 from "joi";
|
|
69103
69410
|
function useCategoryPrelovedController() {
|
|
69104
69411
|
const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById, deleteById: _deleteById } = useCategoryPrelovedRepo();
|
|
@@ -69110,7 +69417,7 @@ function useCategoryPrelovedController() {
|
|
|
69110
69417
|
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
69111
69418
|
if (error) {
|
|
69112
69419
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
69113
|
-
|
|
69420
|
+
logger191.log({ level: "error", message: messages });
|
|
69114
69421
|
next(new BadRequestError217(messages));
|
|
69115
69422
|
return;
|
|
69116
69423
|
}
|
|
@@ -69119,7 +69426,7 @@ function useCategoryPrelovedController() {
|
|
|
69119
69426
|
res.status(200).json({ data });
|
|
69120
69427
|
return;
|
|
69121
69428
|
} catch (error2) {
|
|
69122
|
-
|
|
69429
|
+
logger191.log({ level: "error", message: error2.message });
|
|
69123
69430
|
next(error2);
|
|
69124
69431
|
return;
|
|
69125
69432
|
}
|
|
@@ -69130,7 +69437,7 @@ function useCategoryPrelovedController() {
|
|
|
69130
69437
|
});
|
|
69131
69438
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
69132
69439
|
if (error) {
|
|
69133
|
-
|
|
69440
|
+
logger191.log({ level: "error", message: error.message });
|
|
69134
69441
|
next(new BadRequestError217(error.message));
|
|
69135
69442
|
return;
|
|
69136
69443
|
}
|
|
@@ -69139,7 +69446,7 @@ function useCategoryPrelovedController() {
|
|
|
69139
69446
|
res.status(200).json({ data });
|
|
69140
69447
|
return;
|
|
69141
69448
|
} catch (error2) {
|
|
69142
|
-
|
|
69449
|
+
logger191.log({ level: "error", message: error2.message });
|
|
69143
69450
|
next(error2);
|
|
69144
69451
|
return;
|
|
69145
69452
|
}
|
|
@@ -69150,7 +69457,7 @@ function useCategoryPrelovedController() {
|
|
|
69150
69457
|
});
|
|
69151
69458
|
if (error) {
|
|
69152
69459
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
69153
|
-
|
|
69460
|
+
logger191.log({ level: "error", message: messages });
|
|
69154
69461
|
next(new BadRequestError217(messages));
|
|
69155
69462
|
return;
|
|
69156
69463
|
}
|
|
@@ -69158,7 +69465,7 @@ function useCategoryPrelovedController() {
|
|
|
69158
69465
|
const data = await _addCategory(value);
|
|
69159
69466
|
res.status(201).json(data);
|
|
69160
69467
|
} catch (error2) {
|
|
69161
|
-
|
|
69468
|
+
logger191.log({ level: "error", message: error2.message });
|
|
69162
69469
|
next(error2);
|
|
69163
69470
|
}
|
|
69164
69471
|
}
|
|
@@ -69168,7 +69475,7 @@ function useCategoryPrelovedController() {
|
|
|
69168
69475
|
});
|
|
69169
69476
|
if (error) {
|
|
69170
69477
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
69171
|
-
|
|
69478
|
+
logger191.log({ level: "error", message: messages });
|
|
69172
69479
|
next(new BadRequestError217(messages));
|
|
69173
69480
|
return;
|
|
69174
69481
|
}
|
|
@@ -69176,7 +69483,7 @@ function useCategoryPrelovedController() {
|
|
|
69176
69483
|
const data = await _updateById(req.params.id, value);
|
|
69177
69484
|
res.status(200).json(data);
|
|
69178
69485
|
} catch (error2) {
|
|
69179
|
-
|
|
69486
|
+
logger191.log({ level: "error", message: error2.message });
|
|
69180
69487
|
next(error2);
|
|
69181
69488
|
}
|
|
69182
69489
|
}
|
|
@@ -69186,7 +69493,7 @@ function useCategoryPrelovedController() {
|
|
|
69186
69493
|
});
|
|
69187
69494
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
69188
69495
|
if (error) {
|
|
69189
|
-
|
|
69496
|
+
logger191.log({ level: "error", message: error.message });
|
|
69190
69497
|
next(new BadRequestError217(error.message));
|
|
69191
69498
|
return;
|
|
69192
69499
|
}
|
|
@@ -69194,7 +69501,7 @@ function useCategoryPrelovedController() {
|
|
|
69194
69501
|
const data = await _deleteById(value._id);
|
|
69195
69502
|
res.status(200).json(data);
|
|
69196
69503
|
} catch (error2) {
|
|
69197
|
-
|
|
69504
|
+
logger191.log({ level: "error", message: error2.message });
|
|
69198
69505
|
next(error2);
|
|
69199
69506
|
}
|
|
69200
69507
|
}
|
|
@@ -69255,7 +69562,7 @@ function MSubcategoryPreloved(value) {
|
|
|
69255
69562
|
import {
|
|
69256
69563
|
BadRequestError as BadRequestError218,
|
|
69257
69564
|
InternalServerError as InternalServerError78,
|
|
69258
|
-
NotFoundError as
|
|
69565
|
+
NotFoundError as NotFoundError61,
|
|
69259
69566
|
useAtlas as useAtlas126
|
|
69260
69567
|
} from "@7365admin1/node-server-utils";
|
|
69261
69568
|
import { ObjectId as ObjectId147 } from "mongodb";
|
|
@@ -69306,7 +69613,7 @@ function useSubcategoryPrelovedRepo() {
|
|
|
69306
69613
|
try {
|
|
69307
69614
|
const data = await collection.findOne({ _id: objectId2 });
|
|
69308
69615
|
if (!data) {
|
|
69309
|
-
throw new
|
|
69616
|
+
throw new NotFoundError61("Subcategory not found.");
|
|
69310
69617
|
}
|
|
69311
69618
|
return data;
|
|
69312
69619
|
} catch (error) {
|
|
@@ -69372,7 +69679,7 @@ function useSubcategoryPrelovedRepo() {
|
|
|
69372
69679
|
}
|
|
69373
69680
|
|
|
69374
69681
|
// src/controllers/subcategory-preloved.controller.ts
|
|
69375
|
-
import { BadRequestError as BadRequestError219, logger as
|
|
69682
|
+
import { BadRequestError as BadRequestError219, logger as logger192 } from "@7365admin1/node-server-utils";
|
|
69376
69683
|
import Joi141 from "joi";
|
|
69377
69684
|
function useSubcategoryPrelovedController() {
|
|
69378
69685
|
const {
|
|
@@ -69391,7 +69698,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69391
69698
|
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
69392
69699
|
if (error) {
|
|
69393
69700
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
69394
|
-
|
|
69701
|
+
logger192.log({ level: "error", message: messages });
|
|
69395
69702
|
next(new BadRequestError219(messages));
|
|
69396
69703
|
return;
|
|
69397
69704
|
}
|
|
@@ -69400,7 +69707,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69400
69707
|
res.status(200).json({ data });
|
|
69401
69708
|
return;
|
|
69402
69709
|
} catch (error2) {
|
|
69403
|
-
|
|
69710
|
+
logger192.log({ level: "error", message: error2.message });
|
|
69404
69711
|
next(error2);
|
|
69405
69712
|
return;
|
|
69406
69713
|
}
|
|
@@ -69411,7 +69718,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69411
69718
|
});
|
|
69412
69719
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
69413
69720
|
if (error) {
|
|
69414
|
-
|
|
69721
|
+
logger192.log({ level: "error", message: error.message });
|
|
69415
69722
|
next(new BadRequestError219(error.message));
|
|
69416
69723
|
return;
|
|
69417
69724
|
}
|
|
@@ -69420,7 +69727,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69420
69727
|
res.status(200).json({ data });
|
|
69421
69728
|
return;
|
|
69422
69729
|
} catch (error2) {
|
|
69423
|
-
|
|
69730
|
+
logger192.log({ level: "error", message: error2.message });
|
|
69424
69731
|
next(error2);
|
|
69425
69732
|
return;
|
|
69426
69733
|
}
|
|
@@ -69431,7 +69738,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69431
69738
|
});
|
|
69432
69739
|
if (error) {
|
|
69433
69740
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
69434
|
-
|
|
69741
|
+
logger192.log({ level: "error", message: messages });
|
|
69435
69742
|
next(new BadRequestError219(messages));
|
|
69436
69743
|
return;
|
|
69437
69744
|
}
|
|
@@ -69439,7 +69746,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69439
69746
|
const data = await _addSubcategory(value);
|
|
69440
69747
|
res.status(201).json(data);
|
|
69441
69748
|
} catch (error2) {
|
|
69442
|
-
|
|
69749
|
+
logger192.log({ level: "error", message: error2.message });
|
|
69443
69750
|
next(error2);
|
|
69444
69751
|
}
|
|
69445
69752
|
}
|
|
@@ -69457,7 +69764,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69457
69764
|
const { error: bodyError, value: bodyValue } = schemaUpdateSubcategoryPreloved.validate(req.body, { abortEarly: false });
|
|
69458
69765
|
if (bodyError) {
|
|
69459
69766
|
const messages = bodyError.details.map((d) => d.message).join(", ");
|
|
69460
|
-
|
|
69767
|
+
logger192.log({ level: "error", message: messages });
|
|
69461
69768
|
next(new BadRequestError219(messages));
|
|
69462
69769
|
return;
|
|
69463
69770
|
}
|
|
@@ -69465,7 +69772,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69465
69772
|
const data = await _updateById(paramsValue._id, bodyValue);
|
|
69466
69773
|
res.status(200).json(data);
|
|
69467
69774
|
} catch (error) {
|
|
69468
|
-
|
|
69775
|
+
logger192.log({ level: "error", message: error.message });
|
|
69469
69776
|
next(error);
|
|
69470
69777
|
}
|
|
69471
69778
|
}
|
|
@@ -69482,7 +69789,7 @@ function useSubcategoryPrelovedController() {
|
|
|
69482
69789
|
const data = await _deleteById(value._id);
|
|
69483
69790
|
res.status(200).json(data);
|
|
69484
69791
|
} catch (error2) {
|
|
69485
|
-
|
|
69792
|
+
logger192.log({ level: "error", message: error2.message });
|
|
69486
69793
|
next(error2);
|
|
69487
69794
|
}
|
|
69488
69795
|
}
|
|
@@ -69581,7 +69888,7 @@ function MChatPreloved(value) {
|
|
|
69581
69888
|
import {
|
|
69582
69889
|
BadRequestError as BadRequestError220,
|
|
69583
69890
|
InternalServerError as InternalServerError79,
|
|
69584
|
-
NotFoundError as
|
|
69891
|
+
NotFoundError as NotFoundError62,
|
|
69585
69892
|
useAtlas as useAtlas127
|
|
69586
69893
|
} from "@7365admin1/node-server-utils";
|
|
69587
69894
|
import { ObjectId as ObjectId149 } from "mongodb";
|
|
@@ -69621,7 +69928,7 @@ function useChatPrelovedRepo() {
|
|
|
69621
69928
|
}
|
|
69622
69929
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
69623
69930
|
if (!existing)
|
|
69624
|
-
throw new
|
|
69931
|
+
throw new NotFoundError62("Chat not found.");
|
|
69625
69932
|
value.edited = true;
|
|
69626
69933
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
69627
69934
|
const res = await collection.updateOne({ _id: objectId2 }, { $set: value });
|
|
@@ -69638,7 +69945,7 @@ function useChatPrelovedRepo() {
|
|
|
69638
69945
|
}
|
|
69639
69946
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
69640
69947
|
if (!existing)
|
|
69641
|
-
throw new
|
|
69948
|
+
throw new NotFoundError62("Chat not found.");
|
|
69642
69949
|
const res = await collection.updateOne(
|
|
69643
69950
|
{ _id: objectId2 },
|
|
69644
69951
|
{ $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
@@ -69656,7 +69963,7 @@ import { BadRequestError as BadRequestError221, InternalServerError as InternalS
|
|
|
69656
69963
|
// src/repositories/channel-preloved.repo.ts
|
|
69657
69964
|
import {
|
|
69658
69965
|
InternalServerError as InternalServerError80,
|
|
69659
|
-
paginate as
|
|
69966
|
+
paginate as paginate64,
|
|
69660
69967
|
useAtlas as useAtlas128
|
|
69661
69968
|
} from "@7365admin1/node-server-utils";
|
|
69662
69969
|
import { ObjectId as ObjectId151 } from "mongodb";
|
|
@@ -69815,7 +70122,7 @@ function useChannelPrelovedRepo() {
|
|
|
69815
70122
|
const totalCount = result[0].totalCount[0]?.count ?? 0;
|
|
69816
70123
|
const items = result[0].items;
|
|
69817
70124
|
items.reverse();
|
|
69818
|
-
return
|
|
70125
|
+
return paginate64(items, normalizedPage, normalizedLimit, totalCount);
|
|
69819
70126
|
} catch (error) {
|
|
69820
70127
|
throw error;
|
|
69821
70128
|
}
|
|
@@ -69938,7 +70245,7 @@ function useChannelPrelovedRepo() {
|
|
|
69938
70245
|
const result = await collection.aggregate(pipeline).toArray();
|
|
69939
70246
|
const totalCount = result[0].totalCount[0]?.count ?? 0;
|
|
69940
70247
|
const items = result[0].items;
|
|
69941
|
-
return
|
|
70248
|
+
return paginate64(items, normalizedPage, normalizedLimit, totalCount);
|
|
69942
70249
|
} catch (error) {
|
|
69943
70250
|
throw error;
|
|
69944
70251
|
}
|
|
@@ -70003,7 +70310,7 @@ function useChatPrelovedService() {
|
|
|
70003
70310
|
}
|
|
70004
70311
|
|
|
70005
70312
|
// src/controllers/chat-preloved.controller.ts
|
|
70006
|
-
import { BadRequestError as BadRequestError222, logger as
|
|
70313
|
+
import { BadRequestError as BadRequestError222, logger as logger193 } from "@7365admin1/node-server-utils";
|
|
70007
70314
|
import Joi144 from "joi";
|
|
70008
70315
|
function useChatPrelovedController() {
|
|
70009
70316
|
const { add: _add } = useChatPrelovedService();
|
|
@@ -70014,7 +70321,7 @@ function useChatPrelovedController() {
|
|
|
70014
70321
|
});
|
|
70015
70322
|
if (error) {
|
|
70016
70323
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70017
|
-
|
|
70324
|
+
logger193.log({ level: "error", message: messages });
|
|
70018
70325
|
next(new BadRequestError222(messages));
|
|
70019
70326
|
return;
|
|
70020
70327
|
}
|
|
@@ -70022,7 +70329,7 @@ function useChatPrelovedController() {
|
|
|
70022
70329
|
const data = await _add(value);
|
|
70023
70330
|
res.status(201).json(data);
|
|
70024
70331
|
} catch (error2) {
|
|
70025
|
-
|
|
70332
|
+
logger193.log({ level: "error", message: error2.message });
|
|
70026
70333
|
next(error2);
|
|
70027
70334
|
}
|
|
70028
70335
|
}
|
|
@@ -70032,7 +70339,7 @@ function useChatPrelovedController() {
|
|
|
70032
70339
|
});
|
|
70033
70340
|
if (error) {
|
|
70034
70341
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70035
|
-
|
|
70342
|
+
logger193.log({ level: "error", message: messages });
|
|
70036
70343
|
next(new BadRequestError222(messages));
|
|
70037
70344
|
return;
|
|
70038
70345
|
}
|
|
@@ -70040,7 +70347,7 @@ function useChatPrelovedController() {
|
|
|
70040
70347
|
const data = await _updateById(req.params.id, value);
|
|
70041
70348
|
res.status(200).json(data);
|
|
70042
70349
|
} catch (error2) {
|
|
70043
|
-
|
|
70350
|
+
logger193.log({ level: "error", message: error2.message });
|
|
70044
70351
|
next(error2);
|
|
70045
70352
|
}
|
|
70046
70353
|
}
|
|
@@ -70050,7 +70357,7 @@ function useChatPrelovedController() {
|
|
|
70050
70357
|
});
|
|
70051
70358
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
70052
70359
|
if (error) {
|
|
70053
|
-
|
|
70360
|
+
logger193.log({ level: "error", message: error.message });
|
|
70054
70361
|
next(new BadRequestError222(error.message));
|
|
70055
70362
|
return;
|
|
70056
70363
|
}
|
|
@@ -70058,7 +70365,7 @@ function useChatPrelovedController() {
|
|
|
70058
70365
|
const data = await _deleteById(value._id);
|
|
70059
70366
|
res.status(200).json(data);
|
|
70060
70367
|
} catch (error2) {
|
|
70061
|
-
|
|
70368
|
+
logger193.log({ level: "error", message: error2.message });
|
|
70062
70369
|
next(error2);
|
|
70063
70370
|
}
|
|
70064
70371
|
}
|
|
@@ -70067,7 +70374,7 @@ function useChatPrelovedController() {
|
|
|
70067
70374
|
|
|
70068
70375
|
// src/events/chat-preloved.event.ts
|
|
70069
70376
|
import Joi145 from "joi";
|
|
70070
|
-
import { logger as
|
|
70377
|
+
import { logger as logger194, useCache as useCache70 } from "@7365admin1/node-server-utils";
|
|
70071
70378
|
function parseSid(cookieHeader) {
|
|
70072
70379
|
const match = cookieHeader.match(/(?:^|;\s*)sid=([^;]*)/);
|
|
70073
70380
|
return match ? decodeURIComponent(match[1]) : null;
|
|
@@ -70120,7 +70427,7 @@ function chatPrelovedEvents(io) {
|
|
|
70120
70427
|
socket.data.userId = (session._id ?? sessionData).toString();
|
|
70121
70428
|
next();
|
|
70122
70429
|
} catch (error) {
|
|
70123
|
-
|
|
70430
|
+
logger194.log({ level: "error", message: `Socket auth error: ${error.message}` });
|
|
70124
70431
|
next(new Error("Authentication error"));
|
|
70125
70432
|
}
|
|
70126
70433
|
});
|
|
@@ -70169,7 +70476,7 @@ function chatPrelovedEvents(io) {
|
|
|
70169
70476
|
}
|
|
70170
70477
|
|
|
70171
70478
|
// src/controllers/channel-preloved.controller.ts
|
|
70172
|
-
import { BadRequestError as BadRequestError223, logger as
|
|
70479
|
+
import { BadRequestError as BadRequestError223, logger as logger195 } from "@7365admin1/node-server-utils";
|
|
70173
70480
|
import Joi146 from "joi";
|
|
70174
70481
|
function useChannelPrelovedController() {
|
|
70175
70482
|
const {
|
|
@@ -70184,7 +70491,7 @@ function useChannelPrelovedController() {
|
|
|
70184
70491
|
});
|
|
70185
70492
|
if (error) {
|
|
70186
70493
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70187
|
-
|
|
70494
|
+
logger195.log({ level: "error", message: messages });
|
|
70188
70495
|
next(new BadRequestError223(messages));
|
|
70189
70496
|
return;
|
|
70190
70497
|
}
|
|
@@ -70192,7 +70499,7 @@ function useChannelPrelovedController() {
|
|
|
70192
70499
|
const data = await _add(value);
|
|
70193
70500
|
res.status(201).json(data);
|
|
70194
70501
|
} catch (error2) {
|
|
70195
|
-
|
|
70502
|
+
logger195.log({ level: "error", message: error2.message });
|
|
70196
70503
|
next(error2);
|
|
70197
70504
|
}
|
|
70198
70505
|
}
|
|
@@ -70210,13 +70517,13 @@ function useChannelPrelovedController() {
|
|
|
70210
70517
|
req.params
|
|
70211
70518
|
);
|
|
70212
70519
|
if (paramError) {
|
|
70213
|
-
|
|
70520
|
+
logger195.log({ level: "error", message: paramError.message });
|
|
70214
70521
|
next(new BadRequestError223(paramError.message));
|
|
70215
70522
|
return;
|
|
70216
70523
|
}
|
|
70217
70524
|
const { error: queryError, value: query } = querySchema.validate(req.query);
|
|
70218
70525
|
if (queryError) {
|
|
70219
|
-
|
|
70526
|
+
logger195.log({ level: "error", message: queryError.message });
|
|
70220
70527
|
next(new BadRequestError223(queryError.message));
|
|
70221
70528
|
return;
|
|
70222
70529
|
}
|
|
@@ -70230,7 +70537,7 @@ function useChannelPrelovedController() {
|
|
|
70230
70537
|
);
|
|
70231
70538
|
res.status(200).json(data);
|
|
70232
70539
|
} catch (error) {
|
|
70233
|
-
|
|
70540
|
+
logger195.log({ level: "error", message: error.message });
|
|
70234
70541
|
next(error);
|
|
70235
70542
|
}
|
|
70236
70543
|
}
|
|
@@ -70242,7 +70549,7 @@ function useChannelPrelovedController() {
|
|
|
70242
70549
|
});
|
|
70243
70550
|
const { error, value } = querySchema.validate(req.query);
|
|
70244
70551
|
if (error) {
|
|
70245
|
-
|
|
70552
|
+
logger195.log({ level: "error", message: error.message });
|
|
70246
70553
|
next(new BadRequestError223(error.message));
|
|
70247
70554
|
return;
|
|
70248
70555
|
}
|
|
@@ -70254,7 +70561,7 @@ function useChannelPrelovedController() {
|
|
|
70254
70561
|
);
|
|
70255
70562
|
res.status(200).json(data);
|
|
70256
70563
|
} catch (error2) {
|
|
70257
|
-
|
|
70564
|
+
logger195.log({ level: "error", message: error2.message });
|
|
70258
70565
|
next(error2);
|
|
70259
70566
|
}
|
|
70260
70567
|
}
|
|
@@ -70267,7 +70574,7 @@ function useChannelPrelovedController() {
|
|
|
70267
70574
|
});
|
|
70268
70575
|
const { error, value } = querySchema.validate(req.query);
|
|
70269
70576
|
if (error) {
|
|
70270
|
-
|
|
70577
|
+
logger195.log({ level: "error", message: error.message });
|
|
70271
70578
|
next(new BadRequestError223(error.message));
|
|
70272
70579
|
return;
|
|
70273
70580
|
}
|
|
@@ -70280,7 +70587,7 @@ function useChannelPrelovedController() {
|
|
|
70280
70587
|
);
|
|
70281
70588
|
res.status(200).json(data);
|
|
70282
70589
|
} catch (error2) {
|
|
70283
|
-
|
|
70590
|
+
logger195.log({ level: "error", message: error2.message });
|
|
70284
70591
|
next(error2);
|
|
70285
70592
|
}
|
|
70286
70593
|
}
|
|
@@ -70290,7 +70597,7 @@ function useChannelPrelovedController() {
|
|
|
70290
70597
|
// src/repositories/bid-preloved.repo.ts
|
|
70291
70598
|
import {
|
|
70292
70599
|
InternalServerError as InternalServerError82,
|
|
70293
|
-
NotFoundError as
|
|
70600
|
+
NotFoundError as NotFoundError63,
|
|
70294
70601
|
useAtlas as useAtlas130
|
|
70295
70602
|
} from "@7365admin1/node-server-utils";
|
|
70296
70603
|
import { ObjectId as ObjectId152 } from "mongodb";
|
|
@@ -70312,7 +70619,7 @@ function useBidPrelovedRepo() {
|
|
|
70312
70619
|
const objectId2 = typeof _id === "string" ? new ObjectId152(_id) : _id;
|
|
70313
70620
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
70314
70621
|
if (!existing)
|
|
70315
|
-
throw new
|
|
70622
|
+
throw new NotFoundError63("Bid not found.");
|
|
70316
70623
|
const res = await collection.updateOne(
|
|
70317
70624
|
{ _id: objectId2 },
|
|
70318
70625
|
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
@@ -70326,7 +70633,7 @@ function useBidPrelovedRepo() {
|
|
|
70326
70633
|
_id = new ObjectId152(_id);
|
|
70327
70634
|
const result = await collection.findOne({ _id });
|
|
70328
70635
|
if (!result)
|
|
70329
|
-
throw new
|
|
70636
|
+
throw new NotFoundError63("Bid not found.");
|
|
70330
70637
|
return result;
|
|
70331
70638
|
}
|
|
70332
70639
|
return { add, getById, updateStatus };
|
|
@@ -70400,7 +70707,7 @@ function useBidPrelovedService() {
|
|
|
70400
70707
|
}
|
|
70401
70708
|
|
|
70402
70709
|
// src/controllers/bid-preloved.controller.ts
|
|
70403
|
-
import { BadRequestError as BadRequestError224, logger as
|
|
70710
|
+
import { BadRequestError as BadRequestError224, logger as logger196 } from "@7365admin1/node-server-utils";
|
|
70404
70711
|
import Joi147 from "joi";
|
|
70405
70712
|
function useBidPrelovedController() {
|
|
70406
70713
|
const { createBid: _createBid } = useBidPrelovedService();
|
|
@@ -70411,7 +70718,7 @@ function useBidPrelovedController() {
|
|
|
70411
70718
|
});
|
|
70412
70719
|
if (error) {
|
|
70413
70720
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70414
|
-
|
|
70721
|
+
logger196.log({ level: "error", message: messages });
|
|
70415
70722
|
next(new BadRequestError224(messages));
|
|
70416
70723
|
return;
|
|
70417
70724
|
}
|
|
@@ -70420,7 +70727,7 @@ function useBidPrelovedController() {
|
|
|
70420
70727
|
res.status(201).json(data);
|
|
70421
70728
|
} catch (error2) {
|
|
70422
70729
|
console.log("error", error2);
|
|
70423
|
-
|
|
70730
|
+
logger196.log({ level: "error", message: error2.message });
|
|
70424
70731
|
next(error2);
|
|
70425
70732
|
}
|
|
70426
70733
|
}
|
|
@@ -70432,7 +70739,7 @@ function useBidPrelovedController() {
|
|
|
70432
70739
|
req.params
|
|
70433
70740
|
);
|
|
70434
70741
|
if (paramError) {
|
|
70435
|
-
|
|
70742
|
+
logger196.log({ level: "error", message: paramError.message });
|
|
70436
70743
|
next(new BadRequestError224(paramError.message));
|
|
70437
70744
|
return;
|
|
70438
70745
|
}
|
|
@@ -70440,7 +70747,7 @@ function useBidPrelovedController() {
|
|
|
70440
70747
|
req.body
|
|
70441
70748
|
);
|
|
70442
70749
|
if (bodyError) {
|
|
70443
|
-
|
|
70750
|
+
logger196.log({ level: "error", message: bodyError.message });
|
|
70444
70751
|
next(new BadRequestError224(bodyError.message));
|
|
70445
70752
|
return;
|
|
70446
70753
|
}
|
|
@@ -70448,7 +70755,7 @@ function useBidPrelovedController() {
|
|
|
70448
70755
|
const data = await _updateStatus(params.id, body.status);
|
|
70449
70756
|
res.status(200).json(data);
|
|
70450
70757
|
} catch (error) {
|
|
70451
|
-
|
|
70758
|
+
logger196.log({ level: "error", message: error.message });
|
|
70452
70759
|
next(error);
|
|
70453
70760
|
}
|
|
70454
70761
|
}
|
|
@@ -70458,7 +70765,7 @@ function useBidPrelovedController() {
|
|
|
70458
70765
|
});
|
|
70459
70766
|
const { error, value: params } = paramsSchema.validate(req.params);
|
|
70460
70767
|
if (error) {
|
|
70461
|
-
|
|
70768
|
+
logger196.log({ level: "error", message: error.message });
|
|
70462
70769
|
next(new BadRequestError224(error.message));
|
|
70463
70770
|
return;
|
|
70464
70771
|
}
|
|
@@ -70466,7 +70773,7 @@ function useBidPrelovedController() {
|
|
|
70466
70773
|
const data = await _getById(params.id);
|
|
70467
70774
|
res.status(200).json(data);
|
|
70468
70775
|
} catch (error2) {
|
|
70469
|
-
|
|
70776
|
+
logger196.log({ level: "error", message: error2.message });
|
|
70470
70777
|
next(error2);
|
|
70471
70778
|
}
|
|
70472
70779
|
}
|
|
@@ -70605,8 +70912,8 @@ var residentFormEntry = Joi148.object({
|
|
|
70605
70912
|
import {
|
|
70606
70913
|
BadRequestError as BadRequestError225,
|
|
70607
70914
|
InternalServerError as InternalServerError84,
|
|
70608
|
-
NotFoundError as
|
|
70609
|
-
paginate as
|
|
70915
|
+
NotFoundError as NotFoundError64,
|
|
70916
|
+
paginate as paginate65,
|
|
70610
70917
|
useAtlas as useAtlas132,
|
|
70611
70918
|
useCache as useCache71
|
|
70612
70919
|
} from "@7365admin1/node-server-utils";
|
|
@@ -70694,7 +71001,7 @@ function useFormEntryRepo() {
|
|
|
70694
71001
|
{ $project: { user: 0 } }
|
|
70695
71002
|
]).toArray();
|
|
70696
71003
|
const length = await collection.countDocuments(query);
|
|
70697
|
-
const data =
|
|
71004
|
+
const data = paginate65(items, page, limit, length);
|
|
70698
71005
|
return data;
|
|
70699
71006
|
} catch (error) {
|
|
70700
71007
|
throw error;
|
|
@@ -70710,7 +71017,7 @@ function useFormEntryRepo() {
|
|
|
70710
71017
|
try {
|
|
70711
71018
|
const [data] = await collection.aggregate([{ $match: query }]).toArray();
|
|
70712
71019
|
if (!data) {
|
|
70713
|
-
throw new
|
|
71020
|
+
throw new NotFoundError64("Document not found.");
|
|
70714
71021
|
}
|
|
70715
71022
|
return data;
|
|
70716
71023
|
} catch (error) {
|
|
@@ -70734,11 +71041,11 @@ function useFormEntryRepo() {
|
|
|
70734
71041
|
}
|
|
70735
71042
|
const onlineFormRequest = await collection.findOne({ _id });
|
|
70736
71043
|
if (!onlineFormRequest) {
|
|
70737
|
-
throw new
|
|
71044
|
+
throw new NotFoundError64("Online form not found.");
|
|
70738
71045
|
}
|
|
70739
71046
|
const user = await getUserById(onlineFormRequest.userId.toString());
|
|
70740
71047
|
if (!user || !user._id) {
|
|
70741
|
-
throw new
|
|
71048
|
+
throw new NotFoundError64("User not found.");
|
|
70742
71049
|
}
|
|
70743
71050
|
const userId = user._id.toString();
|
|
70744
71051
|
await NotificationService.onlineFormRequestStatusUpdated({
|
|
@@ -70825,7 +71132,7 @@ function useFormEntryRepo() {
|
|
|
70825
71132
|
{ $limit: limit }
|
|
70826
71133
|
]).toArray();
|
|
70827
71134
|
const length = await collection.countDocuments(query);
|
|
70828
|
-
const data =
|
|
71135
|
+
const data = paginate65(items, page, limit, length);
|
|
70829
71136
|
return data;
|
|
70830
71137
|
} catch (error) {
|
|
70831
71138
|
throw error;
|
|
@@ -70844,7 +71151,7 @@ function useFormEntryRepo() {
|
|
|
70844
71151
|
}
|
|
70845
71152
|
|
|
70846
71153
|
// src/controllers/online-forms-v2.controller.ts
|
|
70847
|
-
import { BadRequestError as BadRequestError226, logger as
|
|
71154
|
+
import { BadRequestError as BadRequestError226, logger as logger198 } from "@7365admin1/node-server-utils";
|
|
70848
71155
|
import Joi149 from "joi";
|
|
70849
71156
|
import ExcelJS3 from "exceljs";
|
|
70850
71157
|
import fs6 from "fs";
|
|
@@ -70906,7 +71213,7 @@ function useFormEntryController() {
|
|
|
70906
71213
|
});
|
|
70907
71214
|
if (error) {
|
|
70908
71215
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70909
|
-
|
|
71216
|
+
logger198.log({ level: "error", message: messages });
|
|
70910
71217
|
next(new BadRequestError226(messages));
|
|
70911
71218
|
return;
|
|
70912
71219
|
}
|
|
@@ -70915,7 +71222,7 @@ function useFormEntryController() {
|
|
|
70915
71222
|
fs6.unlink(req.file.path, () => {
|
|
70916
71223
|
});
|
|
70917
71224
|
} catch (error) {
|
|
70918
|
-
|
|
71225
|
+
logger198.log({ level: "error", message: error.message });
|
|
70919
71226
|
next(error);
|
|
70920
71227
|
}
|
|
70921
71228
|
}
|
|
@@ -70932,7 +71239,7 @@ function useFormEntryController() {
|
|
|
70932
71239
|
const { error, value } = schema2.validate(req.query);
|
|
70933
71240
|
if (error) {
|
|
70934
71241
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70935
|
-
|
|
71242
|
+
logger198.log({ level: "error", message: messages });
|
|
70936
71243
|
next(new BadRequestError226(messages));
|
|
70937
71244
|
return;
|
|
70938
71245
|
}
|
|
@@ -70941,7 +71248,7 @@ function useFormEntryController() {
|
|
|
70941
71248
|
res.json(data);
|
|
70942
71249
|
return;
|
|
70943
71250
|
} catch (error) {
|
|
70944
|
-
|
|
71251
|
+
logger198.log({ level: "error", message: error.message });
|
|
70945
71252
|
next(error);
|
|
70946
71253
|
return;
|
|
70947
71254
|
}
|
|
@@ -70954,7 +71261,7 @@ function useFormEntryController() {
|
|
|
70954
71261
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
70955
71262
|
if (error) {
|
|
70956
71263
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70957
|
-
|
|
71264
|
+
logger198.log({ level: "error", message: messages });
|
|
70958
71265
|
next(new BadRequestError226(messages));
|
|
70959
71266
|
return;
|
|
70960
71267
|
}
|
|
@@ -70963,7 +71270,7 @@ function useFormEntryController() {
|
|
|
70963
71270
|
res.json(data);
|
|
70964
71271
|
return;
|
|
70965
71272
|
} catch (error) {
|
|
70966
|
-
|
|
71273
|
+
logger198.log({ level: "error", message: error.message });
|
|
70967
71274
|
next(error);
|
|
70968
71275
|
return;
|
|
70969
71276
|
}
|
|
@@ -70976,7 +71283,7 @@ function useFormEntryController() {
|
|
|
70976
71283
|
});
|
|
70977
71284
|
if (error) {
|
|
70978
71285
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
70979
|
-
|
|
71286
|
+
logger198.log({ level: "error", message: messages });
|
|
70980
71287
|
next(new BadRequestError226(messages));
|
|
70981
71288
|
return;
|
|
70982
71289
|
}
|
|
@@ -70985,7 +71292,7 @@ function useFormEntryController() {
|
|
|
70985
71292
|
res.json({ message: "Successfully updated online form." });
|
|
70986
71293
|
return;
|
|
70987
71294
|
} catch (error) {
|
|
70988
|
-
|
|
71295
|
+
logger198.log({ level: "error", message: error.message });
|
|
70989
71296
|
next(error);
|
|
70990
71297
|
return;
|
|
70991
71298
|
}
|
|
@@ -70996,7 +71303,7 @@ function useFormEntryController() {
|
|
|
70996
71303
|
const _id = req.params.id;
|
|
70997
71304
|
const { error } = validation.validate(_id);
|
|
70998
71305
|
if (error) {
|
|
70999
|
-
|
|
71306
|
+
logger198.log({ level: "error", message: error.message });
|
|
71000
71307
|
next(new BadRequestError226(error.message));
|
|
71001
71308
|
return;
|
|
71002
71309
|
}
|
|
@@ -71004,7 +71311,7 @@ function useFormEntryController() {
|
|
|
71004
71311
|
res.json({ message: "Successfully deleted online form." });
|
|
71005
71312
|
return;
|
|
71006
71313
|
} catch (error) {
|
|
71007
|
-
|
|
71314
|
+
logger198.log({ level: "error", message: error.message });
|
|
71008
71315
|
next(error);
|
|
71009
71316
|
return;
|
|
71010
71317
|
}
|
|
@@ -71021,7 +71328,7 @@ function useFormEntryController() {
|
|
|
71021
71328
|
});
|
|
71022
71329
|
if (error) {
|
|
71023
71330
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
71024
|
-
|
|
71331
|
+
logger198.log({ level: "error", message: messages });
|
|
71025
71332
|
next(new BadRequestError226(messages));
|
|
71026
71333
|
return;
|
|
71027
71334
|
}
|
|
@@ -71030,7 +71337,7 @@ function useFormEntryController() {
|
|
|
71030
71337
|
res.status(201).json({ message: data });
|
|
71031
71338
|
return;
|
|
71032
71339
|
} catch (error2) {
|
|
71033
|
-
|
|
71340
|
+
logger198.log({ level: "error", message: error2.message });
|
|
71034
71341
|
next(error2);
|
|
71035
71342
|
return;
|
|
71036
71343
|
}
|
|
@@ -71042,7 +71349,7 @@ function useFormEntryController() {
|
|
|
71042
71349
|
});
|
|
71043
71350
|
if (error) {
|
|
71044
71351
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
71045
|
-
|
|
71352
|
+
logger198.log({ level: "error", message: messages });
|
|
71046
71353
|
next(new BadRequestError226(messages));
|
|
71047
71354
|
return;
|
|
71048
71355
|
}
|
|
@@ -71051,7 +71358,7 @@ function useFormEntryController() {
|
|
|
71051
71358
|
res.status(201).json({ message: data });
|
|
71052
71359
|
return;
|
|
71053
71360
|
} catch (error2) {
|
|
71054
|
-
|
|
71361
|
+
logger198.log({ level: "error", message: error2.message });
|
|
71055
71362
|
next(error2);
|
|
71056
71363
|
return;
|
|
71057
71364
|
}
|
|
@@ -71071,7 +71378,7 @@ function useFormEntryController() {
|
|
|
71071
71378
|
});
|
|
71072
71379
|
if (error) {
|
|
71073
71380
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
71074
|
-
|
|
71381
|
+
logger198.log({ level: "error", message: messages });
|
|
71075
71382
|
next(new BadRequestError226(messages));
|
|
71076
71383
|
return;
|
|
71077
71384
|
}
|
|
@@ -71079,7 +71386,7 @@ function useFormEntryController() {
|
|
|
71079
71386
|
const result = await _residentForm({ userId, site, org, search, page, limit });
|
|
71080
71387
|
res.json(result);
|
|
71081
71388
|
} catch (error) {
|
|
71082
|
-
|
|
71389
|
+
logger198.log({ level: "error", message: error.message });
|
|
71083
71390
|
next(error);
|
|
71084
71391
|
return;
|
|
71085
71392
|
}
|
|
@@ -71135,7 +71442,7 @@ function useBuildingLevelService() {
|
|
|
71135
71442
|
}
|
|
71136
71443
|
|
|
71137
71444
|
// src/controllers/building-level.controller.ts
|
|
71138
|
-
import { BadRequestError as BadRequestError227, logger as
|
|
71445
|
+
import { BadRequestError as BadRequestError227, logger as logger199 } from "@7365admin1/node-server-utils";
|
|
71139
71446
|
import Joi150 from "joi";
|
|
71140
71447
|
function useBuildingLevelController() {
|
|
71141
71448
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
@@ -71153,7 +71460,7 @@ function useBuildingLevelController() {
|
|
|
71153
71460
|
});
|
|
71154
71461
|
if (error) {
|
|
71155
71462
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
71156
|
-
|
|
71463
|
+
logger199.log({ level: "error", message: messages });
|
|
71157
71464
|
next(new BadRequestError227(messages));
|
|
71158
71465
|
return;
|
|
71159
71466
|
}
|
|
@@ -71177,7 +71484,7 @@ function useBuildingLevelController() {
|
|
|
71177
71484
|
});
|
|
71178
71485
|
if (error) {
|
|
71179
71486
|
const messages = error.details.map((d) => d.message);
|
|
71180
|
-
|
|
71487
|
+
logger199.log({ level: "error", message: messages.join(", ") });
|
|
71181
71488
|
next(new BadRequestError227(messages.join(", ")));
|
|
71182
71489
|
return;
|
|
71183
71490
|
}
|
|
@@ -71203,7 +71510,7 @@ function useBuildingLevelController() {
|
|
|
71203
71510
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
71204
71511
|
if (error) {
|
|
71205
71512
|
const messages = error.details.map((d) => d.message);
|
|
71206
|
-
|
|
71513
|
+
logger199.log({ level: "error", message: messages.join(", ") });
|
|
71207
71514
|
next(new BadRequestError227(messages.join(", ")));
|
|
71208
71515
|
return;
|
|
71209
71516
|
}
|
|
@@ -71223,7 +71530,7 @@ function useBuildingLevelController() {
|
|
|
71223
71530
|
});
|
|
71224
71531
|
if (error) {
|
|
71225
71532
|
const messages = error.details.map((d) => d.message);
|
|
71226
|
-
|
|
71533
|
+
logger199.log({ level: "error", message: messages.join(", ") });
|
|
71227
71534
|
next(new BadRequestError227(messages.join(", ")));
|
|
71228
71535
|
return;
|
|
71229
71536
|
}
|
|
@@ -71242,7 +71549,7 @@ function useBuildingLevelController() {
|
|
|
71242
71549
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
71243
71550
|
if (error) {
|
|
71244
71551
|
const messages = error.details.map((d) => d.message);
|
|
71245
|
-
|
|
71552
|
+
logger199.log({ level: "error", message: messages.join(", ") });
|
|
71246
71553
|
next(new BadRequestError227(messages.join(", ")));
|
|
71247
71554
|
return;
|
|
71248
71555
|
}
|
|
@@ -71267,7 +71574,7 @@ function useBuildingLevelController() {
|
|
|
71267
71574
|
const { error, value } = schema2.validate(req.body);
|
|
71268
71575
|
if (error) {
|
|
71269
71576
|
const messages = error.details.map((d) => d.message);
|
|
71270
|
-
|
|
71577
|
+
logger199.log({ level: "error", message: messages.join(", ") });
|
|
71271
71578
|
next(new BadRequestError227(messages.join(", ")));
|
|
71272
71579
|
return;
|
|
71273
71580
|
}
|
|
@@ -71293,7 +71600,7 @@ function useBuildingLevelController() {
|
|
|
71293
71600
|
});
|
|
71294
71601
|
if (error) {
|
|
71295
71602
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
71296
|
-
|
|
71603
|
+
logger199.log({ level: "error", message: messages });
|
|
71297
71604
|
next(new BadRequestError227(messages));
|
|
71298
71605
|
return;
|
|
71299
71606
|
}
|
|
@@ -71317,7 +71624,7 @@ function useBuildingLevelController() {
|
|
|
71317
71624
|
}
|
|
71318
71625
|
|
|
71319
71626
|
// src/models/hid-amico.model.ts
|
|
71320
|
-
import { BadRequestError as BadRequestError228, logger as
|
|
71627
|
+
import { BadRequestError as BadRequestError228, logger as logger200 } from "@7365admin1/node-server-utils";
|
|
71321
71628
|
import { ObjectId as ObjectId155 } from "mongodb";
|
|
71322
71629
|
import Joi151 from "joi";
|
|
71323
71630
|
function canReadObjectId(value) {
|
|
@@ -71532,7 +71839,7 @@ var schemaHidAmicoNotificationParams = Joi151.object({
|
|
|
71532
71839
|
function MHidAmicoReader(value) {
|
|
71533
71840
|
const { error } = schemaHidAmicoReader.validate(value);
|
|
71534
71841
|
if (error) {
|
|
71535
|
-
|
|
71842
|
+
logger200.info(`HID Amico reader: ${error.message}`);
|
|
71536
71843
|
throw new BadRequestError228(error.message);
|
|
71537
71844
|
}
|
|
71538
71845
|
return {
|
|
@@ -71559,7 +71866,7 @@ function MHidAmicoReader(value) {
|
|
|
71559
71866
|
function MHidAmicoEvent(value) {
|
|
71560
71867
|
const { error } = schemaHidAmicoEvent.validate(value);
|
|
71561
71868
|
if (error) {
|
|
71562
|
-
|
|
71869
|
+
logger200.info(`HID Amico event: ${error.message}`);
|
|
71563
71870
|
throw new BadRequestError228(error.message);
|
|
71564
71871
|
}
|
|
71565
71872
|
return {
|
|
@@ -71578,7 +71885,7 @@ function optionalObjectId(value) {
|
|
|
71578
71885
|
function MHidAmicoIdentity(value) {
|
|
71579
71886
|
const { error } = schemaHidAmicoIdentity.validate(value);
|
|
71580
71887
|
if (error) {
|
|
71581
|
-
|
|
71888
|
+
logger200.info(`HID Amico identity: ${error.message}`);
|
|
71582
71889
|
throw new BadRequestError228(error.message);
|
|
71583
71890
|
}
|
|
71584
71891
|
return {
|
|
@@ -71605,8 +71912,8 @@ function MHidAmicoIdentity(value) {
|
|
|
71605
71912
|
import {
|
|
71606
71913
|
BadRequestError as BadRequestError229,
|
|
71607
71914
|
InternalServerError as InternalServerError85,
|
|
71608
|
-
logger as
|
|
71609
|
-
paginate as
|
|
71915
|
+
logger as logger201,
|
|
71916
|
+
paginate as paginate66,
|
|
71610
71917
|
useAtlas as useAtlas134
|
|
71611
71918
|
} from "@7365admin1/node-server-utils";
|
|
71612
71919
|
import { ObjectId as ObjectId156 } from "mongodb";
|
|
@@ -71682,7 +71989,7 @@ function useHidAmicoRepo() {
|
|
|
71682
71989
|
]);
|
|
71683
71990
|
return "HID Amico indexes created.";
|
|
71684
71991
|
} catch (error) {
|
|
71685
|
-
|
|
71992
|
+
logger201.error(error.message);
|
|
71686
71993
|
throw new Error("Failed to create HID Amico indexes.");
|
|
71687
71994
|
}
|
|
71688
71995
|
}
|
|
@@ -71707,7 +72014,7 @@ function useHidAmicoRepo() {
|
|
|
71707
72014
|
}
|
|
71708
72015
|
const items = await readers().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
71709
72016
|
const total = await readers().countDocuments(query);
|
|
71710
|
-
return
|
|
72017
|
+
return paginate66(items.map(hideSecret), page, limit, total);
|
|
71711
72018
|
}
|
|
71712
72019
|
async function getById(id, options = {}) {
|
|
71713
72020
|
const _id = toId(id, "reader ID");
|
|
@@ -71770,7 +72077,7 @@ function useHidAmicoRepo() {
|
|
|
71770
72077
|
}
|
|
71771
72078
|
const items = await events().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
71772
72079
|
const total = await events().countDocuments(query);
|
|
71773
|
-
return
|
|
72080
|
+
return paginate66(items, page, limit, total);
|
|
71774
72081
|
}
|
|
71775
72082
|
async function addIdentity(value, session) {
|
|
71776
72083
|
try {
|
|
@@ -71816,7 +72123,7 @@ function useHidAmicoRepo() {
|
|
|
71816
72123
|
}
|
|
71817
72124
|
const items = await identities().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
71818
72125
|
const total = await identities().countDocuments(query);
|
|
71819
|
-
return
|
|
72126
|
+
return paginate66(items, page, limit, total);
|
|
71820
72127
|
}
|
|
71821
72128
|
async function updateIdentity(id, value, session) {
|
|
71822
72129
|
const { error } = schemaUpdateHidAmicoIdentity.validate(value);
|