@7365admin1/core 2.34.0 → 2.35.1
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 +12 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +145 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +190 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -148,7 +148,8 @@ import {
|
|
|
148
148
|
NotFoundError as NotFoundError4,
|
|
149
149
|
AppError,
|
|
150
150
|
useCache as useCache5,
|
|
151
|
-
makeCacheKey as makeCacheKey5
|
|
151
|
+
makeCacheKey as makeCacheKey5,
|
|
152
|
+
toObjectId
|
|
152
153
|
} from "@7365admin1/node-server-utils";
|
|
153
154
|
|
|
154
155
|
// src/repositories/feedback.repo.ts
|
|
@@ -1582,10 +1583,21 @@ function useOccurrenceEntryRepo() {
|
|
|
1582
1583
|
} catch (error) {
|
|
1583
1584
|
throw new BadRequestError7("Invalid site ID format.");
|
|
1584
1585
|
}
|
|
1585
|
-
const
|
|
1586
|
-
|
|
1586
|
+
const escapedSearch = search ? search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") : "";
|
|
1587
|
+
const query = {
|
|
1588
|
+
site,
|
|
1589
|
+
...search && {
|
|
1590
|
+
$or: [
|
|
1591
|
+
{ occurrence: { $regex: escapedSearch, $options: "i" } },
|
|
1592
|
+
{ bookEntryCount: { $regex: escapedSearch, $options: "i" } },
|
|
1593
|
+
{ subjectName: { $regex: escapedSearch, $options: "i" } },
|
|
1594
|
+
{ userName: { $regex: escapedSearch, $options: "i" } }
|
|
1595
|
+
]
|
|
1596
|
+
},
|
|
1597
|
+
...dailyOccurrenceBookId && {
|
|
1598
|
+
dailyOccurrenceBookId: typeof dailyOccurrenceBookId === "string" ? new ObjectId7(dailyOccurrenceBookId) : dailyOccurrenceBookId
|
|
1599
|
+
}
|
|
1587
1600
|
};
|
|
1588
|
-
let query = { ...baseQuery };
|
|
1589
1601
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
1590
1602
|
const cacheOptions = {
|
|
1591
1603
|
site: site.toString(),
|
|
@@ -1594,20 +1606,9 @@ function useOccurrenceEntryRepo() {
|
|
|
1594
1606
|
limit,
|
|
1595
1607
|
...dailyOccurrenceBookId && {
|
|
1596
1608
|
dailyOccurrenceBookId
|
|
1597
|
-
}
|
|
1609
|
+
},
|
|
1610
|
+
...search && { search }
|
|
1598
1611
|
};
|
|
1599
|
-
if (search) {
|
|
1600
|
-
query.$text = { $search: search };
|
|
1601
|
-
cacheOptions.search = search;
|
|
1602
|
-
}
|
|
1603
|
-
if (dailyOccurrenceBookId) {
|
|
1604
|
-
try {
|
|
1605
|
-
dailyOccurrenceBookId = new ObjectId7(dailyOccurrenceBookId);
|
|
1606
|
-
query.dailyOccurrenceBookId = dailyOccurrenceBookId;
|
|
1607
|
-
} catch (error) {
|
|
1608
|
-
throw new BadRequestError7("Invalid daily occurrence book ID format.");
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
1612
|
const cacheKey = makeCacheKey4(namespace_collection, cacheOptions);
|
|
1612
1613
|
const cachedData = await getCache(cacheKey);
|
|
1613
1614
|
if (cachedData) {
|
|
@@ -1709,19 +1710,6 @@ function useOccurrenceEntryRepo() {
|
|
|
1709
1710
|
{ session }
|
|
1710
1711
|
).toArray();
|
|
1711
1712
|
length = await collection.countDocuments(query, { session });
|
|
1712
|
-
if ((!items || items.length === 0) && search) {
|
|
1713
|
-
const regexQuery = {
|
|
1714
|
-
...baseQuery,
|
|
1715
|
-
$or: [{ occurrence: { $regex: search, $options: "i" } }]
|
|
1716
|
-
};
|
|
1717
|
-
items = await collection.aggregate([
|
|
1718
|
-
{ $match: regexQuery },
|
|
1719
|
-
{ $sort: sort },
|
|
1720
|
-
{ $skip: page * limit },
|
|
1721
|
-
{ $limit: limit }
|
|
1722
|
-
]).toArray();
|
|
1723
|
-
length = await collection.countDocuments(regexQuery, { session });
|
|
1724
|
-
}
|
|
1725
1713
|
const data = paginate3(items, page, limit, length);
|
|
1726
1714
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
1727
1715
|
logger6.info(`Cache set for key: ${cacheKey}`);
|
|
@@ -2210,20 +2198,9 @@ function useUserRepo() {
|
|
|
2210
2198
|
}
|
|
2211
2199
|
async function getUserByEmail(email) {
|
|
2212
2200
|
try {
|
|
2213
|
-
const cacheKey = makeCacheKey5(namespace_collection, { email });
|
|
2214
|
-
const cachedData = await getCache(cacheKey);
|
|
2215
|
-
if (cachedData) {
|
|
2216
|
-
logger7.info(`Cache hit for key: ${cacheKey}`);
|
|
2217
|
-
return cachedData;
|
|
2218
|
-
}
|
|
2219
2201
|
const data = await collection.findOne({
|
|
2220
2202
|
email: { $regex: `^${email}$`, $options: "i" }
|
|
2221
2203
|
});
|
|
2222
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
2223
|
-
logger7.info(`Cache set for key: ${cacheKey}`);
|
|
2224
|
-
}).catch((err) => {
|
|
2225
|
-
logger7.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
2226
|
-
});
|
|
2227
2204
|
return data;
|
|
2228
2205
|
} catch (error) {
|
|
2229
2206
|
throw new InternalServerError5("Failed to get user by email.");
|
|
@@ -2530,6 +2507,39 @@ function useUserRepo() {
|
|
|
2530
2507
|
throw new InternalServerError5("Failed to update user password.");
|
|
2531
2508
|
}
|
|
2532
2509
|
}
|
|
2510
|
+
async function resetPassword({
|
|
2511
|
+
_id,
|
|
2512
|
+
password,
|
|
2513
|
+
sid
|
|
2514
|
+
}, session) {
|
|
2515
|
+
try {
|
|
2516
|
+
_id = new ObjectId9(_id);
|
|
2517
|
+
} catch (error) {
|
|
2518
|
+
throw new BadRequestError9("Invalid user ID format.");
|
|
2519
|
+
}
|
|
2520
|
+
try {
|
|
2521
|
+
const result = await collection.updateOne(
|
|
2522
|
+
{ _id },
|
|
2523
|
+
{ $set: { password, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
2524
|
+
{ session }
|
|
2525
|
+
);
|
|
2526
|
+
const cacheKey = makeCacheKey5(namespace_collection, { _id });
|
|
2527
|
+
delCache(cacheKey).then(() => {
|
|
2528
|
+
logger7.info(`Cache deleted for key: ${cacheKey}`);
|
|
2529
|
+
}).catch((err) => {
|
|
2530
|
+
logger7.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
2531
|
+
});
|
|
2532
|
+
const authCacheKey = `sid:${sid}`;
|
|
2533
|
+
delCache(authCacheKey).then(() => {
|
|
2534
|
+
logger7.info(`Cache deleted for key: ${authCacheKey}`);
|
|
2535
|
+
}).catch((err) => {
|
|
2536
|
+
logger7.error(`Failed to delete cache for key: ${authCacheKey}`, err);
|
|
2537
|
+
});
|
|
2538
|
+
return result;
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
throw new InternalServerError5("Failed to update user password.");
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2533
2543
|
async function updateBirthday({
|
|
2534
2544
|
_id,
|
|
2535
2545
|
month,
|
|
@@ -2622,6 +2632,19 @@ function useUserRepo() {
|
|
|
2622
2632
|
throw new InternalServerError5(`Failed to update user ${field}.`);
|
|
2623
2633
|
}
|
|
2624
2634
|
}
|
|
2635
|
+
async function updateUserSIDById(id, sid, session) {
|
|
2636
|
+
const _id = toObjectId(id);
|
|
2637
|
+
try {
|
|
2638
|
+
const result = await collection.updateOne(
|
|
2639
|
+
{ _id },
|
|
2640
|
+
{ $set: { sid, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
2641
|
+
{ session }
|
|
2642
|
+
);
|
|
2643
|
+
return result;
|
|
2644
|
+
} catch (error) {
|
|
2645
|
+
throw new InternalServerError5("Failed to update user.");
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2625
2648
|
return {
|
|
2626
2649
|
createIndex,
|
|
2627
2650
|
createTextIndex,
|
|
@@ -2637,7 +2660,9 @@ function useUserRepo() {
|
|
|
2637
2660
|
updateBirthday,
|
|
2638
2661
|
updateUserFieldById,
|
|
2639
2662
|
updateDefaultOrgByEmail,
|
|
2640
|
-
getUserByEmailStatus
|
|
2663
|
+
getUserByEmailStatus,
|
|
2664
|
+
updateUserSIDById,
|
|
2665
|
+
resetPassword
|
|
2641
2666
|
};
|
|
2642
2667
|
}
|
|
2643
2668
|
|
|
@@ -3482,7 +3507,11 @@ function useMemberRepo() {
|
|
|
3482
3507
|
|
|
3483
3508
|
// src/services/auth.service.ts
|
|
3484
3509
|
function useAuthService() {
|
|
3485
|
-
const {
|
|
3510
|
+
const {
|
|
3511
|
+
getUserByEmail,
|
|
3512
|
+
getUserById: _getUserById,
|
|
3513
|
+
updateUserSIDById: _updateUserSIDById
|
|
3514
|
+
} = useUserRepo();
|
|
3486
3515
|
const { getByToken, deleteByToken } = useSessionRepo();
|
|
3487
3516
|
const expiresIn = "15m";
|
|
3488
3517
|
const { setCache, delCache } = useCache7("sessions");
|
|
@@ -3520,7 +3549,9 @@ function useAuthService() {
|
|
|
3520
3549
|
}
|
|
3521
3550
|
const sid = uuidv4();
|
|
3522
3551
|
const cacheKey = `sid:${sid}`;
|
|
3523
|
-
|
|
3552
|
+
await _updateUserSIDById(user._id, sid);
|
|
3553
|
+
const updatedUser = await _getUserById(user._id);
|
|
3554
|
+
setCache(cacheKey, updatedUser, 14400).then(() => {
|
|
3524
3555
|
console.log("Session ID cached successfully");
|
|
3525
3556
|
}).catch((error) => {
|
|
3526
3557
|
console.error("Error caching session ID:", error);
|
|
@@ -4351,7 +4382,7 @@ import {
|
|
|
4351
4382
|
logger as logger12,
|
|
4352
4383
|
makeCacheKey as makeCacheKey9,
|
|
4353
4384
|
AppError as AppError4,
|
|
4354
|
-
toObjectId as
|
|
4385
|
+
toObjectId as toObjectId3
|
|
4355
4386
|
} from "@7365admin1/node-server-utils";
|
|
4356
4387
|
import Joi10 from "joi";
|
|
4357
4388
|
function useSiteRepo() {
|
|
@@ -4737,7 +4768,7 @@ function useSiteRepo() {
|
|
|
4737
4768
|
}
|
|
4738
4769
|
}
|
|
4739
4770
|
async function updateSiteById(id, payload, session) {
|
|
4740
|
-
const _id =
|
|
4771
|
+
const _id = toObjectId3(id);
|
|
4741
4772
|
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4742
4773
|
try {
|
|
4743
4774
|
const res = await collection.updateOne(
|
|
@@ -5751,7 +5782,8 @@ function useUserService() {
|
|
|
5751
5782
|
getUserById,
|
|
5752
5783
|
getUserByEmail,
|
|
5753
5784
|
updatePassword,
|
|
5754
|
-
updateUserFieldById: _updateUserFieldById
|
|
5785
|
+
updateUserFieldById: _updateUserFieldById,
|
|
5786
|
+
resetPassword: _resetPassword
|
|
5755
5787
|
} = useUserRepo();
|
|
5756
5788
|
const { getRoleByName, addRole } = useRoleRepo();
|
|
5757
5789
|
const { add: addMember } = useMemberRepo();
|
|
@@ -5927,8 +5959,12 @@ function useUserService() {
|
|
|
5927
5959
|
throw new InternalServerError14("Invalid user ID.");
|
|
5928
5960
|
}
|
|
5929
5961
|
await updateStatusById(id, "complete", session);
|
|
5930
|
-
await
|
|
5931
|
-
{
|
|
5962
|
+
await _resetPassword(
|
|
5963
|
+
{
|
|
5964
|
+
_id: user._id.toString(),
|
|
5965
|
+
password: hashedPassword,
|
|
5966
|
+
sid: user.sid
|
|
5967
|
+
},
|
|
5932
5968
|
session
|
|
5933
5969
|
);
|
|
5934
5970
|
await session?.commitTransaction();
|
|
@@ -8652,7 +8688,7 @@ import {
|
|
|
8652
8688
|
import { z } from "zod";
|
|
8653
8689
|
import { ObjectId as ObjectId26 } from "mongodb";
|
|
8654
8690
|
import { BadRequestError as BadRequestError39 } from "@7365admin1/node-server-utils";
|
|
8655
|
-
function
|
|
8691
|
+
function toObjectId4(value) {
|
|
8656
8692
|
if (typeof value === "string") {
|
|
8657
8693
|
if (!/^[a-fA-F0-9]{24}$/.test(value)) {
|
|
8658
8694
|
throw new BadRequestError39(`Invalid ObjectId format: ${value}`);
|
|
@@ -8704,7 +8740,7 @@ var TInvoice = z.object({
|
|
|
8704
8740
|
message: "Invalid ObjectId: Must be a 24-character hex string."
|
|
8705
8741
|
}),
|
|
8706
8742
|
z.instanceof(ObjectId26, { message: "Invalid ObjectId instance." })
|
|
8707
|
-
]).optional().transform((val) => val ?
|
|
8743
|
+
]).optional().transform((val) => val ? toObjectId4(val) : void 0),
|
|
8708
8744
|
invoiceNumber: z.string({ required_error: "Invoice number is required." }),
|
|
8709
8745
|
type: TInvoiceType.default("other"),
|
|
8710
8746
|
amount: z.number().min(0, { message: "Invoice amount must be at least 0." }),
|
|
@@ -12457,7 +12493,7 @@ import {
|
|
|
12457
12493
|
logger as logger46,
|
|
12458
12494
|
makeCacheKey as makeCacheKey21,
|
|
12459
12495
|
paginate as paginate16,
|
|
12460
|
-
toObjectId as
|
|
12496
|
+
toObjectId as toObjectId6,
|
|
12461
12497
|
useAtlas as useAtlas29,
|
|
12462
12498
|
useCache as useCache22
|
|
12463
12499
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12685,7 +12721,7 @@ function useSiteCameraRepo() {
|
|
|
12685
12721
|
});
|
|
12686
12722
|
}
|
|
12687
12723
|
async function getBySite(site, options = {}) {
|
|
12688
|
-
const _site =
|
|
12724
|
+
const _site = toObjectId6(site);
|
|
12689
12725
|
const cacheKeyOptions = {
|
|
12690
12726
|
site,
|
|
12691
12727
|
tag: "get-by-site",
|
|
@@ -12919,7 +12955,7 @@ import {
|
|
|
12919
12955
|
BadRequestError as BadRequestError66,
|
|
12920
12956
|
InternalServerError as InternalServerError23,
|
|
12921
12957
|
paginate as paginate17,
|
|
12922
|
-
toObjectId as
|
|
12958
|
+
toObjectId as toObjectId7,
|
|
12923
12959
|
useAtlas as useAtlas30
|
|
12924
12960
|
} from "@7365admin1/node-server-utils";
|
|
12925
12961
|
|
|
@@ -13226,21 +13262,21 @@ function MVisitorTransaction(value) {
|
|
|
13226
13262
|
try {
|
|
13227
13263
|
value.org = new ObjectId39(value.org);
|
|
13228
13264
|
} catch (error2) {
|
|
13229
|
-
throw new Error("Invalid ID.");
|
|
13265
|
+
throw new Error("Invalid org ID.");
|
|
13230
13266
|
}
|
|
13231
13267
|
}
|
|
13232
13268
|
if (value.site && typeof value.site === "string") {
|
|
13233
13269
|
try {
|
|
13234
13270
|
value.site = new ObjectId39(value.site);
|
|
13235
13271
|
} catch (error2) {
|
|
13236
|
-
throw new Error("Invalid ID.");
|
|
13272
|
+
throw new Error("Invalid site ID.");
|
|
13237
13273
|
}
|
|
13238
13274
|
}
|
|
13239
13275
|
if (value.unit && typeof value.unit === "string") {
|
|
13240
13276
|
try {
|
|
13241
13277
|
value.unit = new ObjectId39(value.unit);
|
|
13242
13278
|
} catch (error2) {
|
|
13243
|
-
throw new Error("Invalid ID.");
|
|
13279
|
+
throw new Error("Invalid unit ID.");
|
|
13244
13280
|
}
|
|
13245
13281
|
}
|
|
13246
13282
|
if (value.manualCheckout && typeof value.manualCheckout === "string") {
|
|
@@ -13270,6 +13306,13 @@ function MVisitorTransaction(value) {
|
|
|
13270
13306
|
return p;
|
|
13271
13307
|
});
|
|
13272
13308
|
}
|
|
13309
|
+
if (value.invitedId && typeof value.invitedId === "string") {
|
|
13310
|
+
try {
|
|
13311
|
+
value.invitedId = new ObjectId39(value.invitedId);
|
|
13312
|
+
} catch (error2) {
|
|
13313
|
+
throw new Error("Invalid invited ID.");
|
|
13314
|
+
}
|
|
13315
|
+
}
|
|
13273
13316
|
const newDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
13274
13317
|
return {
|
|
13275
13318
|
_id: value._id,
|
|
@@ -13310,11 +13353,11 @@ function MVisitorTransaction(value) {
|
|
|
13310
13353
|
numberOfPassengers: value.numberOfPassengers ?? null,
|
|
13311
13354
|
email: value.email,
|
|
13312
13355
|
isOvernightParking: value.isOvernightParking ?? false,
|
|
13313
|
-
invitedId:
|
|
13356
|
+
invitedId: value.invitedId ?? "",
|
|
13314
13357
|
overnightParking: value.isOvernightParking == true ? {
|
|
13315
13358
|
status: "pending approval",
|
|
13316
13359
|
remarks: "",
|
|
13317
|
-
updatedBy:
|
|
13360
|
+
updatedBy: value.invitedId ?? ""
|
|
13318
13361
|
} : null
|
|
13319
13362
|
};
|
|
13320
13363
|
}
|
|
@@ -13561,7 +13604,7 @@ function useVisitorTransactionRepo() {
|
|
|
13561
13604
|
}
|
|
13562
13605
|
}
|
|
13563
13606
|
async function getVisitorTransactionById(id) {
|
|
13564
|
-
const _id =
|
|
13607
|
+
const _id = toObjectId7(id);
|
|
13565
13608
|
try {
|
|
13566
13609
|
const basePipeline = [{ $match: { _id } }];
|
|
13567
13610
|
const [result] = await collection.aggregate([
|
|
@@ -13603,7 +13646,7 @@ function useVisitorTransactionRepo() {
|
|
|
13603
13646
|
}
|
|
13604
13647
|
}
|
|
13605
13648
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
13606
|
-
const _site = typeof site === "string" ?
|
|
13649
|
+
const _site = typeof site === "string" ? toObjectId7(site) : site;
|
|
13607
13650
|
const query = {
|
|
13608
13651
|
plateNumber,
|
|
13609
13652
|
site: _site,
|
|
@@ -13687,7 +13730,7 @@ function useVisitorTransactionRepo() {
|
|
|
13687
13730
|
}
|
|
13688
13731
|
}
|
|
13689
13732
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
13690
|
-
const site =
|
|
13733
|
+
const site = toObjectId7(siteId);
|
|
13691
13734
|
try {
|
|
13692
13735
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13693
13736
|
const expiredTransactions = await collection.find({
|
|
@@ -13936,7 +13979,7 @@ import {
|
|
|
13936
13979
|
logger as logger49,
|
|
13937
13980
|
NotFoundError as NotFoundError17,
|
|
13938
13981
|
paginate as paginate18,
|
|
13939
|
-
toObjectId as
|
|
13982
|
+
toObjectId as toObjectId8,
|
|
13940
13983
|
useAtlas as useAtlas31
|
|
13941
13984
|
} from "@7365admin1/node-server-utils";
|
|
13942
13985
|
import { ObjectId as ObjectId42 } from "mongodb";
|
|
@@ -14535,7 +14578,7 @@ function useVehicleRepo() {
|
|
|
14535
14578
|
page = page > 0 ? page - 1 : 0;
|
|
14536
14579
|
const skip = page * limit;
|
|
14537
14580
|
try {
|
|
14538
|
-
const unit =
|
|
14581
|
+
const unit = toObjectId8(unitId);
|
|
14539
14582
|
const query = {
|
|
14540
14583
|
unit
|
|
14541
14584
|
};
|
|
@@ -14604,7 +14647,7 @@ import {
|
|
|
14604
14647
|
useAtlas as useAtlas32,
|
|
14605
14648
|
useCache as useCache25,
|
|
14606
14649
|
AppError as AppError10,
|
|
14607
|
-
toObjectId as
|
|
14650
|
+
toObjectId as toObjectId9
|
|
14608
14651
|
} from "@7365admin1/node-server-utils";
|
|
14609
14652
|
import { ObjectId as ObjectId43 } from "mongodb";
|
|
14610
14653
|
var site_people_namespace_collection = "site.people";
|
|
@@ -15085,7 +15128,7 @@ function usePersonRepo() {
|
|
|
15085
15128
|
async function pushVehicleById(id, plate, session) {
|
|
15086
15129
|
const { plateNumber, recNo } = plate;
|
|
15087
15130
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15088
|
-
const _id =
|
|
15131
|
+
const _id = toObjectId9(id);
|
|
15089
15132
|
try {
|
|
15090
15133
|
const updateExisting = await collection.updateOne(
|
|
15091
15134
|
{
|
|
@@ -15143,7 +15186,7 @@ function usePersonRepo() {
|
|
|
15143
15186
|
}
|
|
15144
15187
|
}
|
|
15145
15188
|
async function getByUserId(userId) {
|
|
15146
|
-
const user =
|
|
15189
|
+
const user = toObjectId9(userId);
|
|
15147
15190
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
15148
15191
|
user: userId
|
|
15149
15192
|
});
|
|
@@ -17415,7 +17458,7 @@ import {
|
|
|
17415
17458
|
logger as logger60,
|
|
17416
17459
|
makeCacheKey as makeCacheKey26,
|
|
17417
17460
|
paginate as paginate21,
|
|
17418
|
-
toObjectId as
|
|
17461
|
+
toObjectId as toObjectId11,
|
|
17419
17462
|
useAtlas as useAtlas37,
|
|
17420
17463
|
useCache as useCache28
|
|
17421
17464
|
} from "@7365admin1/node-server-utils";
|
|
@@ -17580,8 +17623,8 @@ function useBuildingUnitRepo() {
|
|
|
17580
17623
|
const query = {
|
|
17581
17624
|
status,
|
|
17582
17625
|
...search && { $text: { $search: search } },
|
|
17583
|
-
...site && { site:
|
|
17584
|
-
...building && { building:
|
|
17626
|
+
...site && { site: toObjectId11(site) },
|
|
17627
|
+
...building && { building: toObjectId11(building) }
|
|
17585
17628
|
};
|
|
17586
17629
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17587
17630
|
const cacheParams = {
|
|
@@ -27215,7 +27258,7 @@ import {
|
|
|
27215
27258
|
makeCacheKey as makeCacheKey37,
|
|
27216
27259
|
NotFoundError as NotFoundError27,
|
|
27217
27260
|
paginate as paginate31,
|
|
27218
|
-
toObjectId as
|
|
27261
|
+
toObjectId as toObjectId12,
|
|
27219
27262
|
useAtlas as useAtlas61,
|
|
27220
27263
|
useCache as useCache39
|
|
27221
27264
|
} from "@7365admin1/node-server-utils";
|
|
@@ -27271,7 +27314,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
27271
27314
|
page = page > 0 ? page - 1 : 0;
|
|
27272
27315
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27273
27316
|
const skip = page * limit;
|
|
27274
|
-
const siteId =
|
|
27317
|
+
const siteId = toObjectId12(site);
|
|
27275
27318
|
const query = {
|
|
27276
27319
|
site: siteId,
|
|
27277
27320
|
status,
|
|
@@ -27317,7 +27360,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
27317
27360
|
}
|
|
27318
27361
|
}
|
|
27319
27362
|
async function getSiteFacilityBookingById(id, session) {
|
|
27320
|
-
const _id =
|
|
27363
|
+
const _id = toObjectId12(id);
|
|
27321
27364
|
const cacheKey = makeCacheKey37(facility_bookings_namespace_collection, {
|
|
27322
27365
|
id
|
|
27323
27366
|
});
|
|
@@ -27343,17 +27386,17 @@ function useSiteFacilityBookingRepo() {
|
|
|
27343
27386
|
}
|
|
27344
27387
|
async function updateSiteFacilityBookingById(id, value, session) {
|
|
27345
27388
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
27346
|
-
const _id =
|
|
27389
|
+
const _id = toObjectId12(id);
|
|
27347
27390
|
if (value.site)
|
|
27348
|
-
value.site = typeof value.site === "string" ?
|
|
27391
|
+
value.site = typeof value.site === "string" ? toObjectId12(value.site) : value.site;
|
|
27349
27392
|
if (value.user)
|
|
27350
|
-
value.user = typeof value.user === "string" ?
|
|
27393
|
+
value.user = typeof value.user === "string" ? toObjectId12(value.user) : value.user;
|
|
27351
27394
|
if (value.date)
|
|
27352
27395
|
value.date = value.date ? new Date(value.date).toISOString() : value.date;
|
|
27353
27396
|
if (value.approvedBy)
|
|
27354
|
-
value.approvedBy = typeof value.approvedBy === "string" ?
|
|
27397
|
+
value.approvedBy = typeof value.approvedBy === "string" ? toObjectId12(value.approvedBy) : value.approvedBy;
|
|
27355
27398
|
if (value.createdBy)
|
|
27356
|
-
value.createdBy = typeof value.createdBy === "string" ?
|
|
27399
|
+
value.createdBy = typeof value.createdBy === "string" ? toObjectId12(value.createdBy) : value.createdBy;
|
|
27357
27400
|
try {
|
|
27358
27401
|
const res = await collection.updateOne(
|
|
27359
27402
|
{ _id },
|
|
@@ -35636,7 +35679,7 @@ import {
|
|
|
35636
35679
|
makeCacheKey as makeCacheKey46,
|
|
35637
35680
|
NotFoundError as NotFoundError37,
|
|
35638
35681
|
paginate as paginate40,
|
|
35639
|
-
toObjectId as
|
|
35682
|
+
toObjectId as toObjectId13,
|
|
35640
35683
|
useAtlas as useAtlas78,
|
|
35641
35684
|
useCache as useCache48
|
|
35642
35685
|
} from "@7365admin1/node-server-utils";
|
|
@@ -35711,7 +35754,7 @@ function useOccurrenceBookRepo() {
|
|
|
35711
35754
|
status = ""
|
|
35712
35755
|
}, session) {
|
|
35713
35756
|
page = page > 0 && !date ? page - 1 : 0;
|
|
35714
|
-
const _site =
|
|
35757
|
+
const _site = toObjectId13(site);
|
|
35715
35758
|
const query = {
|
|
35716
35759
|
site: _site,
|
|
35717
35760
|
...status && { status },
|
|
@@ -42173,7 +42216,7 @@ import {
|
|
|
42173
42216
|
InternalServerError as InternalServerError59,
|
|
42174
42217
|
logger as logger155,
|
|
42175
42218
|
makeCacheKey as makeCacheKey57,
|
|
42176
|
-
toObjectId as
|
|
42219
|
+
toObjectId as toObjectId14,
|
|
42177
42220
|
useAtlas as useAtlas98,
|
|
42178
42221
|
useCache as useCache59
|
|
42179
42222
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42265,7 +42308,7 @@ function useNewDashboardRepo() {
|
|
|
42265
42308
|
securityDashboardCollection
|
|
42266
42309
|
);
|
|
42267
42310
|
async function getMetric(collectionString, siteId, period) {
|
|
42268
|
-
const site =
|
|
42311
|
+
const site = toObjectId14(siteId);
|
|
42269
42312
|
const range = getPeriodRangeWithPrevious(period);
|
|
42270
42313
|
const collection = db.collection(collectionString);
|
|
42271
42314
|
const current = await collection.countDocuments({
|
|
@@ -44243,7 +44286,7 @@ import {
|
|
|
44243
44286
|
InternalServerError as InternalServerError63,
|
|
44244
44287
|
logger as logger163,
|
|
44245
44288
|
makeCacheKey as makeCacheKey61,
|
|
44246
|
-
toObjectId as
|
|
44289
|
+
toObjectId as toObjectId15,
|
|
44247
44290
|
useAtlas as useAtlas103,
|
|
44248
44291
|
useCache as useCache63
|
|
44249
44292
|
} from "@7365admin1/node-server-utils";
|
|
@@ -44322,7 +44365,7 @@ function useOvernightParkingRepo() {
|
|
|
44322
44365
|
}
|
|
44323
44366
|
}
|
|
44324
44367
|
async function getSiteOvernightParking(site) {
|
|
44325
|
-
const siteId =
|
|
44368
|
+
const siteId = toObjectId15(site);
|
|
44326
44369
|
const cacheKey = makeCacheKey61(overnight_parking_namespace_collection, {
|
|
44327
44370
|
site
|
|
44328
44371
|
});
|
|
@@ -44418,7 +44461,7 @@ function useOvernightParkingController() {
|
|
|
44418
44461
|
|
|
44419
44462
|
// src/models/overnight-parking-request.model.ts
|
|
44420
44463
|
import Joi118 from "joi";
|
|
44421
|
-
import { toObjectId as
|
|
44464
|
+
import { toObjectId as toObjectId16 } from "@7365admin1/node-server-utils";
|
|
44422
44465
|
var OvernightParkingRequestStatus = /* @__PURE__ */ ((OvernightParkingRequestStatus2) => {
|
|
44423
44466
|
OvernightParkingRequestStatus2["PENDING"] = "pending";
|
|
44424
44467
|
OvernightParkingRequestStatus2["APPROVED"] = "approved";
|
|
@@ -44455,7 +44498,7 @@ function MOvernightParkingRequest(value) {
|
|
|
44455
44498
|
throw new Error(error.details[0].message);
|
|
44456
44499
|
}
|
|
44457
44500
|
if (value.site && typeof value.site === "string")
|
|
44458
|
-
value.site =
|
|
44501
|
+
value.site = toObjectId16(value.site);
|
|
44459
44502
|
const data = {
|
|
44460
44503
|
...value,
|
|
44461
44504
|
createdAt: value.createdAt ? new Date(value.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -44472,7 +44515,7 @@ import {
|
|
|
44472
44515
|
logger as logger165,
|
|
44473
44516
|
makeCacheKey as makeCacheKey62,
|
|
44474
44517
|
paginate as paginate54,
|
|
44475
|
-
toObjectId as
|
|
44518
|
+
toObjectId as toObjectId17,
|
|
44476
44519
|
useAtlas as useAtlas104,
|
|
44477
44520
|
useCache as useCache64
|
|
44478
44521
|
} from "@7365admin1/node-server-utils";
|
|
@@ -44540,7 +44583,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44540
44583
|
}) {
|
|
44541
44584
|
page = page ? page - 1 : 0;
|
|
44542
44585
|
const skip = page * limit;
|
|
44543
|
-
const siteId =
|
|
44586
|
+
const siteId = toObjectId17(site);
|
|
44544
44587
|
const query = {
|
|
44545
44588
|
site: siteId,
|
|
44546
44589
|
...status && { status }
|
|
@@ -44591,7 +44634,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44591
44634
|
logger165.info(`Cache hit for key: ${cacheKey}`);
|
|
44592
44635
|
return cachedData;
|
|
44593
44636
|
}
|
|
44594
|
-
const _id =
|
|
44637
|
+
const _id = toObjectId17(id);
|
|
44595
44638
|
const data = await collection.findOne({ _id });
|
|
44596
44639
|
if (!data)
|
|
44597
44640
|
throw new BadRequestError188("Overnight parking request not found.");
|
|
@@ -44607,7 +44650,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44607
44650
|
}
|
|
44608
44651
|
async function updateOvernightParkingRequestById(id, value, session) {
|
|
44609
44652
|
try {
|
|
44610
|
-
const _id =
|
|
44653
|
+
const _id = toObjectId17(id);
|
|
44611
44654
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
44612
44655
|
const data = await collection.updateOne(
|
|
44613
44656
|
{ _id },
|
|
@@ -44633,7 +44676,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44633
44676
|
}
|
|
44634
44677
|
async function deleteOvernightParkingRequestById(id, session) {
|
|
44635
44678
|
try {
|
|
44636
|
-
const _id =
|
|
44679
|
+
const _id = toObjectId17(id);
|
|
44637
44680
|
const value = {
|
|
44638
44681
|
deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
44639
44682
|
status: "deleted" /* DELETED */
|
|
@@ -44662,7 +44705,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44662
44705
|
}
|
|
44663
44706
|
async function updateExpiredRequests(site, session) {
|
|
44664
44707
|
try {
|
|
44665
|
-
const _site =
|
|
44708
|
+
const _site = toObjectId17(site);
|
|
44666
44709
|
const value = {
|
|
44667
44710
|
status: "expired" /* EXPIRED */
|
|
44668
44711
|
};
|
|
@@ -47260,7 +47303,7 @@ import {
|
|
|
47260
47303
|
logger as logger175,
|
|
47261
47304
|
makeCacheKey as makeCacheKey64,
|
|
47262
47305
|
paginate as paginate57,
|
|
47263
|
-
toObjectId as
|
|
47306
|
+
toObjectId as toObjectId18,
|
|
47264
47307
|
useAtlas as useAtlas112,
|
|
47265
47308
|
useCache as useCache66
|
|
47266
47309
|
} from "@7365admin1/node-server-utils";
|
|
@@ -47367,7 +47410,7 @@ function useVerificationRepoV2() {
|
|
|
47367
47410
|
}
|
|
47368
47411
|
async function getVerificationById(id) {
|
|
47369
47412
|
try {
|
|
47370
|
-
const _id =
|
|
47413
|
+
const _id = toObjectId18(id);
|
|
47371
47414
|
const cacheKey = makeCacheKey64(namespace_collection, { id });
|
|
47372
47415
|
const cachedData = await getCache(cacheKey);
|
|
47373
47416
|
if (cachedData) {
|
|
@@ -48073,7 +48116,7 @@ import {
|
|
|
48073
48116
|
AppError as AppError27,
|
|
48074
48117
|
useCache as useCache67,
|
|
48075
48118
|
makeCacheKey as makeCacheKey65,
|
|
48076
|
-
toObjectId as
|
|
48119
|
+
toObjectId as toObjectId19
|
|
48077
48120
|
} from "@7365admin1/node-server-utils";
|
|
48078
48121
|
function useUserRepoV2() {
|
|
48079
48122
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
@@ -48174,7 +48217,7 @@ function useUserRepoV2() {
|
|
|
48174
48217
|
}
|
|
48175
48218
|
}
|
|
48176
48219
|
async function getUserById(id) {
|
|
48177
|
-
const _id =
|
|
48220
|
+
const _id = toObjectId19(id);
|
|
48178
48221
|
try {
|
|
48179
48222
|
const cacheKey = makeCacheKey65(namespace_collection, { id });
|
|
48180
48223
|
const cachedData = await getCache(cacheKey);
|
|
@@ -48379,7 +48422,7 @@ function useUserRepoV2() {
|
|
|
48379
48422
|
}
|
|
48380
48423
|
async function updatePasswordById({ _id, password }, session) {
|
|
48381
48424
|
const cacheKey = makeCacheKey65(namespace_collection, { _id });
|
|
48382
|
-
_id =
|
|
48425
|
+
_id = toObjectId19(_id);
|
|
48383
48426
|
try {
|
|
48384
48427
|
const result = await collection.updateOne(
|
|
48385
48428
|
{ _id },
|
|
@@ -48585,9 +48628,25 @@ function useAuthServiceV2() {
|
|
|
48585
48628
|
throw new InternalServerError71("Error deleting token");
|
|
48586
48629
|
}
|
|
48587
48630
|
}
|
|
48631
|
+
async function verifyPassword(_id, password) {
|
|
48632
|
+
try {
|
|
48633
|
+
const user = await _getUserById(_id);
|
|
48634
|
+
const isPasswordMatch = await comparePassword3(password, user.password);
|
|
48635
|
+
if (!isPasswordMatch) {
|
|
48636
|
+
throw new BadRequestError199("Invalid credentials");
|
|
48637
|
+
}
|
|
48638
|
+
return "Verification successful.";
|
|
48639
|
+
} catch (error) {
|
|
48640
|
+
if (error instanceof BadRequestError199) {
|
|
48641
|
+
throw error;
|
|
48642
|
+
}
|
|
48643
|
+
throw new InternalServerError71("Error during password verification");
|
|
48644
|
+
}
|
|
48645
|
+
}
|
|
48588
48646
|
return {
|
|
48589
48647
|
login,
|
|
48590
|
-
logout
|
|
48648
|
+
logout,
|
|
48649
|
+
verifyPassword
|
|
48591
48650
|
};
|
|
48592
48651
|
}
|
|
48593
48652
|
|
|
@@ -48803,7 +48862,11 @@ function useUserServiceV2() {
|
|
|
48803
48862
|
// src/controllers/auth-v2.controller.ts
|
|
48804
48863
|
function useAuthControllerV2() {
|
|
48805
48864
|
const { signUp: _signUp } = useVerificationServiceV2();
|
|
48806
|
-
const {
|
|
48865
|
+
const {
|
|
48866
|
+
login: _login,
|
|
48867
|
+
logout: _logout,
|
|
48868
|
+
verifyPassword: _verifyPassword
|
|
48869
|
+
} = useAuthServiceV2();
|
|
48807
48870
|
const { resetPassword: _resetPassword } = useUserServiceV2();
|
|
48808
48871
|
async function signUp(req, res, next) {
|
|
48809
48872
|
try {
|
|
@@ -48917,11 +48980,38 @@ function useAuthControllerV2() {
|
|
|
48917
48980
|
return;
|
|
48918
48981
|
}
|
|
48919
48982
|
}
|
|
48983
|
+
async function verifyPassword(req, res, next) {
|
|
48984
|
+
const schema2 = Joi127.object({
|
|
48985
|
+
_id: Joi127.string().hex().required(),
|
|
48986
|
+
password: Joi127.string().required().min(8)
|
|
48987
|
+
});
|
|
48988
|
+
const { error, value } = schema2.validate(
|
|
48989
|
+
{ _id: req.params.id, ...req.body },
|
|
48990
|
+
{ abortEarly: false }
|
|
48991
|
+
);
|
|
48992
|
+
if (error) {
|
|
48993
|
+
const messages = error.details.map((d) => d.message);
|
|
48994
|
+
logger180.log({ level: "error", message: messages.join(", ") });
|
|
48995
|
+
next(new BadRequestError201(messages.join(", ")));
|
|
48996
|
+
return;
|
|
48997
|
+
}
|
|
48998
|
+
const { _id, password } = value;
|
|
48999
|
+
try {
|
|
49000
|
+
const message = await _verifyPassword(_id, password);
|
|
49001
|
+
res.json({ message });
|
|
49002
|
+
return;
|
|
49003
|
+
} catch (error2) {
|
|
49004
|
+
logger180.log({ level: "error", message: error2.message });
|
|
49005
|
+
next(error2);
|
|
49006
|
+
return;
|
|
49007
|
+
}
|
|
49008
|
+
}
|
|
48920
49009
|
return {
|
|
48921
49010
|
signUp,
|
|
48922
49011
|
login,
|
|
48923
49012
|
logout,
|
|
48924
|
-
resetPassword
|
|
49013
|
+
resetPassword,
|
|
49014
|
+
verifyPassword
|
|
48925
49015
|
};
|
|
48926
49016
|
}
|
|
48927
49017
|
|