@7365admin1/core 2.34.0 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +117 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -66
- 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
|
|
@@ -2210,20 +2211,9 @@ function useUserRepo() {
|
|
|
2210
2211
|
}
|
|
2211
2212
|
async function getUserByEmail(email) {
|
|
2212
2213
|
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
2214
|
const data = await collection.findOne({
|
|
2220
2215
|
email: { $regex: `^${email}$`, $options: "i" }
|
|
2221
2216
|
});
|
|
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
2217
|
return data;
|
|
2228
2218
|
} catch (error) {
|
|
2229
2219
|
throw new InternalServerError5("Failed to get user by email.");
|
|
@@ -2530,6 +2520,39 @@ function useUserRepo() {
|
|
|
2530
2520
|
throw new InternalServerError5("Failed to update user password.");
|
|
2531
2521
|
}
|
|
2532
2522
|
}
|
|
2523
|
+
async function resetPassword({
|
|
2524
|
+
_id,
|
|
2525
|
+
password,
|
|
2526
|
+
sid
|
|
2527
|
+
}, session) {
|
|
2528
|
+
try {
|
|
2529
|
+
_id = new ObjectId9(_id);
|
|
2530
|
+
} catch (error) {
|
|
2531
|
+
throw new BadRequestError9("Invalid user ID format.");
|
|
2532
|
+
}
|
|
2533
|
+
try {
|
|
2534
|
+
const result = await collection.updateOne(
|
|
2535
|
+
{ _id },
|
|
2536
|
+
{ $set: { password, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
2537
|
+
{ session }
|
|
2538
|
+
);
|
|
2539
|
+
const cacheKey = makeCacheKey5(namespace_collection, { _id });
|
|
2540
|
+
delCache(cacheKey).then(() => {
|
|
2541
|
+
logger7.info(`Cache deleted for key: ${cacheKey}`);
|
|
2542
|
+
}).catch((err) => {
|
|
2543
|
+
logger7.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
2544
|
+
});
|
|
2545
|
+
const authCacheKey = `sid:${sid}`;
|
|
2546
|
+
delCache(authCacheKey).then(() => {
|
|
2547
|
+
logger7.info(`Cache deleted for key: ${authCacheKey}`);
|
|
2548
|
+
}).catch((err) => {
|
|
2549
|
+
logger7.error(`Failed to delete cache for key: ${authCacheKey}`, err);
|
|
2550
|
+
});
|
|
2551
|
+
return result;
|
|
2552
|
+
} catch (error) {
|
|
2553
|
+
throw new InternalServerError5("Failed to update user password.");
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2533
2556
|
async function updateBirthday({
|
|
2534
2557
|
_id,
|
|
2535
2558
|
month,
|
|
@@ -2622,6 +2645,19 @@ function useUserRepo() {
|
|
|
2622
2645
|
throw new InternalServerError5(`Failed to update user ${field}.`);
|
|
2623
2646
|
}
|
|
2624
2647
|
}
|
|
2648
|
+
async function updateUserSIDById(id, sid, session) {
|
|
2649
|
+
const _id = toObjectId(id);
|
|
2650
|
+
try {
|
|
2651
|
+
const result = await collection.updateOne(
|
|
2652
|
+
{ _id },
|
|
2653
|
+
{ $set: { sid, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
2654
|
+
{ session }
|
|
2655
|
+
);
|
|
2656
|
+
return result;
|
|
2657
|
+
} catch (error) {
|
|
2658
|
+
throw new InternalServerError5("Failed to update user.");
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2625
2661
|
return {
|
|
2626
2662
|
createIndex,
|
|
2627
2663
|
createTextIndex,
|
|
@@ -2637,7 +2673,9 @@ function useUserRepo() {
|
|
|
2637
2673
|
updateBirthday,
|
|
2638
2674
|
updateUserFieldById,
|
|
2639
2675
|
updateDefaultOrgByEmail,
|
|
2640
|
-
getUserByEmailStatus
|
|
2676
|
+
getUserByEmailStatus,
|
|
2677
|
+
updateUserSIDById,
|
|
2678
|
+
resetPassword
|
|
2641
2679
|
};
|
|
2642
2680
|
}
|
|
2643
2681
|
|
|
@@ -3482,7 +3520,11 @@ function useMemberRepo() {
|
|
|
3482
3520
|
|
|
3483
3521
|
// src/services/auth.service.ts
|
|
3484
3522
|
function useAuthService() {
|
|
3485
|
-
const {
|
|
3523
|
+
const {
|
|
3524
|
+
getUserByEmail,
|
|
3525
|
+
getUserById: _getUserById,
|
|
3526
|
+
updateUserSIDById: _updateUserSIDById
|
|
3527
|
+
} = useUserRepo();
|
|
3486
3528
|
const { getByToken, deleteByToken } = useSessionRepo();
|
|
3487
3529
|
const expiresIn = "15m";
|
|
3488
3530
|
const { setCache, delCache } = useCache7("sessions");
|
|
@@ -3520,7 +3562,9 @@ function useAuthService() {
|
|
|
3520
3562
|
}
|
|
3521
3563
|
const sid = uuidv4();
|
|
3522
3564
|
const cacheKey = `sid:${sid}`;
|
|
3523
|
-
|
|
3565
|
+
await _updateUserSIDById(user._id, sid);
|
|
3566
|
+
const updatedUser = await _getUserById(user._id);
|
|
3567
|
+
setCache(cacheKey, updatedUser, 14400).then(() => {
|
|
3524
3568
|
console.log("Session ID cached successfully");
|
|
3525
3569
|
}).catch((error) => {
|
|
3526
3570
|
console.error("Error caching session ID:", error);
|
|
@@ -4351,7 +4395,7 @@ import {
|
|
|
4351
4395
|
logger as logger12,
|
|
4352
4396
|
makeCacheKey as makeCacheKey9,
|
|
4353
4397
|
AppError as AppError4,
|
|
4354
|
-
toObjectId as
|
|
4398
|
+
toObjectId as toObjectId3
|
|
4355
4399
|
} from "@7365admin1/node-server-utils";
|
|
4356
4400
|
import Joi10 from "joi";
|
|
4357
4401
|
function useSiteRepo() {
|
|
@@ -4737,7 +4781,7 @@ function useSiteRepo() {
|
|
|
4737
4781
|
}
|
|
4738
4782
|
}
|
|
4739
4783
|
async function updateSiteById(id, payload, session) {
|
|
4740
|
-
const _id =
|
|
4784
|
+
const _id = toObjectId3(id);
|
|
4741
4785
|
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4742
4786
|
try {
|
|
4743
4787
|
const res = await collection.updateOne(
|
|
@@ -5751,7 +5795,8 @@ function useUserService() {
|
|
|
5751
5795
|
getUserById,
|
|
5752
5796
|
getUserByEmail,
|
|
5753
5797
|
updatePassword,
|
|
5754
|
-
updateUserFieldById: _updateUserFieldById
|
|
5798
|
+
updateUserFieldById: _updateUserFieldById,
|
|
5799
|
+
resetPassword: _resetPassword
|
|
5755
5800
|
} = useUserRepo();
|
|
5756
5801
|
const { getRoleByName, addRole } = useRoleRepo();
|
|
5757
5802
|
const { add: addMember } = useMemberRepo();
|
|
@@ -5927,8 +5972,12 @@ function useUserService() {
|
|
|
5927
5972
|
throw new InternalServerError14("Invalid user ID.");
|
|
5928
5973
|
}
|
|
5929
5974
|
await updateStatusById(id, "complete", session);
|
|
5930
|
-
await
|
|
5931
|
-
{
|
|
5975
|
+
await _resetPassword(
|
|
5976
|
+
{
|
|
5977
|
+
_id: user._id.toString(),
|
|
5978
|
+
password: hashedPassword,
|
|
5979
|
+
sid: user.sid
|
|
5980
|
+
},
|
|
5932
5981
|
session
|
|
5933
5982
|
);
|
|
5934
5983
|
await session?.commitTransaction();
|
|
@@ -8652,7 +8701,7 @@ import {
|
|
|
8652
8701
|
import { z } from "zod";
|
|
8653
8702
|
import { ObjectId as ObjectId26 } from "mongodb";
|
|
8654
8703
|
import { BadRequestError as BadRequestError39 } from "@7365admin1/node-server-utils";
|
|
8655
|
-
function
|
|
8704
|
+
function toObjectId4(value) {
|
|
8656
8705
|
if (typeof value === "string") {
|
|
8657
8706
|
if (!/^[a-fA-F0-9]{24}$/.test(value)) {
|
|
8658
8707
|
throw new BadRequestError39(`Invalid ObjectId format: ${value}`);
|
|
@@ -8704,7 +8753,7 @@ var TInvoice = z.object({
|
|
|
8704
8753
|
message: "Invalid ObjectId: Must be a 24-character hex string."
|
|
8705
8754
|
}),
|
|
8706
8755
|
z.instanceof(ObjectId26, { message: "Invalid ObjectId instance." })
|
|
8707
|
-
]).optional().transform((val) => val ?
|
|
8756
|
+
]).optional().transform((val) => val ? toObjectId4(val) : void 0),
|
|
8708
8757
|
invoiceNumber: z.string({ required_error: "Invoice number is required." }),
|
|
8709
8758
|
type: TInvoiceType.default("other"),
|
|
8710
8759
|
amount: z.number().min(0, { message: "Invoice amount must be at least 0." }),
|
|
@@ -12457,7 +12506,7 @@ import {
|
|
|
12457
12506
|
logger as logger46,
|
|
12458
12507
|
makeCacheKey as makeCacheKey21,
|
|
12459
12508
|
paginate as paginate16,
|
|
12460
|
-
toObjectId as
|
|
12509
|
+
toObjectId as toObjectId6,
|
|
12461
12510
|
useAtlas as useAtlas29,
|
|
12462
12511
|
useCache as useCache22
|
|
12463
12512
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12685,7 +12734,7 @@ function useSiteCameraRepo() {
|
|
|
12685
12734
|
});
|
|
12686
12735
|
}
|
|
12687
12736
|
async function getBySite(site, options = {}) {
|
|
12688
|
-
const _site =
|
|
12737
|
+
const _site = toObjectId6(site);
|
|
12689
12738
|
const cacheKeyOptions = {
|
|
12690
12739
|
site,
|
|
12691
12740
|
tag: "get-by-site",
|
|
@@ -12919,7 +12968,7 @@ import {
|
|
|
12919
12968
|
BadRequestError as BadRequestError66,
|
|
12920
12969
|
InternalServerError as InternalServerError23,
|
|
12921
12970
|
paginate as paginate17,
|
|
12922
|
-
toObjectId as
|
|
12971
|
+
toObjectId as toObjectId7,
|
|
12923
12972
|
useAtlas as useAtlas30
|
|
12924
12973
|
} from "@7365admin1/node-server-utils";
|
|
12925
12974
|
|
|
@@ -13561,7 +13610,7 @@ function useVisitorTransactionRepo() {
|
|
|
13561
13610
|
}
|
|
13562
13611
|
}
|
|
13563
13612
|
async function getVisitorTransactionById(id) {
|
|
13564
|
-
const _id =
|
|
13613
|
+
const _id = toObjectId7(id);
|
|
13565
13614
|
try {
|
|
13566
13615
|
const basePipeline = [{ $match: { _id } }];
|
|
13567
13616
|
const [result] = await collection.aggregate([
|
|
@@ -13603,7 +13652,7 @@ function useVisitorTransactionRepo() {
|
|
|
13603
13652
|
}
|
|
13604
13653
|
}
|
|
13605
13654
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
13606
|
-
const _site = typeof site === "string" ?
|
|
13655
|
+
const _site = typeof site === "string" ? toObjectId7(site) : site;
|
|
13607
13656
|
const query = {
|
|
13608
13657
|
plateNumber,
|
|
13609
13658
|
site: _site,
|
|
@@ -13687,7 +13736,7 @@ function useVisitorTransactionRepo() {
|
|
|
13687
13736
|
}
|
|
13688
13737
|
}
|
|
13689
13738
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
13690
|
-
const site =
|
|
13739
|
+
const site = toObjectId7(siteId);
|
|
13691
13740
|
try {
|
|
13692
13741
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13693
13742
|
const expiredTransactions = await collection.find({
|
|
@@ -13936,7 +13985,7 @@ import {
|
|
|
13936
13985
|
logger as logger49,
|
|
13937
13986
|
NotFoundError as NotFoundError17,
|
|
13938
13987
|
paginate as paginate18,
|
|
13939
|
-
toObjectId as
|
|
13988
|
+
toObjectId as toObjectId8,
|
|
13940
13989
|
useAtlas as useAtlas31
|
|
13941
13990
|
} from "@7365admin1/node-server-utils";
|
|
13942
13991
|
import { ObjectId as ObjectId42 } from "mongodb";
|
|
@@ -14535,7 +14584,7 @@ function useVehicleRepo() {
|
|
|
14535
14584
|
page = page > 0 ? page - 1 : 0;
|
|
14536
14585
|
const skip = page * limit;
|
|
14537
14586
|
try {
|
|
14538
|
-
const unit =
|
|
14587
|
+
const unit = toObjectId8(unitId);
|
|
14539
14588
|
const query = {
|
|
14540
14589
|
unit
|
|
14541
14590
|
};
|
|
@@ -14604,7 +14653,7 @@ import {
|
|
|
14604
14653
|
useAtlas as useAtlas32,
|
|
14605
14654
|
useCache as useCache25,
|
|
14606
14655
|
AppError as AppError10,
|
|
14607
|
-
toObjectId as
|
|
14656
|
+
toObjectId as toObjectId9
|
|
14608
14657
|
} from "@7365admin1/node-server-utils";
|
|
14609
14658
|
import { ObjectId as ObjectId43 } from "mongodb";
|
|
14610
14659
|
var site_people_namespace_collection = "site.people";
|
|
@@ -15085,7 +15134,7 @@ function usePersonRepo() {
|
|
|
15085
15134
|
async function pushVehicleById(id, plate, session) {
|
|
15086
15135
|
const { plateNumber, recNo } = plate;
|
|
15087
15136
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15088
|
-
const _id =
|
|
15137
|
+
const _id = toObjectId9(id);
|
|
15089
15138
|
try {
|
|
15090
15139
|
const updateExisting = await collection.updateOne(
|
|
15091
15140
|
{
|
|
@@ -15143,7 +15192,7 @@ function usePersonRepo() {
|
|
|
15143
15192
|
}
|
|
15144
15193
|
}
|
|
15145
15194
|
async function getByUserId(userId) {
|
|
15146
|
-
const user =
|
|
15195
|
+
const user = toObjectId9(userId);
|
|
15147
15196
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
15148
15197
|
user: userId
|
|
15149
15198
|
});
|
|
@@ -17415,7 +17464,7 @@ import {
|
|
|
17415
17464
|
logger as logger60,
|
|
17416
17465
|
makeCacheKey as makeCacheKey26,
|
|
17417
17466
|
paginate as paginate21,
|
|
17418
|
-
toObjectId as
|
|
17467
|
+
toObjectId as toObjectId11,
|
|
17419
17468
|
useAtlas as useAtlas37,
|
|
17420
17469
|
useCache as useCache28
|
|
17421
17470
|
} from "@7365admin1/node-server-utils";
|
|
@@ -17580,8 +17629,8 @@ function useBuildingUnitRepo() {
|
|
|
17580
17629
|
const query = {
|
|
17581
17630
|
status,
|
|
17582
17631
|
...search && { $text: { $search: search } },
|
|
17583
|
-
...site && { site:
|
|
17584
|
-
...building && { building:
|
|
17632
|
+
...site && { site: toObjectId11(site) },
|
|
17633
|
+
...building && { building: toObjectId11(building) }
|
|
17585
17634
|
};
|
|
17586
17635
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17587
17636
|
const cacheParams = {
|
|
@@ -27215,7 +27264,7 @@ import {
|
|
|
27215
27264
|
makeCacheKey as makeCacheKey37,
|
|
27216
27265
|
NotFoundError as NotFoundError27,
|
|
27217
27266
|
paginate as paginate31,
|
|
27218
|
-
toObjectId as
|
|
27267
|
+
toObjectId as toObjectId12,
|
|
27219
27268
|
useAtlas as useAtlas61,
|
|
27220
27269
|
useCache as useCache39
|
|
27221
27270
|
} from "@7365admin1/node-server-utils";
|
|
@@ -27271,7 +27320,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
27271
27320
|
page = page > 0 ? page - 1 : 0;
|
|
27272
27321
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
27273
27322
|
const skip = page * limit;
|
|
27274
|
-
const siteId =
|
|
27323
|
+
const siteId = toObjectId12(site);
|
|
27275
27324
|
const query = {
|
|
27276
27325
|
site: siteId,
|
|
27277
27326
|
status,
|
|
@@ -27317,7 +27366,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
27317
27366
|
}
|
|
27318
27367
|
}
|
|
27319
27368
|
async function getSiteFacilityBookingById(id, session) {
|
|
27320
|
-
const _id =
|
|
27369
|
+
const _id = toObjectId12(id);
|
|
27321
27370
|
const cacheKey = makeCacheKey37(facility_bookings_namespace_collection, {
|
|
27322
27371
|
id
|
|
27323
27372
|
});
|
|
@@ -27343,17 +27392,17 @@ function useSiteFacilityBookingRepo() {
|
|
|
27343
27392
|
}
|
|
27344
27393
|
async function updateSiteFacilityBookingById(id, value, session) {
|
|
27345
27394
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
27346
|
-
const _id =
|
|
27395
|
+
const _id = toObjectId12(id);
|
|
27347
27396
|
if (value.site)
|
|
27348
|
-
value.site = typeof value.site === "string" ?
|
|
27397
|
+
value.site = typeof value.site === "string" ? toObjectId12(value.site) : value.site;
|
|
27349
27398
|
if (value.user)
|
|
27350
|
-
value.user = typeof value.user === "string" ?
|
|
27399
|
+
value.user = typeof value.user === "string" ? toObjectId12(value.user) : value.user;
|
|
27351
27400
|
if (value.date)
|
|
27352
27401
|
value.date = value.date ? new Date(value.date).toISOString() : value.date;
|
|
27353
27402
|
if (value.approvedBy)
|
|
27354
|
-
value.approvedBy = typeof value.approvedBy === "string" ?
|
|
27403
|
+
value.approvedBy = typeof value.approvedBy === "string" ? toObjectId12(value.approvedBy) : value.approvedBy;
|
|
27355
27404
|
if (value.createdBy)
|
|
27356
|
-
value.createdBy = typeof value.createdBy === "string" ?
|
|
27405
|
+
value.createdBy = typeof value.createdBy === "string" ? toObjectId12(value.createdBy) : value.createdBy;
|
|
27357
27406
|
try {
|
|
27358
27407
|
const res = await collection.updateOne(
|
|
27359
27408
|
{ _id },
|
|
@@ -35636,7 +35685,7 @@ import {
|
|
|
35636
35685
|
makeCacheKey as makeCacheKey46,
|
|
35637
35686
|
NotFoundError as NotFoundError37,
|
|
35638
35687
|
paginate as paginate40,
|
|
35639
|
-
toObjectId as
|
|
35688
|
+
toObjectId as toObjectId13,
|
|
35640
35689
|
useAtlas as useAtlas78,
|
|
35641
35690
|
useCache as useCache48
|
|
35642
35691
|
} from "@7365admin1/node-server-utils";
|
|
@@ -35711,7 +35760,7 @@ function useOccurrenceBookRepo() {
|
|
|
35711
35760
|
status = ""
|
|
35712
35761
|
}, session) {
|
|
35713
35762
|
page = page > 0 && !date ? page - 1 : 0;
|
|
35714
|
-
const _site =
|
|
35763
|
+
const _site = toObjectId13(site);
|
|
35715
35764
|
const query = {
|
|
35716
35765
|
site: _site,
|
|
35717
35766
|
...status && { status },
|
|
@@ -42173,7 +42222,7 @@ import {
|
|
|
42173
42222
|
InternalServerError as InternalServerError59,
|
|
42174
42223
|
logger as logger155,
|
|
42175
42224
|
makeCacheKey as makeCacheKey57,
|
|
42176
|
-
toObjectId as
|
|
42225
|
+
toObjectId as toObjectId14,
|
|
42177
42226
|
useAtlas as useAtlas98,
|
|
42178
42227
|
useCache as useCache59
|
|
42179
42228
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42265,7 +42314,7 @@ function useNewDashboardRepo() {
|
|
|
42265
42314
|
securityDashboardCollection
|
|
42266
42315
|
);
|
|
42267
42316
|
async function getMetric(collectionString, siteId, period) {
|
|
42268
|
-
const site =
|
|
42317
|
+
const site = toObjectId14(siteId);
|
|
42269
42318
|
const range = getPeriodRangeWithPrevious(period);
|
|
42270
42319
|
const collection = db.collection(collectionString);
|
|
42271
42320
|
const current = await collection.countDocuments({
|
|
@@ -44243,7 +44292,7 @@ import {
|
|
|
44243
44292
|
InternalServerError as InternalServerError63,
|
|
44244
44293
|
logger as logger163,
|
|
44245
44294
|
makeCacheKey as makeCacheKey61,
|
|
44246
|
-
toObjectId as
|
|
44295
|
+
toObjectId as toObjectId15,
|
|
44247
44296
|
useAtlas as useAtlas103,
|
|
44248
44297
|
useCache as useCache63
|
|
44249
44298
|
} from "@7365admin1/node-server-utils";
|
|
@@ -44322,7 +44371,7 @@ function useOvernightParkingRepo() {
|
|
|
44322
44371
|
}
|
|
44323
44372
|
}
|
|
44324
44373
|
async function getSiteOvernightParking(site) {
|
|
44325
|
-
const siteId =
|
|
44374
|
+
const siteId = toObjectId15(site);
|
|
44326
44375
|
const cacheKey = makeCacheKey61(overnight_parking_namespace_collection, {
|
|
44327
44376
|
site
|
|
44328
44377
|
});
|
|
@@ -44418,7 +44467,7 @@ function useOvernightParkingController() {
|
|
|
44418
44467
|
|
|
44419
44468
|
// src/models/overnight-parking-request.model.ts
|
|
44420
44469
|
import Joi118 from "joi";
|
|
44421
|
-
import { toObjectId as
|
|
44470
|
+
import { toObjectId as toObjectId16 } from "@7365admin1/node-server-utils";
|
|
44422
44471
|
var OvernightParkingRequestStatus = /* @__PURE__ */ ((OvernightParkingRequestStatus2) => {
|
|
44423
44472
|
OvernightParkingRequestStatus2["PENDING"] = "pending";
|
|
44424
44473
|
OvernightParkingRequestStatus2["APPROVED"] = "approved";
|
|
@@ -44455,7 +44504,7 @@ function MOvernightParkingRequest(value) {
|
|
|
44455
44504
|
throw new Error(error.details[0].message);
|
|
44456
44505
|
}
|
|
44457
44506
|
if (value.site && typeof value.site === "string")
|
|
44458
|
-
value.site =
|
|
44507
|
+
value.site = toObjectId16(value.site);
|
|
44459
44508
|
const data = {
|
|
44460
44509
|
...value,
|
|
44461
44510
|
createdAt: value.createdAt ? new Date(value.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -44472,7 +44521,7 @@ import {
|
|
|
44472
44521
|
logger as logger165,
|
|
44473
44522
|
makeCacheKey as makeCacheKey62,
|
|
44474
44523
|
paginate as paginate54,
|
|
44475
|
-
toObjectId as
|
|
44524
|
+
toObjectId as toObjectId17,
|
|
44476
44525
|
useAtlas as useAtlas104,
|
|
44477
44526
|
useCache as useCache64
|
|
44478
44527
|
} from "@7365admin1/node-server-utils";
|
|
@@ -44540,7 +44589,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44540
44589
|
}) {
|
|
44541
44590
|
page = page ? page - 1 : 0;
|
|
44542
44591
|
const skip = page * limit;
|
|
44543
|
-
const siteId =
|
|
44592
|
+
const siteId = toObjectId17(site);
|
|
44544
44593
|
const query = {
|
|
44545
44594
|
site: siteId,
|
|
44546
44595
|
...status && { status }
|
|
@@ -44591,7 +44640,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44591
44640
|
logger165.info(`Cache hit for key: ${cacheKey}`);
|
|
44592
44641
|
return cachedData;
|
|
44593
44642
|
}
|
|
44594
|
-
const _id =
|
|
44643
|
+
const _id = toObjectId17(id);
|
|
44595
44644
|
const data = await collection.findOne({ _id });
|
|
44596
44645
|
if (!data)
|
|
44597
44646
|
throw new BadRequestError188("Overnight parking request not found.");
|
|
@@ -44607,7 +44656,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44607
44656
|
}
|
|
44608
44657
|
async function updateOvernightParkingRequestById(id, value, session) {
|
|
44609
44658
|
try {
|
|
44610
|
-
const _id =
|
|
44659
|
+
const _id = toObjectId17(id);
|
|
44611
44660
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
44612
44661
|
const data = await collection.updateOne(
|
|
44613
44662
|
{ _id },
|
|
@@ -44633,7 +44682,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44633
44682
|
}
|
|
44634
44683
|
async function deleteOvernightParkingRequestById(id, session) {
|
|
44635
44684
|
try {
|
|
44636
|
-
const _id =
|
|
44685
|
+
const _id = toObjectId17(id);
|
|
44637
44686
|
const value = {
|
|
44638
44687
|
deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
44639
44688
|
status: "deleted" /* DELETED */
|
|
@@ -44662,7 +44711,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
44662
44711
|
}
|
|
44663
44712
|
async function updateExpiredRequests(site, session) {
|
|
44664
44713
|
try {
|
|
44665
|
-
const _site =
|
|
44714
|
+
const _site = toObjectId17(site);
|
|
44666
44715
|
const value = {
|
|
44667
44716
|
status: "expired" /* EXPIRED */
|
|
44668
44717
|
};
|
|
@@ -47260,7 +47309,7 @@ import {
|
|
|
47260
47309
|
logger as logger175,
|
|
47261
47310
|
makeCacheKey as makeCacheKey64,
|
|
47262
47311
|
paginate as paginate57,
|
|
47263
|
-
toObjectId as
|
|
47312
|
+
toObjectId as toObjectId18,
|
|
47264
47313
|
useAtlas as useAtlas112,
|
|
47265
47314
|
useCache as useCache66
|
|
47266
47315
|
} from "@7365admin1/node-server-utils";
|
|
@@ -47367,7 +47416,7 @@ function useVerificationRepoV2() {
|
|
|
47367
47416
|
}
|
|
47368
47417
|
async function getVerificationById(id) {
|
|
47369
47418
|
try {
|
|
47370
|
-
const _id =
|
|
47419
|
+
const _id = toObjectId18(id);
|
|
47371
47420
|
const cacheKey = makeCacheKey64(namespace_collection, { id });
|
|
47372
47421
|
const cachedData = await getCache(cacheKey);
|
|
47373
47422
|
if (cachedData) {
|
|
@@ -48073,7 +48122,7 @@ import {
|
|
|
48073
48122
|
AppError as AppError27,
|
|
48074
48123
|
useCache as useCache67,
|
|
48075
48124
|
makeCacheKey as makeCacheKey65,
|
|
48076
|
-
toObjectId as
|
|
48125
|
+
toObjectId as toObjectId19
|
|
48077
48126
|
} from "@7365admin1/node-server-utils";
|
|
48078
48127
|
function useUserRepoV2() {
|
|
48079
48128
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
@@ -48174,7 +48223,7 @@ function useUserRepoV2() {
|
|
|
48174
48223
|
}
|
|
48175
48224
|
}
|
|
48176
48225
|
async function getUserById(id) {
|
|
48177
|
-
const _id =
|
|
48226
|
+
const _id = toObjectId19(id);
|
|
48178
48227
|
try {
|
|
48179
48228
|
const cacheKey = makeCacheKey65(namespace_collection, { id });
|
|
48180
48229
|
const cachedData = await getCache(cacheKey);
|
|
@@ -48379,7 +48428,7 @@ function useUserRepoV2() {
|
|
|
48379
48428
|
}
|
|
48380
48429
|
async function updatePasswordById({ _id, password }, session) {
|
|
48381
48430
|
const cacheKey = makeCacheKey65(namespace_collection, { _id });
|
|
48382
|
-
_id =
|
|
48431
|
+
_id = toObjectId19(_id);
|
|
48383
48432
|
try {
|
|
48384
48433
|
const result = await collection.updateOne(
|
|
48385
48434
|
{ _id },
|
|
@@ -48585,9 +48634,25 @@ function useAuthServiceV2() {
|
|
|
48585
48634
|
throw new InternalServerError71("Error deleting token");
|
|
48586
48635
|
}
|
|
48587
48636
|
}
|
|
48637
|
+
async function verifyPassword(_id, password) {
|
|
48638
|
+
try {
|
|
48639
|
+
const user = await _getUserById(_id);
|
|
48640
|
+
const isPasswordMatch = await comparePassword3(password, user.password);
|
|
48641
|
+
if (!isPasswordMatch) {
|
|
48642
|
+
throw new BadRequestError199("Invalid credentials");
|
|
48643
|
+
}
|
|
48644
|
+
return "Verification successful.";
|
|
48645
|
+
} catch (error) {
|
|
48646
|
+
if (error instanceof BadRequestError199) {
|
|
48647
|
+
throw error;
|
|
48648
|
+
}
|
|
48649
|
+
throw new InternalServerError71("Error during password verification");
|
|
48650
|
+
}
|
|
48651
|
+
}
|
|
48588
48652
|
return {
|
|
48589
48653
|
login,
|
|
48590
|
-
logout
|
|
48654
|
+
logout,
|
|
48655
|
+
verifyPassword
|
|
48591
48656
|
};
|
|
48592
48657
|
}
|
|
48593
48658
|
|
|
@@ -48803,7 +48868,11 @@ function useUserServiceV2() {
|
|
|
48803
48868
|
// src/controllers/auth-v2.controller.ts
|
|
48804
48869
|
function useAuthControllerV2() {
|
|
48805
48870
|
const { signUp: _signUp } = useVerificationServiceV2();
|
|
48806
|
-
const {
|
|
48871
|
+
const {
|
|
48872
|
+
login: _login,
|
|
48873
|
+
logout: _logout,
|
|
48874
|
+
verifyPassword: _verifyPassword
|
|
48875
|
+
} = useAuthServiceV2();
|
|
48807
48876
|
const { resetPassword: _resetPassword } = useUserServiceV2();
|
|
48808
48877
|
async function signUp(req, res, next) {
|
|
48809
48878
|
try {
|
|
@@ -48917,11 +48986,38 @@ function useAuthControllerV2() {
|
|
|
48917
48986
|
return;
|
|
48918
48987
|
}
|
|
48919
48988
|
}
|
|
48989
|
+
async function verifyPassword(req, res, next) {
|
|
48990
|
+
const schema2 = Joi127.object({
|
|
48991
|
+
_id: Joi127.string().hex().required(),
|
|
48992
|
+
password: Joi127.string().required().min(8)
|
|
48993
|
+
});
|
|
48994
|
+
const { error, value } = schema2.validate(
|
|
48995
|
+
{ _id: req.params.id, ...req.body },
|
|
48996
|
+
{ abortEarly: false }
|
|
48997
|
+
);
|
|
48998
|
+
if (error) {
|
|
48999
|
+
const messages = error.details.map((d) => d.message);
|
|
49000
|
+
logger180.log({ level: "error", message: messages.join(", ") });
|
|
49001
|
+
next(new BadRequestError201(messages.join(", ")));
|
|
49002
|
+
return;
|
|
49003
|
+
}
|
|
49004
|
+
const { _id, password } = value;
|
|
49005
|
+
try {
|
|
49006
|
+
const message = await _verifyPassword(_id, password);
|
|
49007
|
+
res.json({ message });
|
|
49008
|
+
return;
|
|
49009
|
+
} catch (error2) {
|
|
49010
|
+
logger180.log({ level: "error", message: error2.message });
|
|
49011
|
+
next(error2);
|
|
49012
|
+
return;
|
|
49013
|
+
}
|
|
49014
|
+
}
|
|
48920
49015
|
return {
|
|
48921
49016
|
signUp,
|
|
48922
49017
|
login,
|
|
48923
49018
|
logout,
|
|
48924
|
-
resetPassword
|
|
49019
|
+
resetPassword,
|
|
49020
|
+
verifyPassword
|
|
48925
49021
|
};
|
|
48926
49022
|
}
|
|
48927
49023
|
|