@7365admin1/core 3.53.3 → 3.53.5
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 +26 -0
- package/dist/index.d.ts +197 -1
- package/dist/index.js +519 -477
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +219 -185
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/invite-org-scope.test.mjs +7 -1
- package/test/role-member-org-scope.test.mjs +4 -1
- package/test/sp-approvals-console-gate.test.mjs +117 -0
- package/test/staff-bypass-tenant-scope.test.mjs +38 -0
package/dist/index.js
CHANGED
|
@@ -5926,7 +5926,9 @@ __export(src_exports, {
|
|
|
5926
5926
|
CLIENT_ACTIONS: () => CLIENT_ACTIONS,
|
|
5927
5927
|
CLOCK_DRIFT_WARN_SECONDS: () => CLOCK_DRIFT_WARN_SECONDS,
|
|
5928
5928
|
CONSOLE_AUDIT_LABELS: () => CONSOLE_AUDIT_LABELS,
|
|
5929
|
+
CONSOLE_PERMISSIONS: () => CONSOLE_PERMISSIONS,
|
|
5929
5930
|
CONTRACTOR_TYPE_LABELS: () => CONTRACTOR_TYPE_LABELS,
|
|
5931
|
+
CROSS_CLIENT_GRANT: () => CROSS_CLIENT_GRANT,
|
|
5930
5932
|
CURRENT_TIME_ENDPOINT: () => CURRENT_TIME_ENDPOINT,
|
|
5931
5933
|
CameraType: () => CameraType,
|
|
5932
5934
|
ConsoleAuditAction: () => ConsoleAuditAction,
|
|
@@ -6138,6 +6140,9 @@ __export(src_exports, {
|
|
|
6138
6140
|
chatSchema: () => chatSchema,
|
|
6139
6141
|
clampPtzSpeed: () => clampPtzSpeed,
|
|
6140
6142
|
clockDriftSeconds: () => clockDriftSeconds,
|
|
6143
|
+
consoleRoleAllows: () => consoleRoleAllows,
|
|
6144
|
+
consoleRoleAllowsAll: () => consoleRoleAllowsAll,
|
|
6145
|
+
consoleSpellings: () => consoleSpellings,
|
|
6141
6146
|
console_audit_namespace_collection: () => console_audit_namespace_collection,
|
|
6142
6147
|
createManpowerRemarksDaily: () => createManpowerRemarksDaily,
|
|
6143
6148
|
customerSchema: () => customerSchema,
|
|
@@ -6237,6 +6242,8 @@ __export(src_exports, {
|
|
|
6237
6242
|
relayForRecorder: () => relayForRecorder,
|
|
6238
6243
|
remarksSchema: () => remarksSchema,
|
|
6239
6244
|
renderPagePdf: () => renderPagePdf,
|
|
6245
|
+
requireConsolePermission: () => requireConsolePermission,
|
|
6246
|
+
requirePlatformStaff: () => requirePlatformStaff,
|
|
6240
6247
|
resetCameraTransports: () => resetCameraTransports,
|
|
6241
6248
|
residentAppModuleKeys: () => residentAppModuleKeys,
|
|
6242
6249
|
residentFormEntry: () => residentFormEntry,
|
|
@@ -6408,6 +6415,7 @@ __export(src_exports, {
|
|
|
6408
6415
|
site_people_namespace_collection: () => site_people_namespace_collection,
|
|
6409
6416
|
snapshotEndpoint: () => snapshotEndpoint,
|
|
6410
6417
|
snapshotRefusalReason: () => snapshotRefusalReason,
|
|
6418
|
+
staffMayBypass: () => staffMayBypass,
|
|
6411
6419
|
stringifyHidJson: () => stringifyHidJson,
|
|
6412
6420
|
stripFacialImageMetadata: () => stripFacialImageMetadata,
|
|
6413
6421
|
subscriptionPlanSchema: () => subscriptionPlanSchema,
|
|
@@ -11191,10 +11199,10 @@ function useAuthService() {
|
|
|
11191
11199
|
|
|
11192
11200
|
// src/controllers/auth.controller.ts
|
|
11193
11201
|
var import_joi16 = __toESM(require("joi"));
|
|
11194
|
-
var
|
|
11202
|
+
var import_node_server_utils40 = require("@7365admin1/node-server-utils");
|
|
11195
11203
|
|
|
11196
11204
|
// src/services/verification.service.ts
|
|
11197
|
-
var
|
|
11205
|
+
var import_node_server_utils35 = require("@7365admin1/node-server-utils");
|
|
11198
11206
|
|
|
11199
11207
|
// src/repositories/verification.repo.ts
|
|
11200
11208
|
var import_node_server_utils19 = require("@7365admin1/node-server-utils");
|
|
@@ -14077,9 +14085,13 @@ async function resolveInviteActor(userId) {
|
|
|
14077
14085
|
const members = await db2.collection("members").find({ user: new import_mongodb25.ObjectId(id), status: { $ne: "deleted" } }).toArray();
|
|
14078
14086
|
const adminMember = members.find((m) => m.type === "admin");
|
|
14079
14087
|
let isSuperAdmin2 = false;
|
|
14088
|
+
let staffPermissions;
|
|
14080
14089
|
if (adminMember?.role && import_mongodb25.ObjectId.isValid(adminMember.role.toString())) {
|
|
14081
14090
|
const role = await db2.collection("roles").findOne({ _id: new import_mongodb25.ObjectId(adminMember.role.toString()), ...LIVE_ROLE });
|
|
14082
14091
|
isSuperAdmin2 = role?.type === "admin";
|
|
14092
|
+
if (isSuperAdmin2) {
|
|
14093
|
+
staffPermissions = Array.isArray(role?.permissions) ? role?.permissions : [];
|
|
14094
|
+
}
|
|
14083
14095
|
}
|
|
14084
14096
|
const orgIds = Array.from(
|
|
14085
14097
|
new Set(
|
|
@@ -14102,6 +14114,7 @@ async function resolveInviteActor(userId) {
|
|
|
14102
14114
|
id,
|
|
14103
14115
|
name: user?.name ?? adminMember?.name ?? "",
|
|
14104
14116
|
isSuperAdmin: isSuperAdmin2,
|
|
14117
|
+
staffPermissions,
|
|
14105
14118
|
orgIds,
|
|
14106
14119
|
propertyManagementOrgIds,
|
|
14107
14120
|
memberships: members.map((m) => ({
|
|
@@ -14202,7 +14215,7 @@ async function holdsRole(userId, roleId) {
|
|
|
14202
14215
|
}
|
|
14203
14216
|
|
|
14204
14217
|
// src/services/service-provider-invite.service.ts
|
|
14205
|
-
var
|
|
14218
|
+
var import_node_server_utils34 = require("@7365admin1/node-server-utils");
|
|
14206
14219
|
var import_mongodb30 = require("mongodb");
|
|
14207
14220
|
|
|
14208
14221
|
// src/services/notification.service.ts
|
|
@@ -15421,10 +15434,173 @@ var NotificationService = class {
|
|
|
15421
15434
|
}
|
|
15422
15435
|
};
|
|
15423
15436
|
|
|
15437
|
+
// src/utils/console-authz.util.ts
|
|
15438
|
+
var import_node_server_utils33 = require("@7365admin1/node-server-utils");
|
|
15439
|
+
|
|
15440
|
+
// src/utils/console-permission.util.ts
|
|
15441
|
+
var CONSOLE_PERMISSIONS = Object.freeze({
|
|
15442
|
+
organizations: Object.freeze([
|
|
15443
|
+
"see-all-organizations",
|
|
15444
|
+
"see-organization-details"
|
|
15445
|
+
]),
|
|
15446
|
+
"promo-codes": Object.freeze([
|
|
15447
|
+
"create-promo-code",
|
|
15448
|
+
"see-promo-code-details",
|
|
15449
|
+
"edit-promo-code-details",
|
|
15450
|
+
"change-promo-code-status",
|
|
15451
|
+
"delete-promo-code"
|
|
15452
|
+
]),
|
|
15453
|
+
users: Object.freeze(["see-all-users", "see-user-details"]),
|
|
15454
|
+
invitations: Object.freeze([
|
|
15455
|
+
"create-invitation",
|
|
15456
|
+
"view-invitations",
|
|
15457
|
+
"cancel-invitation"
|
|
15458
|
+
]),
|
|
15459
|
+
subscriptions: Object.freeze([
|
|
15460
|
+
"see-all-subscriptions",
|
|
15461
|
+
"see-subscription-details",
|
|
15462
|
+
"manage-subscription"
|
|
15463
|
+
]),
|
|
15464
|
+
"sp-approvals": Object.freeze([
|
|
15465
|
+
"see-all-sp-approvals",
|
|
15466
|
+
"approve-sp",
|
|
15467
|
+
"reject-sp",
|
|
15468
|
+
"delete-sp-approval"
|
|
15469
|
+
]),
|
|
15470
|
+
"marketplace-vendors": Object.freeze([
|
|
15471
|
+
"see-all-marketplace-vendors",
|
|
15472
|
+
"see-marketplace-vendor-details"
|
|
15473
|
+
]),
|
|
15474
|
+
"platform-terms": Object.freeze([
|
|
15475
|
+
"see-platform-terms",
|
|
15476
|
+
"edit-platform-terms"
|
|
15477
|
+
]),
|
|
15478
|
+
"activity-history": Object.freeze(["see-activity-history"]),
|
|
15479
|
+
members: Object.freeze([
|
|
15480
|
+
"view-members",
|
|
15481
|
+
"assign-member-role",
|
|
15482
|
+
"suspend-member",
|
|
15483
|
+
"activate-member",
|
|
15484
|
+
"delete-member"
|
|
15485
|
+
]),
|
|
15486
|
+
"roles-and-permissions": Object.freeze([
|
|
15487
|
+
"add-role",
|
|
15488
|
+
"see-all-roles",
|
|
15489
|
+
"see-role-details",
|
|
15490
|
+
"update-role",
|
|
15491
|
+
"delete-role"
|
|
15492
|
+
])
|
|
15493
|
+
});
|
|
15494
|
+
var RESOURCE_SPELLINGS = Object.freeze({
|
|
15495
|
+
"roles-and-permissions": Object.freeze([
|
|
15496
|
+
"roles-and-permissions",
|
|
15497
|
+
"roles"
|
|
15498
|
+
]),
|
|
15499
|
+
roles: Object.freeze(["roles", "roles-and-permissions"])
|
|
15500
|
+
});
|
|
15501
|
+
function consoleSpellings(resource, action) {
|
|
15502
|
+
const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
|
|
15503
|
+
return resources.map((name) => `${name}:${action}`);
|
|
15504
|
+
}
|
|
15505
|
+
function consoleRoleAllowsAll(held) {
|
|
15506
|
+
if (!Array.isArray(held) || held.length === 0)
|
|
15507
|
+
return true;
|
|
15508
|
+
return held.includes("*");
|
|
15509
|
+
}
|
|
15510
|
+
function consoleRoleAllows(held, resource, action) {
|
|
15511
|
+
if (consoleRoleAllowsAll(held))
|
|
15512
|
+
return true;
|
|
15513
|
+
const actions = CONSOLE_PERMISSIONS[resource];
|
|
15514
|
+
if (!actions?.length)
|
|
15515
|
+
return false;
|
|
15516
|
+
const wanted = action ? actions.includes(action) ? [action] : [] : actions;
|
|
15517
|
+
return wanted.some(
|
|
15518
|
+
(name) => consoleSpellings(resource, name).some(
|
|
15519
|
+
(spelling) => held.includes(spelling)
|
|
15520
|
+
)
|
|
15521
|
+
);
|
|
15522
|
+
}
|
|
15523
|
+
var CROSS_CLIENT_GRANT = {
|
|
15524
|
+
resource: "organizations"
|
|
15525
|
+
};
|
|
15526
|
+
function staffMayBypass(actor, grant = CROSS_CLIENT_GRANT) {
|
|
15527
|
+
if (!actor.isSuperAdmin)
|
|
15528
|
+
return false;
|
|
15529
|
+
return consoleRoleAllows(actor.staffPermissions, grant.resource, grant.action);
|
|
15530
|
+
}
|
|
15531
|
+
|
|
15532
|
+
// src/utils/console-authz.util.ts
|
|
15533
|
+
function callerId(req) {
|
|
15534
|
+
const user = req.user;
|
|
15535
|
+
return user?.user?.toString?.() || user?._id?.toString?.() || "";
|
|
15536
|
+
}
|
|
15537
|
+
async function requirePlatformStaff(req, grant) {
|
|
15538
|
+
const id = callerId(req);
|
|
15539
|
+
const role = id ? await resolveStaffRole(id) : null;
|
|
15540
|
+
if (!role) {
|
|
15541
|
+
throw new import_node_server_utils33.UnauthorizedError("Not authorized.");
|
|
15542
|
+
}
|
|
15543
|
+
if (grant && !consoleRoleAllows(role.permissions, grant.resource, grant.action)) {
|
|
15544
|
+
throw new import_node_server_utils33.UnauthorizedError("Not authorized.");
|
|
15545
|
+
}
|
|
15546
|
+
return id;
|
|
15547
|
+
}
|
|
15548
|
+
async function requireConsolePermission(req, resource, action) {
|
|
15549
|
+
return await requirePlatformStaff(req, { resource, action });
|
|
15550
|
+
}
|
|
15551
|
+
async function requireSelfOrPlatformStaff(req, userId, grant) {
|
|
15552
|
+
const id = callerId(req);
|
|
15553
|
+
const target = userId?.toString() ?? "";
|
|
15554
|
+
if (id && target && target === id)
|
|
15555
|
+
return id;
|
|
15556
|
+
return await requirePlatformStaff(req, grant);
|
|
15557
|
+
}
|
|
15558
|
+
async function requireOrgAccess(req, orgId) {
|
|
15559
|
+
return await requireOrgReach(req, orgId);
|
|
15560
|
+
}
|
|
15561
|
+
async function requirePlatformOwner(req, grant) {
|
|
15562
|
+
const id = callerId(req);
|
|
15563
|
+
if (!id || !await isPlatformOwner(id)) {
|
|
15564
|
+
throw new import_node_server_utils33.UnauthorizedError("Not authorized.");
|
|
15565
|
+
}
|
|
15566
|
+
if (grant)
|
|
15567
|
+
await requirePlatformStaff(req, grant);
|
|
15568
|
+
return id;
|
|
15569
|
+
}
|
|
15570
|
+
async function requireOrgReach(req, orgId) {
|
|
15571
|
+
const id = callerId(req);
|
|
15572
|
+
if (!id)
|
|
15573
|
+
throw new import_node_server_utils33.UnauthorizedError("Not authorized.");
|
|
15574
|
+
const org = orgId?.toString() ?? "";
|
|
15575
|
+
const actor = await resolveInviteActor(id);
|
|
15576
|
+
if (staffMayBypass(actor))
|
|
15577
|
+
return id;
|
|
15578
|
+
if (org && actor.orgIds.includes(org))
|
|
15579
|
+
return id;
|
|
15580
|
+
if (org && await hasOrgInvitation(id, org))
|
|
15581
|
+
return id;
|
|
15582
|
+
if (org && await hasOrgOwnership(id, org))
|
|
15583
|
+
return id;
|
|
15584
|
+
throw new import_node_server_utils33.UnauthorizedError("Not authorized.");
|
|
15585
|
+
}
|
|
15586
|
+
async function requireInviteReach(req, org, app) {
|
|
15587
|
+
const apps = Array.isArray(app) ? app : [app];
|
|
15588
|
+
if (apps.some((a) => a === PLATFORM_STAFF_MEMBER_TYPE)) {
|
|
15589
|
+
await requirePlatformStaff(req);
|
|
15590
|
+
}
|
|
15591
|
+
if (org)
|
|
15592
|
+
await requireOrgReach(req, org);
|
|
15593
|
+
}
|
|
15594
|
+
async function requireUserFieldWrite(req, userId, field, grant) {
|
|
15595
|
+
if (field === "email")
|
|
15596
|
+
return await requirePlatformStaff(req, grant);
|
|
15597
|
+
return await requireSelfOrPlatformStaff(req, userId, grant);
|
|
15598
|
+
}
|
|
15599
|
+
|
|
15424
15600
|
// src/services/service-provider-invite.service.ts
|
|
15425
15601
|
var INVITE_VALID_HOURS = 72;
|
|
15426
15602
|
function useServiceProviderInviteService() {
|
|
15427
|
-
const mailer = new
|
|
15603
|
+
const mailer = new import_node_server_utils34.useMailer({
|
|
15428
15604
|
host: MAILER_TRANSPORT_HOST,
|
|
15429
15605
|
port: MAILER_TRANSPORT_PORT,
|
|
15430
15606
|
secure: MAILER_TRANSPORT_SECURE,
|
|
@@ -15478,16 +15654,16 @@ function useServiceProviderInviteService() {
|
|
|
15478
15654
|
});
|
|
15479
15655
|
}
|
|
15480
15656
|
} catch (error) {
|
|
15481
|
-
|
|
15657
|
+
import_node_server_utils34.logger.log({
|
|
15482
15658
|
level: "error",
|
|
15483
15659
|
message: `Invitation in-app notification failed: ${error?.message}`
|
|
15484
15660
|
});
|
|
15485
15661
|
}
|
|
15486
|
-
const filePath = (0,
|
|
15662
|
+
const filePath = (0, import_node_server_utils34.getDirectory)(
|
|
15487
15663
|
__dirname,
|
|
15488
15664
|
`./public/handlebars/${invite.type}`
|
|
15489
15665
|
);
|
|
15490
|
-
const emailContent = (0,
|
|
15666
|
+
const emailContent = (0, import_node_server_utils34.compileHandlebar)({
|
|
15491
15667
|
context: {
|
|
15492
15668
|
email,
|
|
15493
15669
|
orgName,
|
|
@@ -15507,22 +15683,22 @@ function useServiceProviderInviteService() {
|
|
|
15507
15683
|
async function load(id) {
|
|
15508
15684
|
const invite = await _getById(id);
|
|
15509
15685
|
if (!invite)
|
|
15510
|
-
throw new
|
|
15686
|
+
throw new import_node_server_utils34.NotFoundError("Invitation not found.");
|
|
15511
15687
|
return invite;
|
|
15512
15688
|
}
|
|
15513
15689
|
function assertOwnerOrSuperAdmin(actor, invite) {
|
|
15514
|
-
if (actor
|
|
15690
|
+
if (staffMayBypass(actor))
|
|
15515
15691
|
return;
|
|
15516
15692
|
const org = inviteOrgId(invite);
|
|
15517
15693
|
if (org && actor.orgIds.includes(org))
|
|
15518
15694
|
return;
|
|
15519
|
-
throw new
|
|
15695
|
+
throw new import_node_server_utils34.UnauthorizedError(
|
|
15520
15696
|
"This invitation belongs to another organisation."
|
|
15521
15697
|
);
|
|
15522
15698
|
}
|
|
15523
15699
|
function assertSuperAdmin(actor) {
|
|
15524
|
-
if (!actor
|
|
15525
|
-
throw new
|
|
15700
|
+
if (!staffMayBypass(actor)) {
|
|
15701
|
+
throw new import_node_server_utils34.UnauthorizedError(
|
|
15526
15702
|
"Only a Seven365 administrator can approve or reject invitations."
|
|
15527
15703
|
);
|
|
15528
15704
|
}
|
|
@@ -15530,12 +15706,12 @@ function useServiceProviderInviteService() {
|
|
|
15530
15706
|
function assertAllowed(action, invite) {
|
|
15531
15707
|
const refusal = refuseServiceProviderInviteAction(action, invite.status);
|
|
15532
15708
|
if (refusal)
|
|
15533
|
-
throw new
|
|
15709
|
+
throw new import_node_server_utils34.BadRequestError(refusal);
|
|
15534
15710
|
}
|
|
15535
15711
|
async function actorFor(userId) {
|
|
15536
15712
|
const actor = await resolveInviteActor(userId);
|
|
15537
15713
|
if (!actor.id)
|
|
15538
|
-
throw new
|
|
15714
|
+
throw new import_node_server_utils34.UnauthorizedError("Sign in to continue.");
|
|
15539
15715
|
return actor;
|
|
15540
15716
|
}
|
|
15541
15717
|
async function listApprovals({
|
|
@@ -15571,8 +15747,8 @@ function useServiceProviderInviteService() {
|
|
|
15571
15747
|
const actor = await actorFor(userId);
|
|
15572
15748
|
let scope = actor.orgIds;
|
|
15573
15749
|
if (orgId) {
|
|
15574
|
-
if (!actor
|
|
15575
|
-
throw new
|
|
15750
|
+
if (!staffMayBypass(actor) && !actor.orgIds.includes(orgId)) {
|
|
15751
|
+
throw new import_node_server_utils34.UnauthorizedError(
|
|
15576
15752
|
"You are not a member of that organisation."
|
|
15577
15753
|
);
|
|
15578
15754
|
}
|
|
@@ -15582,7 +15758,7 @@ function useServiceProviderInviteService() {
|
|
|
15582
15758
|
statuses: statuses ?? [],
|
|
15583
15759
|
// A super admin asking for everything passes no scope; everyone else is
|
|
15584
15760
|
// pinned to their own organisations even if they ask for more.
|
|
15585
|
-
orgIds: actor
|
|
15761
|
+
orgIds: staffMayBypass(actor) && !orgId ? void 0 : scope,
|
|
15586
15762
|
search,
|
|
15587
15763
|
page,
|
|
15588
15764
|
limit
|
|
@@ -15641,7 +15817,7 @@ function useServiceProviderInviteService() {
|
|
|
15641
15817
|
assertSuperAdmin(actor);
|
|
15642
15818
|
const trimmed = String(reason ?? "").trim();
|
|
15643
15819
|
if (!trimmed) {
|
|
15644
|
-
throw new
|
|
15820
|
+
throw new import_node_server_utils34.BadRequestError(
|
|
15645
15821
|
"Give a reason for not approving this invitation. The property manager will see it."
|
|
15646
15822
|
);
|
|
15647
15823
|
}
|
|
@@ -15695,7 +15871,7 @@ function useServiceProviderInviteService() {
|
|
|
15695
15871
|
set: { expireAt }
|
|
15696
15872
|
});
|
|
15697
15873
|
if (!updated) {
|
|
15698
|
-
throw new
|
|
15874
|
+
throw new import_node_server_utils34.BadRequestError(
|
|
15699
15875
|
refuseServiceProviderInviteAction("resend", invite.status) ?? "This invitation cannot be sent again."
|
|
15700
15876
|
);
|
|
15701
15877
|
}
|
|
@@ -15731,7 +15907,7 @@ function useServiceProviderInviteService() {
|
|
|
15731
15907
|
);
|
|
15732
15908
|
const invitedUserId = user?._id?.toString();
|
|
15733
15909
|
if (!invitedUserId || invitedUserId !== userId) {
|
|
15734
|
-
throw new
|
|
15910
|
+
throw new import_node_server_utils34.UnauthorizedError("This invitation was sent to someone else.");
|
|
15735
15911
|
}
|
|
15736
15912
|
}
|
|
15737
15913
|
async function decline({ id, userId }) {
|
|
@@ -15761,7 +15937,7 @@ function useServiceProviderInviteService() {
|
|
|
15761
15937
|
const invite = await load(id);
|
|
15762
15938
|
await assertInvitedParty(actor.id, invite);
|
|
15763
15939
|
if (invite.status === "awaiting-approval" /* AWAITING_APPROVAL */) {
|
|
15764
|
-
throw new
|
|
15940
|
+
throw new import_node_server_utils34.NotFoundError("Invitation not found.");
|
|
15765
15941
|
}
|
|
15766
15942
|
const { orgName, siteName } = await inviteContext(invite);
|
|
15767
15943
|
return {
|
|
@@ -15799,7 +15975,7 @@ function useVerificationService() {
|
|
|
15799
15975
|
from: MAILER_FROM_EMAIL,
|
|
15800
15976
|
password: MAILER_PASSWORD
|
|
15801
15977
|
};
|
|
15802
|
-
const mailer = new
|
|
15978
|
+
const mailer = new import_node_server_utils35.useMailer(MailerConfig);
|
|
15803
15979
|
const {
|
|
15804
15980
|
add,
|
|
15805
15981
|
getById: _getById,
|
|
@@ -15837,11 +16013,11 @@ function useVerificationService() {
|
|
|
15837
16013
|
value.type = type;
|
|
15838
16014
|
const res = await add(value);
|
|
15839
16015
|
const dir = __dirname;
|
|
15840
|
-
const filePath = (0,
|
|
16016
|
+
const filePath = (0, import_node_server_utils35.getDirectory)(dir, `./public/handlebars/${type}`);
|
|
15841
16017
|
const isMember = type === "member-invite";
|
|
15842
16018
|
const subject = isMember ? "Member Invite" : "User Invite";
|
|
15843
16019
|
const link = `${APP_MAIN}/verify/${isMember ? "membership" : "invitation"}/${res}`;
|
|
15844
|
-
const emailContent = (0,
|
|
16020
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
15845
16021
|
context: {
|
|
15846
16022
|
email: userName,
|
|
15847
16023
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
@@ -15855,7 +16031,7 @@ function useVerificationService() {
|
|
|
15855
16031
|
html: emailContent,
|
|
15856
16032
|
sender: "iService365"
|
|
15857
16033
|
}).catch((error) => {
|
|
15858
|
-
|
|
16034
|
+
import_node_server_utils35.logger.log({
|
|
15859
16035
|
level: "error",
|
|
15860
16036
|
message: `Error sending user ${type} email: ${error}`
|
|
15861
16037
|
});
|
|
@@ -15899,7 +16075,7 @@ function useVerificationService() {
|
|
|
15899
16075
|
const createdId = await add(value);
|
|
15900
16076
|
verificationIds.push(createdId.toString());
|
|
15901
16077
|
const link = `${APP_MAIN}/verify/invitation/${createdId}`;
|
|
15902
|
-
const emailContent = (0,
|
|
16078
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
15903
16079
|
context: {
|
|
15904
16080
|
email,
|
|
15905
16081
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
@@ -15912,7 +16088,7 @@ function useVerificationService() {
|
|
|
15912
16088
|
hasPestControl: app === "pest_control_services",
|
|
15913
16089
|
hasPoolMaintenance: app === "pool_maintenance_services"
|
|
15914
16090
|
},
|
|
15915
|
-
filePath: (0,
|
|
16091
|
+
filePath: (0, import_node_server_utils35.getDirectory)(__dirname, "./public/handlebars/user-invite")
|
|
15916
16092
|
});
|
|
15917
16093
|
await mailer.sendMail({
|
|
15918
16094
|
to: email,
|
|
@@ -15941,7 +16117,7 @@ function useVerificationService() {
|
|
|
15941
16117
|
});
|
|
15942
16118
|
if (existing) {
|
|
15943
16119
|
if (existing.status === "complete") {
|
|
15944
|
-
throw new
|
|
16120
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
15945
16121
|
`User already completed member invite for app: ${metadata.app}`
|
|
15946
16122
|
);
|
|
15947
16123
|
}
|
|
@@ -15956,13 +16132,13 @@ function useVerificationService() {
|
|
|
15956
16132
|
};
|
|
15957
16133
|
const res = await add(value);
|
|
15958
16134
|
const link = `${APP_MAIN}/verify/membership/${res}`;
|
|
15959
|
-
const emailContent = (0,
|
|
16135
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
15960
16136
|
context: {
|
|
15961
16137
|
email,
|
|
15962
16138
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
15963
16139
|
link
|
|
15964
16140
|
},
|
|
15965
|
-
filePath: (0,
|
|
16141
|
+
filePath: (0, import_node_server_utils35.getDirectory)(__dirname, "./public/handlebars/member-invite")
|
|
15966
16142
|
});
|
|
15967
16143
|
await mailer.sendMail({
|
|
15968
16144
|
to: email,
|
|
@@ -16008,8 +16184,8 @@ function useVerificationService() {
|
|
|
16008
16184
|
});
|
|
16009
16185
|
if (error) {
|
|
16010
16186
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
16011
|
-
|
|
16012
|
-
throw new
|
|
16187
|
+
import_node_server_utils35.logger.log({ level: "error", message: messages });
|
|
16188
|
+
throw new import_node_server_utils35.BadRequestError(`Invalid input: ${error.message}`);
|
|
16013
16189
|
}
|
|
16014
16190
|
let subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
16015
16191
|
let type = "service-provider-invite" /* SERVICE_PROVIDER_INVITE */;
|
|
@@ -16032,10 +16208,10 @@ function useVerificationService() {
|
|
|
16032
16208
|
const org = await getOrgById(orgId);
|
|
16033
16209
|
const actor = await resolveInviteActor(invitedBy);
|
|
16034
16210
|
if (!actor.id) {
|
|
16035
|
-
throw new
|
|
16211
|
+
throw new import_node_server_utils35.UnauthorizedError("Sign in to continue.");
|
|
16036
16212
|
}
|
|
16037
|
-
if (!actor
|
|
16038
|
-
throw new
|
|
16213
|
+
if (!staffMayBypass(actor) && !actor.orgIds.includes(orgId)) {
|
|
16214
|
+
throw new import_node_server_utils35.UnauthorizedError(
|
|
16039
16215
|
"You can only invite service providers to your own organisation's sites."
|
|
16040
16216
|
);
|
|
16041
16217
|
}
|
|
@@ -16054,7 +16230,7 @@ function useVerificationService() {
|
|
|
16054
16230
|
inviterIsPropertyManagement: actor.propertyManagementOrgIds.includes(orgId)
|
|
16055
16231
|
});
|
|
16056
16232
|
if (!decision.ok) {
|
|
16057
|
-
throw new
|
|
16233
|
+
throw new import_node_server_utils35.BadRequestError(decision.reason);
|
|
16058
16234
|
}
|
|
16059
16235
|
value.type = decision.type;
|
|
16060
16236
|
subject = decision.subject;
|
|
@@ -16115,8 +16291,8 @@ function useVerificationService() {
|
|
|
16115
16291
|
});
|
|
16116
16292
|
if (error) {
|
|
16117
16293
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
16118
|
-
|
|
16119
|
-
throw new
|
|
16294
|
+
import_node_server_utils35.logger.log({ level: "error", message: messages });
|
|
16295
|
+
throw new import_node_server_utils35.BadRequestError(`Invalid input: ${error.message}`);
|
|
16120
16296
|
}
|
|
16121
16297
|
const subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
16122
16298
|
const type = "service-provider-invite" /* SERVICE_PROVIDER_INVITE */;
|
|
@@ -16136,12 +16312,12 @@ function useVerificationService() {
|
|
|
16136
16312
|
};
|
|
16137
16313
|
try {
|
|
16138
16314
|
const id = await _add(value);
|
|
16139
|
-
const filePath = (0,
|
|
16315
|
+
const filePath = (0, import_node_server_utils35.getDirectory)(
|
|
16140
16316
|
__dirname,
|
|
16141
16317
|
`./public/handlebars/${value.type}`
|
|
16142
16318
|
);
|
|
16143
16319
|
const link = `${APP_MAIN}/verify/${value.type}/${id}`;
|
|
16144
|
-
const emailContent = (0,
|
|
16320
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
16145
16321
|
context: {
|
|
16146
16322
|
email,
|
|
16147
16323
|
app,
|
|
@@ -16174,12 +16350,12 @@ function useVerificationService() {
|
|
|
16174
16350
|
try {
|
|
16175
16351
|
const user = await getUserByEmail(email);
|
|
16176
16352
|
if (!user) {
|
|
16177
|
-
throw new
|
|
16353
|
+
throw new import_node_server_utils35.NotFoundError("Email not found");
|
|
16178
16354
|
}
|
|
16179
16355
|
const res = await add(value);
|
|
16180
16356
|
const dir = __dirname;
|
|
16181
|
-
const filePath = (0,
|
|
16182
|
-
const emailContent = (0,
|
|
16357
|
+
const filePath = (0, import_node_server_utils35.getDirectory)(dir, "./public/handlebars/forget-password");
|
|
16358
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
16183
16359
|
context: {
|
|
16184
16360
|
userName: user?.name,
|
|
16185
16361
|
validity: VERIFICATION_FORGET_PASSWORD_DURATION,
|
|
@@ -16193,21 +16369,21 @@ function useVerificationService() {
|
|
|
16193
16369
|
sender: "iService365",
|
|
16194
16370
|
html: emailContent
|
|
16195
16371
|
}).catch((error) => {
|
|
16196
|
-
|
|
16372
|
+
import_node_server_utils35.logger.log({
|
|
16197
16373
|
level: "error",
|
|
16198
16374
|
message: `Error sending forget password email: ${error}`
|
|
16199
16375
|
});
|
|
16200
16376
|
});
|
|
16201
16377
|
return "Successfully created a link to reset password. Please check your email.";
|
|
16202
16378
|
} catch (error) {
|
|
16203
|
-
throw new
|
|
16379
|
+
throw new import_node_server_utils35.InternalServerError("Failed to create forget password link.");
|
|
16204
16380
|
}
|
|
16205
16381
|
}
|
|
16206
16382
|
async function getById(id) {
|
|
16207
16383
|
try {
|
|
16208
16384
|
const _id = await _getById(id);
|
|
16209
16385
|
if (!_id) {
|
|
16210
|
-
throw new
|
|
16386
|
+
throw new import_node_server_utils35.NotFoundError("Verification not found.");
|
|
16211
16387
|
}
|
|
16212
16388
|
return _id;
|
|
16213
16389
|
} catch (error) {
|
|
@@ -16216,48 +16392,48 @@ function useVerificationService() {
|
|
|
16216
16392
|
}
|
|
16217
16393
|
function errorByType(type, status) {
|
|
16218
16394
|
if ((type === "user-invite" || type === "member-invite" || type === "service-provider-invite" || type === "service-provider-create-org") && status === "expired") {
|
|
16219
|
-
throw new
|
|
16395
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16220
16396
|
"Invitation has already expired, please contact admin to resend the invitation."
|
|
16221
16397
|
);
|
|
16222
16398
|
}
|
|
16223
16399
|
if (type === "user-sign-up" && status === "expired") {
|
|
16224
|
-
throw new
|
|
16400
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16225
16401
|
"Sign up verification has expired, please sign up again to get a new verification link."
|
|
16226
16402
|
);
|
|
16227
16403
|
}
|
|
16228
16404
|
if ((type === "user-invite" || type === "member-invite" || type === "service-provider-invite" || type === "service-provider-create-org") && status === "complete") {
|
|
16229
|
-
throw new
|
|
16405
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16230
16406
|
"User already registered, please login to continue."
|
|
16231
16407
|
);
|
|
16232
16408
|
}
|
|
16233
16409
|
if (type === "forget-password" && status === "complete") {
|
|
16234
|
-
throw new
|
|
16410
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16235
16411
|
"Forget password verification has already been used, please request a new one."
|
|
16236
16412
|
);
|
|
16237
16413
|
}
|
|
16238
16414
|
if (type === "forget-password" && status === "expired") {
|
|
16239
|
-
throw new
|
|
16415
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16240
16416
|
"Forget password verification has expired, please request a new one."
|
|
16241
16417
|
);
|
|
16242
16418
|
}
|
|
16243
|
-
throw new
|
|
16419
|
+
throw new import_node_server_utils35.BadRequestError("Invalid verification.");
|
|
16244
16420
|
}
|
|
16245
16421
|
async function verify(id) {
|
|
16246
|
-
const session =
|
|
16422
|
+
const session = import_node_server_utils35.useAtlas.getClient()?.startSession();
|
|
16247
16423
|
session?.startTransaction();
|
|
16248
16424
|
try {
|
|
16249
16425
|
const _id = await _getById(id);
|
|
16250
16426
|
if (!_id) {
|
|
16251
|
-
throw new
|
|
16427
|
+
throw new import_node_server_utils35.NotFoundError("Verification not found.");
|
|
16252
16428
|
}
|
|
16253
16429
|
if (_id.status === "expired") {
|
|
16254
16430
|
errorByType(_id.type, "expired");
|
|
16255
16431
|
}
|
|
16256
16432
|
if (_id.status === "cancelled") {
|
|
16257
|
-
throw new
|
|
16433
|
+
throw new import_node_server_utils35.BadRequestError("Verification already cancelled.");
|
|
16258
16434
|
}
|
|
16259
16435
|
if (_id.status === "complete") {
|
|
16260
|
-
throw new
|
|
16436
|
+
throw new import_node_server_utils35.BadRequestError("Verification already completed.");
|
|
16261
16437
|
}
|
|
16262
16438
|
const expiration = new Date(_id.expireAt).getTime();
|
|
16263
16439
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
@@ -16268,7 +16444,7 @@ function useVerificationService() {
|
|
|
16268
16444
|
return _id;
|
|
16269
16445
|
} catch (error) {
|
|
16270
16446
|
await session?.abortTransaction();
|
|
16271
|
-
|
|
16447
|
+
import_node_server_utils35.logger.log({
|
|
16272
16448
|
level: "info",
|
|
16273
16449
|
message: `Error verifying user invitation: ${error}`
|
|
16274
16450
|
});
|
|
@@ -16281,7 +16457,7 @@ function useVerificationService() {
|
|
|
16281
16457
|
try {
|
|
16282
16458
|
await updateStatusById(id, "cancelled");
|
|
16283
16459
|
} catch (error) {
|
|
16284
|
-
throw new
|
|
16460
|
+
throw new import_node_server_utils35.InternalServerError(
|
|
16285
16461
|
`Error cancelling user invitation: ${error}`
|
|
16286
16462
|
);
|
|
16287
16463
|
}
|
|
@@ -16301,7 +16477,7 @@ function useVerificationService() {
|
|
|
16301
16477
|
try {
|
|
16302
16478
|
const user = await getUserByEmail(email);
|
|
16303
16479
|
if (user) {
|
|
16304
|
-
throw new
|
|
16480
|
+
throw new import_node_server_utils35.BadRequestError(
|
|
16305
16481
|
`Email ${email} is already registered, please login to continue.`
|
|
16306
16482
|
);
|
|
16307
16483
|
}
|
|
@@ -16315,8 +16491,8 @@ function useVerificationService() {
|
|
|
16315
16491
|
};
|
|
16316
16492
|
const res = await add(value);
|
|
16317
16493
|
const dir = __dirname;
|
|
16318
|
-
const filePath = (0,
|
|
16319
|
-
const emailContent = (0,
|
|
16494
|
+
const filePath = (0, import_node_server_utils35.getDirectory)(dir, "./public/handlebars/sign-up");
|
|
16495
|
+
const emailContent = (0, import_node_server_utils35.compileHandlebar)({
|
|
16320
16496
|
context: {
|
|
16321
16497
|
email,
|
|
16322
16498
|
validity: "5 minutes",
|
|
@@ -16330,7 +16506,7 @@ function useVerificationService() {
|
|
|
16330
16506
|
html: emailContent,
|
|
16331
16507
|
sender: "iService365"
|
|
16332
16508
|
}).catch((error) => {
|
|
16333
|
-
|
|
16509
|
+
import_node_server_utils35.logger.log({
|
|
16334
16510
|
level: "error",
|
|
16335
16511
|
message: `Error sending user invite email: ${error}`
|
|
16336
16512
|
});
|
|
@@ -16351,7 +16527,7 @@ function useVerificationService() {
|
|
|
16351
16527
|
}
|
|
16352
16528
|
return "Successfully checked for expired invitations.";
|
|
16353
16529
|
} catch (error) {
|
|
16354
|
-
|
|
16530
|
+
import_node_server_utils35.logger.log({
|
|
16355
16531
|
level: "info",
|
|
16356
16532
|
message: `Error checking expired user invitation: ${error}`
|
|
16357
16533
|
});
|
|
@@ -16375,13 +16551,13 @@ function useVerificationService() {
|
|
|
16375
16551
|
}
|
|
16376
16552
|
|
|
16377
16553
|
// src/services/user.service.ts
|
|
16378
|
-
var
|
|
16554
|
+
var import_node_server_utils39 = require("@7365admin1/node-server-utils");
|
|
16379
16555
|
|
|
16380
16556
|
// src/repositories/role.repo.ts
|
|
16381
|
-
var
|
|
16557
|
+
var import_node_server_utils37 = require("@7365admin1/node-server-utils");
|
|
16382
16558
|
|
|
16383
16559
|
// src/models/role.model.ts
|
|
16384
|
-
var
|
|
16560
|
+
var import_node_server_utils36 = require("@7365admin1/node-server-utils");
|
|
16385
16561
|
var import_mongodb32 = require("mongodb");
|
|
16386
16562
|
var PLATFORM_STAFF_ROLE_TYPE = "admin";
|
|
16387
16563
|
var MRole = class {
|
|
@@ -16390,28 +16566,28 @@ var MRole = class {
|
|
|
16390
16566
|
try {
|
|
16391
16567
|
value._id = new import_mongodb32.ObjectId(value._id);
|
|
16392
16568
|
} catch (error) {
|
|
16393
|
-
throw new
|
|
16569
|
+
throw new import_node_server_utils36.BadRequestError("Invalid role ID format.");
|
|
16394
16570
|
}
|
|
16395
16571
|
}
|
|
16396
16572
|
if (typeof value.org === "string" && value.org.length === 24) {
|
|
16397
16573
|
try {
|
|
16398
16574
|
value.org = new import_mongodb32.ObjectId(value.org);
|
|
16399
16575
|
} catch (error) {
|
|
16400
|
-
throw new
|
|
16576
|
+
throw new import_node_server_utils36.BadRequestError("Invalid org ID format.");
|
|
16401
16577
|
}
|
|
16402
16578
|
}
|
|
16403
16579
|
if (typeof value.site === "string" && value.site.length === 24) {
|
|
16404
16580
|
try {
|
|
16405
16581
|
value.site = new import_mongodb32.ObjectId(value.site);
|
|
16406
16582
|
} catch (error) {
|
|
16407
|
-
throw new
|
|
16583
|
+
throw new import_node_server_utils36.BadRequestError("Invalid site ID format.");
|
|
16408
16584
|
}
|
|
16409
16585
|
}
|
|
16410
16586
|
if (value.createdBy) {
|
|
16411
16587
|
try {
|
|
16412
16588
|
value.createdBy = new import_mongodb32.ObjectId(value.createdBy);
|
|
16413
16589
|
} catch (error) {
|
|
16414
|
-
throw new
|
|
16590
|
+
throw new import_node_server_utils36.BadRequestError("Invalid created by ID format.");
|
|
16415
16591
|
}
|
|
16416
16592
|
}
|
|
16417
16593
|
this._id = value._id ?? new import_mongodb32.ObjectId();
|
|
@@ -16434,9 +16610,9 @@ var MRole = class {
|
|
|
16434
16610
|
// src/repositories/role.repo.ts
|
|
16435
16611
|
var import_mongodb33 = require("mongodb");
|
|
16436
16612
|
function useRoleRepo() {
|
|
16437
|
-
const db2 =
|
|
16613
|
+
const db2 = import_node_server_utils37.useAtlas.getDb();
|
|
16438
16614
|
if (!db2) {
|
|
16439
|
-
throw new
|
|
16615
|
+
throw new import_node_server_utils37.InternalServerError("Unable to connect to server.");
|
|
16440
16616
|
}
|
|
16441
16617
|
const namespace_collection = "roles";
|
|
16442
16618
|
const collection = db2.collection(namespace_collection);
|
|
@@ -16448,14 +16624,14 @@ function useRoleRepo() {
|
|
|
16448
16624
|
{ key: { status: 1 } }
|
|
16449
16625
|
]);
|
|
16450
16626
|
} catch (error) {
|
|
16451
|
-
throw new
|
|
16627
|
+
throw new import_node_server_utils37.InternalServerError("Failed to create index on role.");
|
|
16452
16628
|
}
|
|
16453
16629
|
}
|
|
16454
16630
|
async function createTextIndex() {
|
|
16455
16631
|
try {
|
|
16456
16632
|
await collection.createIndex({ name: "text" });
|
|
16457
16633
|
} catch (error) {
|
|
16458
|
-
throw new
|
|
16634
|
+
throw new import_node_server_utils37.InternalServerError("Failed to create text index on role.");
|
|
16459
16635
|
}
|
|
16460
16636
|
}
|
|
16461
16637
|
async function createUniqueIndex() {
|
|
@@ -16465,62 +16641,62 @@ function useRoleRepo() {
|
|
|
16465
16641
|
{ unique: true }
|
|
16466
16642
|
);
|
|
16467
16643
|
} catch (error) {
|
|
16468
|
-
throw new
|
|
16644
|
+
throw new import_node_server_utils37.InternalServerError("Failed to create unique index on role.");
|
|
16469
16645
|
}
|
|
16470
16646
|
}
|
|
16471
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
16472
|
-
const { delNamespace: _delDashboardNameSpace } = (0,
|
|
16647
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils37.useCache)(namespace_collection);
|
|
16648
|
+
const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils37.useCache)("dashboard");
|
|
16473
16649
|
async function addRole(value, session) {
|
|
16474
16650
|
value = new MRole(value);
|
|
16475
16651
|
try {
|
|
16476
16652
|
const res = await collection.insertOne(value, { session });
|
|
16477
16653
|
delNamespace().then(() => {
|
|
16478
|
-
|
|
16654
|
+
import_node_server_utils37.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16479
16655
|
}).catch((err) => {
|
|
16480
|
-
|
|
16656
|
+
import_node_server_utils37.logger.error(
|
|
16481
16657
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16482
16658
|
err
|
|
16483
16659
|
);
|
|
16484
16660
|
});
|
|
16485
16661
|
return res.insertedId;
|
|
16486
16662
|
} catch (error) {
|
|
16487
|
-
|
|
16663
|
+
import_node_server_utils37.logger.log({ level: "error", message: `${error}` });
|
|
16488
16664
|
const isDuplicated = error.message.includes("duplicate");
|
|
16489
16665
|
if (isDuplicated) {
|
|
16490
|
-
throw new
|
|
16666
|
+
throw new import_node_server_utils37.BadRequestError("Role already exists.");
|
|
16491
16667
|
}
|
|
16492
|
-
throw new
|
|
16668
|
+
throw new import_node_server_utils37.InternalServerError("Failed to create role.");
|
|
16493
16669
|
}
|
|
16494
16670
|
}
|
|
16495
16671
|
async function getRoleByUserId(value) {
|
|
16496
16672
|
try {
|
|
16497
16673
|
value = new import_mongodb33.ObjectId(value);
|
|
16498
16674
|
} catch (error) {
|
|
16499
|
-
throw new
|
|
16675
|
+
throw new import_node_server_utils37.BadRequestError("Invalid user ID format.");
|
|
16500
16676
|
}
|
|
16501
16677
|
try {
|
|
16502
|
-
const cacheKey = (0,
|
|
16678
|
+
const cacheKey = (0, import_node_server_utils37.makeCacheKey)(namespace_collection, { user: value });
|
|
16503
16679
|
const cachedData = await getCache(cacheKey);
|
|
16504
16680
|
if (cachedData) {
|
|
16505
|
-
|
|
16681
|
+
import_node_server_utils37.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16506
16682
|
return cachedData;
|
|
16507
16683
|
}
|
|
16508
16684
|
const data = await collection.findOne({ user: value });
|
|
16509
16685
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16510
|
-
|
|
16686
|
+
import_node_server_utils37.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16511
16687
|
}).catch((err) => {
|
|
16512
|
-
|
|
16688
|
+
import_node_server_utils37.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16513
16689
|
});
|
|
16514
16690
|
return data;
|
|
16515
16691
|
} catch (error) {
|
|
16516
|
-
throw new
|
|
16692
|
+
throw new import_node_server_utils37.InternalServerError("Failed to retrieve role by user ID.");
|
|
16517
16693
|
}
|
|
16518
16694
|
}
|
|
16519
16695
|
async function getOwnerRolesByTypeOrg(type, org) {
|
|
16520
16696
|
try {
|
|
16521
16697
|
org = new import_mongodb33.ObjectId(org);
|
|
16522
16698
|
} catch (error) {
|
|
16523
|
-
throw new
|
|
16699
|
+
throw new import_node_server_utils37.BadRequestError("Invalid organization ID format.");
|
|
16524
16700
|
}
|
|
16525
16701
|
const cacheOptions = {
|
|
16526
16702
|
org: org.toString(),
|
|
@@ -16528,69 +16704,69 @@ function useRoleRepo() {
|
|
|
16528
16704
|
type,
|
|
16529
16705
|
status: "active"
|
|
16530
16706
|
};
|
|
16531
|
-
const cacheKey = (0,
|
|
16707
|
+
const cacheKey = (0, import_node_server_utils37.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16532
16708
|
const cachedData = await getCache(cacheKey);
|
|
16533
16709
|
if (cachedData) {
|
|
16534
|
-
|
|
16710
|
+
import_node_server_utils37.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16535
16711
|
return cachedData;
|
|
16536
16712
|
}
|
|
16537
16713
|
try {
|
|
16538
16714
|
const data = await collection.find({ org, permissions: "*", type, status: "active" }).toArray();
|
|
16539
16715
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16540
|
-
|
|
16716
|
+
import_node_server_utils37.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16541
16717
|
}).catch((err) => {
|
|
16542
|
-
|
|
16718
|
+
import_node_server_utils37.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16543
16719
|
});
|
|
16544
16720
|
return data;
|
|
16545
16721
|
} catch (error) {
|
|
16546
|
-
throw new
|
|
16722
|
+
throw new import_node_server_utils37.InternalServerError("Failed to retrieve role by user ID.");
|
|
16547
16723
|
}
|
|
16548
16724
|
}
|
|
16549
16725
|
async function getRoleById(_id) {
|
|
16550
16726
|
try {
|
|
16551
16727
|
_id = new import_mongodb33.ObjectId(_id);
|
|
16552
16728
|
} catch (error) {
|
|
16553
|
-
throw new
|
|
16729
|
+
throw new import_node_server_utils37.BadRequestError("Invalid role ID format.");
|
|
16554
16730
|
}
|
|
16555
16731
|
try {
|
|
16556
|
-
const cacheKey = (0,
|
|
16732
|
+
const cacheKey = (0, import_node_server_utils37.makeCacheKey)(namespace_collection, { _id });
|
|
16557
16733
|
const cachedData = await getCache(cacheKey);
|
|
16558
16734
|
if (cachedData) {
|
|
16559
|
-
|
|
16735
|
+
import_node_server_utils37.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16560
16736
|
return cachedData;
|
|
16561
16737
|
}
|
|
16562
16738
|
const data = await collection.findOne({ _id });
|
|
16563
16739
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16564
|
-
|
|
16740
|
+
import_node_server_utils37.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16565
16741
|
}).catch((err) => {
|
|
16566
|
-
|
|
16742
|
+
import_node_server_utils37.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16567
16743
|
});
|
|
16568
16744
|
return data;
|
|
16569
16745
|
} catch (error) {
|
|
16570
|
-
throw new
|
|
16746
|
+
throw new import_node_server_utils37.InternalServerError("Failed to retrieve role by ID.");
|
|
16571
16747
|
}
|
|
16572
16748
|
}
|
|
16573
16749
|
async function getRoleByName(name, type) {
|
|
16574
16750
|
if (!name) {
|
|
16575
|
-
throw new
|
|
16751
|
+
throw new import_node_server_utils37.BadRequestError("Role name is required.");
|
|
16576
16752
|
}
|
|
16577
16753
|
const query2 = type ? { name, type } : { name };
|
|
16578
16754
|
try {
|
|
16579
|
-
const cacheKey = (0,
|
|
16755
|
+
const cacheKey = (0, import_node_server_utils37.makeCacheKey)(namespace_collection, query2);
|
|
16580
16756
|
const cachedData = await getCache(cacheKey);
|
|
16581
16757
|
if (cachedData) {
|
|
16582
|
-
|
|
16758
|
+
import_node_server_utils37.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16583
16759
|
return cachedData;
|
|
16584
16760
|
}
|
|
16585
16761
|
const data = await collection.findOne(query2);
|
|
16586
16762
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16587
|
-
|
|
16763
|
+
import_node_server_utils37.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16588
16764
|
}).catch((err) => {
|
|
16589
|
-
|
|
16765
|
+
import_node_server_utils37.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16590
16766
|
});
|
|
16591
16767
|
return data;
|
|
16592
16768
|
} catch (error) {
|
|
16593
|
-
throw new
|
|
16769
|
+
throw new import_node_server_utils37.InternalServerError("Failed to retrieve role by name.");
|
|
16594
16770
|
}
|
|
16595
16771
|
}
|
|
16596
16772
|
async function getRoles({
|
|
@@ -16607,14 +16783,14 @@ function useRoleRepo() {
|
|
|
16607
16783
|
try {
|
|
16608
16784
|
org = new import_mongodb33.ObjectId(org);
|
|
16609
16785
|
} catch (error) {
|
|
16610
|
-
throw new
|
|
16786
|
+
throw new import_node_server_utils37.BadRequestError("Invalid organization ID format.");
|
|
16611
16787
|
}
|
|
16612
16788
|
}
|
|
16613
16789
|
if (site && typeof site === "string" && site.length === 24) {
|
|
16614
16790
|
try {
|
|
16615
16791
|
site = new import_mongodb33.ObjectId(site);
|
|
16616
16792
|
} catch (error) {
|
|
16617
|
-
throw new
|
|
16793
|
+
throw new import_node_server_utils37.BadRequestError("Invalid site ID format.");
|
|
16618
16794
|
}
|
|
16619
16795
|
}
|
|
16620
16796
|
const query2 = { status: "active", org };
|
|
@@ -16633,10 +16809,10 @@ function useRoleRepo() {
|
|
|
16633
16809
|
query2.type = type;
|
|
16634
16810
|
cacheOptions.type = type;
|
|
16635
16811
|
}
|
|
16636
|
-
const cacheKey = (0,
|
|
16812
|
+
const cacheKey = (0, import_node_server_utils37.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16637
16813
|
const cachedData = await getCache(cacheKey);
|
|
16638
16814
|
if (cachedData) {
|
|
16639
|
-
|
|
16815
|
+
import_node_server_utils37.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16640
16816
|
return cachedData;
|
|
16641
16817
|
}
|
|
16642
16818
|
try {
|
|
@@ -16647,15 +16823,15 @@ function useRoleRepo() {
|
|
|
16647
16823
|
{ $limit: limit }
|
|
16648
16824
|
]).toArray();
|
|
16649
16825
|
const length = await collection.countDocuments(query2);
|
|
16650
|
-
const data = (0,
|
|
16826
|
+
const data = (0, import_node_server_utils37.paginate)(items, page, limit, length);
|
|
16651
16827
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16652
|
-
|
|
16828
|
+
import_node_server_utils37.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16653
16829
|
}).catch((err) => {
|
|
16654
|
-
|
|
16830
|
+
import_node_server_utils37.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16655
16831
|
});
|
|
16656
16832
|
return data;
|
|
16657
16833
|
} catch (error) {
|
|
16658
|
-
|
|
16834
|
+
import_node_server_utils37.logger.log({ level: "error", message: `${error}` });
|
|
16659
16835
|
throw error;
|
|
16660
16836
|
}
|
|
16661
16837
|
}
|
|
@@ -16665,12 +16841,12 @@ function useRoleRepo() {
|
|
|
16665
16841
|
org = new import_mongodb33.ObjectId(org);
|
|
16666
16842
|
}
|
|
16667
16843
|
} catch (error) {
|
|
16668
|
-
throw new
|
|
16844
|
+
throw new import_node_server_utils37.BadRequestError("Invalid organization ID format.");
|
|
16669
16845
|
}
|
|
16670
16846
|
try {
|
|
16671
16847
|
return await collection.find({ status: "active", type, org }).sort({ name: 1 }).toArray();
|
|
16672
16848
|
} catch (error) {
|
|
16673
|
-
throw new
|
|
16849
|
+
throw new import_node_server_utils37.InternalServerError("Failed to retrieve replacement roles.");
|
|
16674
16850
|
}
|
|
16675
16851
|
}
|
|
16676
16852
|
async function assertNotSeededOwnerRole(_id) {
|
|
@@ -16679,19 +16855,19 @@ function useRoleRepo() {
|
|
|
16679
16855
|
{ projection: { type: 1, default: 1 } }
|
|
16680
16856
|
);
|
|
16681
16857
|
if (role?.type === PLATFORM_STAFF_ROLE_TYPE && role?.default === true) {
|
|
16682
|
-
throw new
|
|
16858
|
+
throw new import_node_server_utils37.BadRequestError(
|
|
16683
16859
|
"The Seven365 platform owner role cannot be edited or deleted."
|
|
16684
16860
|
);
|
|
16685
16861
|
}
|
|
16686
16862
|
}
|
|
16687
16863
|
async function updateRole(_id, value, session) {
|
|
16688
16864
|
if (!_id) {
|
|
16689
|
-
throw new
|
|
16865
|
+
throw new import_node_server_utils37.BadRequestError("Role ID is required.");
|
|
16690
16866
|
}
|
|
16691
16867
|
try {
|
|
16692
16868
|
_id = new import_mongodb33.ObjectId(_id);
|
|
16693
16869
|
} catch (error) {
|
|
16694
|
-
throw new
|
|
16870
|
+
throw new import_node_server_utils37.BadRequestError("Invalid role ID format.");
|
|
16695
16871
|
}
|
|
16696
16872
|
await assertNotSeededOwnerRole(_id);
|
|
16697
16873
|
if (!value.name) {
|
|
@@ -16704,9 +16880,9 @@ function useRoleRepo() {
|
|
|
16704
16880
|
try {
|
|
16705
16881
|
await collection.updateOne({ _id }, { $set: value }, { session });
|
|
16706
16882
|
delNamespace().then(() => {
|
|
16707
|
-
|
|
16883
|
+
import_node_server_utils37.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16708
16884
|
}).catch((err) => {
|
|
16709
|
-
|
|
16885
|
+
import_node_server_utils37.logger.error(
|
|
16710
16886
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16711
16887
|
err
|
|
16712
16888
|
);
|
|
@@ -16715,29 +16891,29 @@ function useRoleRepo() {
|
|
|
16715
16891
|
} catch (error) {
|
|
16716
16892
|
const isDuplicated = error.message.includes("duplicate");
|
|
16717
16893
|
if (isDuplicated) {
|
|
16718
|
-
throw new
|
|
16894
|
+
throw new import_node_server_utils37.BadRequestError("Role name already exists.");
|
|
16719
16895
|
}
|
|
16720
|
-
throw new
|
|
16896
|
+
throw new import_node_server_utils37.InternalServerError("Failed to update role.");
|
|
16721
16897
|
}
|
|
16722
16898
|
} else {
|
|
16723
|
-
throw new
|
|
16899
|
+
throw new import_node_server_utils37.BadRequestError("No fields to update.");
|
|
16724
16900
|
}
|
|
16725
16901
|
}
|
|
16726
16902
|
async function updatePermissionsById(_id, permissions, session) {
|
|
16727
16903
|
if (!_id) {
|
|
16728
|
-
throw new
|
|
16904
|
+
throw new import_node_server_utils37.BadRequestError("Role ID is required.");
|
|
16729
16905
|
}
|
|
16730
16906
|
try {
|
|
16731
16907
|
_id = new import_mongodb33.ObjectId(_id);
|
|
16732
16908
|
} catch (error) {
|
|
16733
|
-
throw new
|
|
16909
|
+
throw new import_node_server_utils37.BadRequestError("Invalid role ID format.");
|
|
16734
16910
|
}
|
|
16735
16911
|
await assertNotSeededOwnerRole(_id);
|
|
16736
16912
|
if (!permissions) {
|
|
16737
|
-
throw new
|
|
16913
|
+
throw new import_node_server_utils37.BadRequestError("Permissions are required.");
|
|
16738
16914
|
}
|
|
16739
16915
|
if (permissions.length === 0) {
|
|
16740
|
-
throw new
|
|
16916
|
+
throw new import_node_server_utils37.BadRequestError("Permissions cannot be empty.");
|
|
16741
16917
|
}
|
|
16742
16918
|
try {
|
|
16743
16919
|
await collection.updateOne(
|
|
@@ -16746,23 +16922,23 @@ function useRoleRepo() {
|
|
|
16746
16922
|
{ session }
|
|
16747
16923
|
);
|
|
16748
16924
|
delNamespace().then(() => {
|
|
16749
|
-
|
|
16925
|
+
import_node_server_utils37.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16750
16926
|
}).catch((err) => {
|
|
16751
|
-
|
|
16927
|
+
import_node_server_utils37.logger.error(
|
|
16752
16928
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16753
16929
|
err
|
|
16754
16930
|
);
|
|
16755
16931
|
});
|
|
16756
16932
|
return "Successfully updated role permissions.";
|
|
16757
16933
|
} catch (error) {
|
|
16758
|
-
throw new
|
|
16934
|
+
throw new import_node_server_utils37.InternalServerError("Failed to update role permissions.");
|
|
16759
16935
|
}
|
|
16760
16936
|
}
|
|
16761
16937
|
async function deleteRole(_id, session) {
|
|
16762
16938
|
try {
|
|
16763
16939
|
_id = new import_mongodb33.ObjectId(_id);
|
|
16764
16940
|
} catch (error) {
|
|
16765
|
-
throw new
|
|
16941
|
+
throw new import_node_server_utils37.BadRequestError("Invalid role ID format.");
|
|
16766
16942
|
}
|
|
16767
16943
|
await assertNotSeededOwnerRole(_id);
|
|
16768
16944
|
try {
|
|
@@ -16777,24 +16953,24 @@ function useRoleRepo() {
|
|
|
16777
16953
|
{ session }
|
|
16778
16954
|
);
|
|
16779
16955
|
if (res.modifiedCount === 0) {
|
|
16780
|
-
throw new
|
|
16956
|
+
throw new import_node_server_utils37.InternalServerError("Unable to update role status.");
|
|
16781
16957
|
}
|
|
16782
16958
|
delNamespace().then(() => {
|
|
16783
|
-
|
|
16959
|
+
import_node_server_utils37.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16784
16960
|
}).catch((err) => {
|
|
16785
|
-
|
|
16961
|
+
import_node_server_utils37.logger.error(
|
|
16786
16962
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16787
16963
|
err
|
|
16788
16964
|
);
|
|
16789
16965
|
});
|
|
16790
16966
|
_delDashboardNameSpace().then(() => {
|
|
16791
|
-
|
|
16967
|
+
import_node_server_utils37.logger.info(`Cache cleared for namespace: dashboard`);
|
|
16792
16968
|
}).catch((err) => {
|
|
16793
|
-
|
|
16969
|
+
import_node_server_utils37.logger.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
16794
16970
|
});
|
|
16795
16971
|
return "Successfully deleted role permission.";
|
|
16796
16972
|
} catch (error) {
|
|
16797
|
-
throw new
|
|
16973
|
+
throw new import_node_server_utils37.InternalServerError("Failed to delete role.");
|
|
16798
16974
|
}
|
|
16799
16975
|
}
|
|
16800
16976
|
return {
|
|
@@ -16815,7 +16991,7 @@ function useRoleRepo() {
|
|
|
16815
16991
|
}
|
|
16816
16992
|
|
|
16817
16993
|
// src/repositories/file.repo.ts
|
|
16818
|
-
var
|
|
16994
|
+
var import_node_server_utils38 = require("@7365admin1/node-server-utils");
|
|
16819
16995
|
|
|
16820
16996
|
// src/models/file.model.ts
|
|
16821
16997
|
var MFile = class {
|
|
@@ -16834,13 +17010,13 @@ var MFile = class {
|
|
|
16834
17010
|
// src/repositories/file.repo.ts
|
|
16835
17011
|
var import_mongodb34 = require("mongodb");
|
|
16836
17012
|
function useFileRepo() {
|
|
16837
|
-
const db2 =
|
|
17013
|
+
const db2 = import_node_server_utils38.useAtlas.getDb();
|
|
16838
17014
|
if (!db2) {
|
|
16839
|
-
throw new
|
|
17015
|
+
throw new import_node_server_utils38.InternalServerError("Unable to connect to server.");
|
|
16840
17016
|
}
|
|
16841
17017
|
const namespace_collection = "files";
|
|
16842
17018
|
const collection = db2.collection(namespace_collection);
|
|
16843
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
17019
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils38.useCache)(namespace_collection);
|
|
16844
17020
|
async function createIndex() {
|
|
16845
17021
|
try {
|
|
16846
17022
|
await collection.createIndexes([
|
|
@@ -16848,7 +17024,7 @@ function useFileRepo() {
|
|
|
16848
17024
|
{ key: { status: 1 } }
|
|
16849
17025
|
]);
|
|
16850
17026
|
} catch (error) {
|
|
16851
|
-
throw new
|
|
17027
|
+
throw new import_node_server_utils38.InternalServerError("Failed to create index on feedback.");
|
|
16852
17028
|
}
|
|
16853
17029
|
}
|
|
16854
17030
|
async function createFile(value, session) {
|
|
@@ -16856,65 +17032,65 @@ function useFileRepo() {
|
|
|
16856
17032
|
value = new MFile(value);
|
|
16857
17033
|
const res = await collection.insertOne(value, { session });
|
|
16858
17034
|
delNamespace().then(() => {
|
|
16859
|
-
|
|
17035
|
+
import_node_server_utils38.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16860
17036
|
}).catch((err) => {
|
|
16861
|
-
|
|
17037
|
+
import_node_server_utils38.logger.error(
|
|
16862
17038
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16863
17039
|
err
|
|
16864
17040
|
);
|
|
16865
17041
|
});
|
|
16866
17042
|
return res.insertedId.toString();
|
|
16867
17043
|
} catch (error) {
|
|
16868
|
-
throw new
|
|
17044
|
+
throw new import_node_server_utils38.InternalServerError("Failed to create file.");
|
|
16869
17045
|
}
|
|
16870
17046
|
}
|
|
16871
17047
|
async function deleteFileById(_id, session) {
|
|
16872
17048
|
try {
|
|
16873
17049
|
_id = new import_mongodb34.ObjectId(_id);
|
|
16874
17050
|
} catch (error) {
|
|
16875
|
-
throw new
|
|
17051
|
+
throw new import_node_server_utils38.BadRequestError("Invalid file ID format.");
|
|
16876
17052
|
}
|
|
16877
17053
|
try {
|
|
16878
17054
|
await collection.deleteOne({ _id }, { session });
|
|
16879
17055
|
delNamespace().then(() => {
|
|
16880
|
-
|
|
17056
|
+
import_node_server_utils38.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16881
17057
|
}).catch((err) => {
|
|
16882
|
-
|
|
17058
|
+
import_node_server_utils38.logger.error(
|
|
16883
17059
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16884
17060
|
err
|
|
16885
17061
|
);
|
|
16886
17062
|
});
|
|
16887
17063
|
return "File deleted successfully.";
|
|
16888
17064
|
} catch (error) {
|
|
16889
|
-
throw new
|
|
17065
|
+
throw new import_node_server_utils38.InternalServerError("Failed to delete file.");
|
|
16890
17066
|
}
|
|
16891
17067
|
}
|
|
16892
17068
|
async function getAllDraftedFiles() {
|
|
16893
|
-
const cacheKey = (0,
|
|
17069
|
+
const cacheKey = (0, import_node_server_utils38.makeCacheKey)(namespace_collection, {
|
|
16894
17070
|
status: ["draft", null]
|
|
16895
17071
|
});
|
|
16896
17072
|
const cachedData = await getCache(cacheKey);
|
|
16897
17073
|
if (cachedData) {
|
|
16898
|
-
|
|
17074
|
+
import_node_server_utils38.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16899
17075
|
return cachedData;
|
|
16900
17076
|
}
|
|
16901
17077
|
try {
|
|
16902
17078
|
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
16903
17079
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16904
|
-
|
|
17080
|
+
import_node_server_utils38.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16905
17081
|
}).catch((err) => {
|
|
16906
|
-
|
|
17082
|
+
import_node_server_utils38.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16907
17083
|
});
|
|
16908
17084
|
return data;
|
|
16909
17085
|
} catch (error) {
|
|
16910
|
-
throw new
|
|
17086
|
+
throw new import_node_server_utils38.InternalServerError("Failed to get drafted files.");
|
|
16911
17087
|
}
|
|
16912
17088
|
}
|
|
16913
17089
|
async function updateStatusById(_id, value, session) {
|
|
16914
17090
|
try {
|
|
16915
17091
|
_id = new import_mongodb34.ObjectId(_id);
|
|
16916
17092
|
} catch (error) {
|
|
16917
|
-
throw new
|
|
17093
|
+
throw new import_node_server_utils38.BadRequestError("Invalid file ID format.");
|
|
16918
17094
|
}
|
|
16919
17095
|
try {
|
|
16920
17096
|
const res = await collection.updateOne(
|
|
@@ -16923,29 +17099,29 @@ function useFileRepo() {
|
|
|
16923
17099
|
{ session }
|
|
16924
17100
|
);
|
|
16925
17101
|
delNamespace().then(() => {
|
|
16926
|
-
|
|
17102
|
+
import_node_server_utils38.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
16927
17103
|
}).catch((err) => {
|
|
16928
|
-
|
|
17104
|
+
import_node_server_utils38.logger.error(
|
|
16929
17105
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
16930
17106
|
err
|
|
16931
17107
|
);
|
|
16932
17108
|
});
|
|
16933
17109
|
return res;
|
|
16934
17110
|
} catch (error) {
|
|
16935
|
-
throw new
|
|
17111
|
+
throw new import_node_server_utils38.InternalServerError("Failed to update file.");
|
|
16936
17112
|
}
|
|
16937
17113
|
}
|
|
16938
17114
|
async function getFileById(_id) {
|
|
16939
17115
|
try {
|
|
16940
17116
|
_id = new import_mongodb34.ObjectId(_id);
|
|
16941
17117
|
} catch (error) {
|
|
16942
|
-
throw new
|
|
17118
|
+
throw new import_node_server_utils38.BadRequestError("Invalid ID.");
|
|
16943
17119
|
}
|
|
16944
|
-
const cacheKey = (0,
|
|
17120
|
+
const cacheKey = (0, import_node_server_utils38.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
16945
17121
|
try {
|
|
16946
17122
|
const cached = await getCache(cacheKey);
|
|
16947
17123
|
if (cached) {
|
|
16948
|
-
|
|
17124
|
+
import_node_server_utils38.logger.log({
|
|
16949
17125
|
level: "info",
|
|
16950
17126
|
message: `Cache hit for getById file: ${cacheKey}`
|
|
16951
17127
|
});
|
|
@@ -16955,22 +17131,22 @@ function useFileRepo() {
|
|
|
16955
17131
|
_id
|
|
16956
17132
|
});
|
|
16957
17133
|
setCache(cacheKey, result, 300).then(() => {
|
|
16958
|
-
|
|
17134
|
+
import_node_server_utils38.logger.log({
|
|
16959
17135
|
level: "info",
|
|
16960
17136
|
message: `Cache set for file by id: ${cacheKey}`
|
|
16961
17137
|
});
|
|
16962
17138
|
}).catch((err) => {
|
|
16963
|
-
|
|
17139
|
+
import_node_server_utils38.logger.log({
|
|
16964
17140
|
level: "error",
|
|
16965
17141
|
message: `Failed to set cache for file by id: ${err.message}`
|
|
16966
17142
|
});
|
|
16967
17143
|
});
|
|
16968
17144
|
return result;
|
|
16969
17145
|
} catch (error) {
|
|
16970
|
-
if (error instanceof
|
|
17146
|
+
if (error instanceof import_node_server_utils38.AppError) {
|
|
16971
17147
|
throw error;
|
|
16972
17148
|
} else {
|
|
16973
|
-
throw new
|
|
17149
|
+
throw new import_node_server_utils38.InternalServerError("Failed to get file by id.");
|
|
16974
17150
|
}
|
|
16975
17151
|
}
|
|
16976
17152
|
}
|
|
@@ -17011,7 +17187,7 @@ function useUserService() {
|
|
|
17011
17187
|
role = result._id?.toString();
|
|
17012
17188
|
}
|
|
17013
17189
|
} catch (error) {
|
|
17014
|
-
|
|
17190
|
+
import_node_server_utils39.logger.error(error.message);
|
|
17015
17191
|
}
|
|
17016
17192
|
if (!role) {
|
|
17017
17193
|
try {
|
|
@@ -17023,15 +17199,15 @@ function useUserService() {
|
|
|
17023
17199
|
});
|
|
17024
17200
|
role = result.toString();
|
|
17025
17201
|
} catch (error) {
|
|
17026
|
-
|
|
17202
|
+
import_node_server_utils39.logger.error(error.message);
|
|
17027
17203
|
}
|
|
17028
17204
|
if (!role) {
|
|
17029
|
-
|
|
17205
|
+
import_node_server_utils39.logger.error("Failed to create default role.");
|
|
17030
17206
|
}
|
|
17031
17207
|
}
|
|
17032
17208
|
let user = "";
|
|
17033
17209
|
if (!DEFAULT_USER_EMAIL) {
|
|
17034
|
-
|
|
17210
|
+
import_node_server_utils39.logger.error("Default user email is not set.");
|
|
17035
17211
|
}
|
|
17036
17212
|
try {
|
|
17037
17213
|
const result = await getUserByEmail(DEFAULT_USER_EMAIL);
|
|
@@ -17039,11 +17215,11 @@ function useUserService() {
|
|
|
17039
17215
|
user = result._id?.toString();
|
|
17040
17216
|
}
|
|
17041
17217
|
} catch (error) {
|
|
17042
|
-
|
|
17218
|
+
import_node_server_utils39.logger.error(error.message);
|
|
17043
17219
|
}
|
|
17044
17220
|
if (!user) {
|
|
17045
17221
|
try {
|
|
17046
|
-
const password = await (0,
|
|
17222
|
+
const password = await (0, import_node_server_utils39.hashPassword)(DEFAULT_USER_PASSWORD);
|
|
17047
17223
|
const userId = await addUser({
|
|
17048
17224
|
email: DEFAULT_USER_EMAIL,
|
|
17049
17225
|
password,
|
|
@@ -17051,10 +17227,10 @@ function useUserService() {
|
|
|
17051
17227
|
});
|
|
17052
17228
|
user = userId.toString();
|
|
17053
17229
|
} catch (error) {
|
|
17054
|
-
|
|
17230
|
+
import_node_server_utils39.logger.error(error.message);
|
|
17055
17231
|
}
|
|
17056
17232
|
if (!user) {
|
|
17057
|
-
|
|
17233
|
+
import_node_server_utils39.logger.error("Failed to create default user.");
|
|
17058
17234
|
}
|
|
17059
17235
|
}
|
|
17060
17236
|
try {
|
|
@@ -17065,7 +17241,7 @@ function useUserService() {
|
|
|
17065
17241
|
type: "admin"
|
|
17066
17242
|
});
|
|
17067
17243
|
} catch (error) {
|
|
17068
|
-
|
|
17244
|
+
import_node_server_utils39.logger.error(error.message);
|
|
17069
17245
|
}
|
|
17070
17246
|
}
|
|
17071
17247
|
async function createUserBySignUp({
|
|
@@ -17073,28 +17249,28 @@ function useUserService() {
|
|
|
17073
17249
|
name = "",
|
|
17074
17250
|
password = ""
|
|
17075
17251
|
} = {}) {
|
|
17076
|
-
const session =
|
|
17252
|
+
const session = import_node_server_utils39.useAtlas.getClient()?.startSession();
|
|
17077
17253
|
session?.startTransaction();
|
|
17078
17254
|
try {
|
|
17079
17255
|
const signUp = await getVerificationById(id);
|
|
17080
17256
|
if (!signUp) {
|
|
17081
|
-
throw new
|
|
17257
|
+
throw new import_node_server_utils39.BadRequestError("Invalid sign up link.");
|
|
17082
17258
|
}
|
|
17083
17259
|
if (signUp.status === "complete") {
|
|
17084
|
-
throw new
|
|
17260
|
+
throw new import_node_server_utils39.BadRequestError(
|
|
17085
17261
|
"You have already an account created using this link."
|
|
17086
17262
|
);
|
|
17087
17263
|
}
|
|
17088
17264
|
const expired = new Date(signUp.expireAt) < /* @__PURE__ */ new Date();
|
|
17089
17265
|
if (signUp.status === "expired" || expired) {
|
|
17090
|
-
throw new
|
|
17266
|
+
throw new import_node_server_utils39.BadRequestError("Sign up link expired.");
|
|
17091
17267
|
}
|
|
17092
17268
|
const email = signUp.email;
|
|
17093
17269
|
const _user = await getUserByEmail(signUp.email);
|
|
17094
17270
|
if (_user) {
|
|
17095
|
-
throw new
|
|
17271
|
+
throw new import_node_server_utils39.BadRequestError(`User already exists: ${email}.`);
|
|
17096
17272
|
}
|
|
17097
|
-
const hashedPassword = await (0,
|
|
17273
|
+
const hashedPassword = await (0, import_node_server_utils39.hashPassword)(password);
|
|
17098
17274
|
let org = null;
|
|
17099
17275
|
if (signUp.metadata?.org) {
|
|
17100
17276
|
org = await getOrgById(signUp.metadata.org);
|
|
@@ -17143,30 +17319,30 @@ function useUserService() {
|
|
|
17143
17319
|
throw error;
|
|
17144
17320
|
}
|
|
17145
17321
|
if (newPassword !== passwordConfirmation) {
|
|
17146
|
-
throw new
|
|
17322
|
+
throw new import_node_server_utils39.BadRequestError("Passwords do not match.");
|
|
17147
17323
|
}
|
|
17148
17324
|
let hashedPassword;
|
|
17149
|
-
const session =
|
|
17325
|
+
const session = import_node_server_utils39.useAtlas.getClient()?.startSession();
|
|
17150
17326
|
session?.startTransaction();
|
|
17151
17327
|
try {
|
|
17152
|
-
hashedPassword = await (0,
|
|
17328
|
+
hashedPassword = await (0, import_node_server_utils39.hashPassword)(newPassword);
|
|
17153
17329
|
} catch (error) {
|
|
17154
|
-
throw new
|
|
17330
|
+
throw new import_node_server_utils39.InternalServerError(`Error hashing password: ${error}`);
|
|
17155
17331
|
}
|
|
17156
17332
|
try {
|
|
17157
17333
|
const otpDoc = await getVerificationById(id);
|
|
17158
17334
|
if (!otpDoc) {
|
|
17159
|
-
throw new
|
|
17335
|
+
throw new import_node_server_utils39.NotFoundError("You are using an invalid reset link.");
|
|
17160
17336
|
}
|
|
17161
17337
|
if (otpDoc.status === "complete") {
|
|
17162
|
-
throw new
|
|
17338
|
+
throw new import_node_server_utils39.BadRequestError("This link has already been invalidated.");
|
|
17163
17339
|
}
|
|
17164
17340
|
const user = await getUserByEmail(otpDoc.email);
|
|
17165
17341
|
if (!user) {
|
|
17166
|
-
throw new
|
|
17342
|
+
throw new import_node_server_utils39.NotFoundError("User not found.");
|
|
17167
17343
|
}
|
|
17168
17344
|
if (!user._id) {
|
|
17169
|
-
throw new
|
|
17345
|
+
throw new import_node_server_utils39.InternalServerError("Invalid user ID.");
|
|
17170
17346
|
}
|
|
17171
17347
|
await updateStatusById(id, "complete", session);
|
|
17172
17348
|
await _resetPassword(
|
|
@@ -17186,7 +17362,7 @@ function useUserService() {
|
|
|
17186
17362
|
session?.endSession();
|
|
17187
17363
|
}
|
|
17188
17364
|
}
|
|
17189
|
-
const s3 = new
|
|
17365
|
+
const s3 = new import_node_server_utils39.useS3({
|
|
17190
17366
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
17191
17367
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
17192
17368
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -17199,7 +17375,7 @@ function useUserService() {
|
|
|
17199
17375
|
user,
|
|
17200
17376
|
previousProfile
|
|
17201
17377
|
}) {
|
|
17202
|
-
const session =
|
|
17378
|
+
const session = import_node_server_utils39.useAtlas.getClient()?.startSession();
|
|
17203
17379
|
session?.startTransaction();
|
|
17204
17380
|
const _file = {
|
|
17205
17381
|
name: file.originalname,
|
|
@@ -17232,18 +17408,18 @@ function useUserService() {
|
|
|
17232
17408
|
async function updatePasswordById(id, currentPassword, newPassword, passwordConfirmation) {
|
|
17233
17409
|
let hashedPassword;
|
|
17234
17410
|
const user = await getUserById(id);
|
|
17235
|
-
const isPasswordValid = await (0,
|
|
17411
|
+
const isPasswordValid = await (0, import_node_server_utils39.comparePassword)(
|
|
17236
17412
|
currentPassword,
|
|
17237
17413
|
user.password
|
|
17238
17414
|
);
|
|
17239
17415
|
if (!isPasswordValid)
|
|
17240
|
-
throw new
|
|
17416
|
+
throw new import_node_server_utils39.BadRequestError("Invalid current password.");
|
|
17241
17417
|
if (newPassword !== passwordConfirmation)
|
|
17242
|
-
throw new
|
|
17418
|
+
throw new import_node_server_utils39.BadRequestError("Passwords do not match.");
|
|
17243
17419
|
try {
|
|
17244
|
-
hashedPassword = await (0,
|
|
17420
|
+
hashedPassword = await (0, import_node_server_utils39.hashPassword)(newPassword);
|
|
17245
17421
|
if (!hashedPassword)
|
|
17246
|
-
throw new
|
|
17422
|
+
throw new import_node_server_utils39.InternalServerError("Error hashing password.");
|
|
17247
17423
|
return await updatePassword({ _id: id, password: hashedPassword });
|
|
17248
17424
|
} catch (error) {
|
|
17249
17425
|
throw error;
|
|
@@ -17281,8 +17457,8 @@ function useAuthController() {
|
|
|
17281
17457
|
});
|
|
17282
17458
|
if (error) {
|
|
17283
17459
|
const messages = error.details.map((d) => d.message);
|
|
17284
|
-
|
|
17285
|
-
next(new
|
|
17460
|
+
import_node_server_utils40.logger.log({ level: "error", message: messages.join(", ") });
|
|
17461
|
+
next(new import_node_server_utils40.BadRequestError(messages.join(", ")));
|
|
17286
17462
|
return;
|
|
17287
17463
|
}
|
|
17288
17464
|
const session = await _login(value);
|
|
@@ -17294,7 +17470,7 @@ function useAuthController() {
|
|
|
17294
17470
|
res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json(session);
|
|
17295
17471
|
return;
|
|
17296
17472
|
} catch (error) {
|
|
17297
|
-
|
|
17473
|
+
import_node_server_utils40.logger.log({ level: "error", message: error.message });
|
|
17298
17474
|
next(error);
|
|
17299
17475
|
return;
|
|
17300
17476
|
}
|
|
@@ -17305,8 +17481,8 @@ function useAuthController() {
|
|
|
17305
17481
|
});
|
|
17306
17482
|
const { error, value } = validation.validate(req.body);
|
|
17307
17483
|
if (error) {
|
|
17308
|
-
|
|
17309
|
-
next(new
|
|
17484
|
+
import_node_server_utils40.logger.log({ level: "error", message: error.message });
|
|
17485
|
+
next(new import_node_server_utils40.BadRequestError(error.message));
|
|
17310
17486
|
return;
|
|
17311
17487
|
}
|
|
17312
17488
|
try {
|
|
@@ -17314,7 +17490,7 @@ function useAuthController() {
|
|
|
17314
17490
|
res.json(session);
|
|
17315
17491
|
return;
|
|
17316
17492
|
} catch (error2) {
|
|
17317
|
-
|
|
17493
|
+
import_node_server_utils40.logger.log({ level: "error", message: error2.message });
|
|
17318
17494
|
next(error2);
|
|
17319
17495
|
return;
|
|
17320
17496
|
}
|
|
@@ -17322,7 +17498,7 @@ function useAuthController() {
|
|
|
17322
17498
|
async function logout(req, res, next) {
|
|
17323
17499
|
const sid = getSessionIdFromRequest(req);
|
|
17324
17500
|
if (!sid) {
|
|
17325
|
-
next(new
|
|
17501
|
+
next(new import_node_server_utils40.BadRequestError("Session ID is required"));
|
|
17326
17502
|
return;
|
|
17327
17503
|
}
|
|
17328
17504
|
const refreshToken2 = typeof req.body?.refreshToken === "string" ? req.body.refreshToken : void 0;
|
|
@@ -17331,7 +17507,7 @@ function useAuthController() {
|
|
|
17331
17507
|
res.json({ message: "Logged out successfully" });
|
|
17332
17508
|
return;
|
|
17333
17509
|
} catch (error) {
|
|
17334
|
-
|
|
17510
|
+
import_node_server_utils40.logger.log({ level: "error", message: error.message });
|
|
17335
17511
|
next(error);
|
|
17336
17512
|
return;
|
|
17337
17513
|
}
|
|
@@ -17346,8 +17522,8 @@ function useAuthController() {
|
|
|
17346
17522
|
});
|
|
17347
17523
|
if (error) {
|
|
17348
17524
|
const messages = error.details.map((d) => d.message);
|
|
17349
|
-
|
|
17350
|
-
next(new
|
|
17525
|
+
import_node_server_utils40.logger.log({ level: "error", message: messages.join(", ") });
|
|
17526
|
+
next(new import_node_server_utils40.BadRequestError(messages.join(", ")));
|
|
17351
17527
|
return;
|
|
17352
17528
|
}
|
|
17353
17529
|
const email = value.email;
|
|
@@ -17362,7 +17538,7 @@ function useAuthController() {
|
|
|
17362
17538
|
res.json({ message });
|
|
17363
17539
|
return;
|
|
17364
17540
|
} catch (error2) {
|
|
17365
|
-
|
|
17541
|
+
import_node_server_utils40.logger.log({ level: "error", message: error2.message });
|
|
17366
17542
|
next(error2);
|
|
17367
17543
|
return;
|
|
17368
17544
|
}
|
|
@@ -17376,8 +17552,8 @@ function useAuthController() {
|
|
|
17376
17552
|
const payload = { ...req.body };
|
|
17377
17553
|
const { error } = validation.validate(payload);
|
|
17378
17554
|
if (error) {
|
|
17379
|
-
|
|
17380
|
-
next(new
|
|
17555
|
+
import_node_server_utils40.logger.log({ level: "error", message: error.message });
|
|
17556
|
+
next(new import_node_server_utils40.BadRequestError(error.message));
|
|
17381
17557
|
return;
|
|
17382
17558
|
}
|
|
17383
17559
|
const otp = req.body.otp;
|
|
@@ -17392,7 +17568,7 @@ function useAuthController() {
|
|
|
17392
17568
|
res.json({ message });
|
|
17393
17569
|
return;
|
|
17394
17570
|
} catch (error2) {
|
|
17395
|
-
|
|
17571
|
+
import_node_server_utils40.logger.log({ level: "error", message: error2.message });
|
|
17396
17572
|
next(error2);
|
|
17397
17573
|
return;
|
|
17398
17574
|
}
|
|
@@ -17407,8 +17583,8 @@ function useAuthController() {
|
|
|
17407
17583
|
const { error } = validation.validate(payload);
|
|
17408
17584
|
if (error) {
|
|
17409
17585
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
17410
|
-
|
|
17411
|
-
next(new
|
|
17586
|
+
import_node_server_utils40.logger.log({ level: "error", message: messages });
|
|
17587
|
+
next(new import_node_server_utils40.BadRequestError(messages));
|
|
17412
17588
|
return;
|
|
17413
17589
|
}
|
|
17414
17590
|
const password = req.body.password;
|
|
@@ -17417,7 +17593,7 @@ function useAuthController() {
|
|
|
17417
17593
|
res.json({ message });
|
|
17418
17594
|
return;
|
|
17419
17595
|
} catch (error2) {
|
|
17420
|
-
|
|
17596
|
+
import_node_server_utils40.logger.log({ level: "error", message: error2.message });
|
|
17421
17597
|
next(error2);
|
|
17422
17598
|
return;
|
|
17423
17599
|
}
|
|
@@ -17437,10 +17613,10 @@ var import_joi18 = __toESM(require("joi"));
|
|
|
17437
17613
|
var import_node_server_utils43 = require("@7365admin1/node-server-utils");
|
|
17438
17614
|
|
|
17439
17615
|
// src/repositories/person.repo.ts
|
|
17440
|
-
var
|
|
17616
|
+
var import_node_server_utils42 = require("@7365admin1/node-server-utils");
|
|
17441
17617
|
|
|
17442
17618
|
// src/models/person.model.ts
|
|
17443
|
-
var
|
|
17619
|
+
var import_node_server_utils41 = require("@7365admin1/node-server-utils");
|
|
17444
17620
|
var import_joi17 = __toESM(require("joi"));
|
|
17445
17621
|
var import_mongodb35 = require("mongodb");
|
|
17446
17622
|
var PersonTypes = /* @__PURE__ */ ((PersonTypes3) => {
|
|
@@ -17568,7 +17744,7 @@ var schemaUpdatePerson = import_joi17.default.object({
|
|
|
17568
17744
|
function MPerson(value) {
|
|
17569
17745
|
const { error } = schemaPerson.validate(value);
|
|
17570
17746
|
if (error) {
|
|
17571
|
-
throw new
|
|
17747
|
+
throw new import_node_server_utils41.BadRequestError(error.details[0].message);
|
|
17572
17748
|
}
|
|
17573
17749
|
if (value._id && typeof value._id === "string") {
|
|
17574
17750
|
try {
|
|
@@ -17597,7 +17773,7 @@ function MPerson(value) {
|
|
|
17597
17773
|
try {
|
|
17598
17774
|
file.id = new import_mongodb35.ObjectId(file.id);
|
|
17599
17775
|
} catch {
|
|
17600
|
-
throw new
|
|
17776
|
+
throw new import_node_server_utils41.BadRequestError("Invalid file id format");
|
|
17601
17777
|
}
|
|
17602
17778
|
}
|
|
17603
17779
|
return file;
|
|
@@ -17614,28 +17790,28 @@ function MPerson(value) {
|
|
|
17614
17790
|
try {
|
|
17615
17791
|
value.acceptedTerms = new import_mongodb35.ObjectId(value.acceptedTerms);
|
|
17616
17792
|
} catch {
|
|
17617
|
-
throw new
|
|
17793
|
+
throw new import_node_server_utils41.BadRequestError("Invalid accepted terms ID.");
|
|
17618
17794
|
}
|
|
17619
17795
|
}
|
|
17620
17796
|
if (value.block && typeof value.block === "string") {
|
|
17621
17797
|
try {
|
|
17622
17798
|
value.block = new import_mongodb35.ObjectId(value.block);
|
|
17623
17799
|
} catch {
|
|
17624
|
-
throw new
|
|
17800
|
+
throw new import_node_server_utils41.BadRequestError("Invalid block ID.");
|
|
17625
17801
|
}
|
|
17626
17802
|
}
|
|
17627
17803
|
if (value.level && typeof value.level === "string") {
|
|
17628
17804
|
try {
|
|
17629
17805
|
value.level = new import_mongodb35.ObjectId(value.level);
|
|
17630
17806
|
} catch {
|
|
17631
|
-
throw new
|
|
17807
|
+
throw new import_node_server_utils41.BadRequestError("Invalid level ID.");
|
|
17632
17808
|
}
|
|
17633
17809
|
}
|
|
17634
17810
|
if (value.unit && typeof value.unit === "string") {
|
|
17635
17811
|
try {
|
|
17636
17812
|
value.unit = new import_mongodb35.ObjectId(value.unit);
|
|
17637
17813
|
} catch {
|
|
17638
|
-
throw new
|
|
17814
|
+
throw new import_node_server_utils41.BadRequestError("Invalid unit ID.");
|
|
17639
17815
|
}
|
|
17640
17816
|
}
|
|
17641
17817
|
return {
|
|
@@ -17717,13 +17893,13 @@ var makeContainsRegex = (input) => {
|
|
|
17717
17893
|
// src/repositories/person.repo.ts
|
|
17718
17894
|
var site_people_namespace_collection = "site.people";
|
|
17719
17895
|
function usePersonRepo() {
|
|
17720
|
-
const db2 =
|
|
17896
|
+
const db2 = import_node_server_utils42.useAtlas.getDb();
|
|
17721
17897
|
if (!db2) {
|
|
17722
|
-
throw new
|
|
17898
|
+
throw new import_node_server_utils42.InternalServerError("Unable to connect to server.");
|
|
17723
17899
|
}
|
|
17724
17900
|
const collection = db2.collection(site_people_namespace_collection);
|
|
17725
17901
|
const vehiclesCollection = db2.collection("vehicles");
|
|
17726
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
17902
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils42.useCache)(
|
|
17727
17903
|
site_people_namespace_collection
|
|
17728
17904
|
);
|
|
17729
17905
|
async function withoutDeletedPlates(people) {
|
|
@@ -17772,7 +17948,7 @@ function usePersonRepo() {
|
|
|
17772
17948
|
{ key: { unit: 1, status: 1 } }
|
|
17773
17949
|
]);
|
|
17774
17950
|
} catch (error) {
|
|
17775
|
-
throw new
|
|
17951
|
+
throw new import_node_server_utils42.InternalServerError("Failed to create index on site people.");
|
|
17776
17952
|
}
|
|
17777
17953
|
}
|
|
17778
17954
|
async function createTextIndex() {
|
|
@@ -17785,7 +17961,7 @@ function usePersonRepo() {
|
|
|
17785
17961
|
contact: "text"
|
|
17786
17962
|
});
|
|
17787
17963
|
} catch (error) {
|
|
17788
|
-
throw new
|
|
17964
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
17789
17965
|
"Failed to create text index on site people."
|
|
17790
17966
|
);
|
|
17791
17967
|
}
|
|
@@ -17795,11 +17971,11 @@ function usePersonRepo() {
|
|
|
17795
17971
|
value = MPerson(value);
|
|
17796
17972
|
const res = await collection.insertOne(value, { session });
|
|
17797
17973
|
delNamespace().then(() => {
|
|
17798
|
-
|
|
17974
|
+
import_node_server_utils42.logger.info(
|
|
17799
17975
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
17800
17976
|
);
|
|
17801
17977
|
}).catch((err) => {
|
|
17802
|
-
|
|
17978
|
+
import_node_server_utils42.logger.error(
|
|
17803
17979
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
17804
17980
|
err
|
|
17805
17981
|
);
|
|
@@ -17808,7 +17984,7 @@ function usePersonRepo() {
|
|
|
17808
17984
|
} catch (error) {
|
|
17809
17985
|
const isDuplicated = error.message.includes("duplicate");
|
|
17810
17986
|
if (isDuplicated) {
|
|
17811
|
-
throw new
|
|
17987
|
+
throw new import_node_server_utils42.BadRequestError("Person already exists.");
|
|
17812
17988
|
}
|
|
17813
17989
|
throw error;
|
|
17814
17990
|
}
|
|
@@ -17936,7 +18112,7 @@ function usePersonRepo() {
|
|
|
17936
18112
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
17937
18113
|
]);
|
|
17938
18114
|
const totalCount = countResult[0]?.total || 0;
|
|
17939
|
-
const data = (0,
|
|
18115
|
+
const data = (0, import_node_server_utils42.paginate)(
|
|
17940
18116
|
await withoutDeletedPlates(items),
|
|
17941
18117
|
page,
|
|
17942
18118
|
limit,
|
|
@@ -17951,7 +18127,7 @@ function usePersonRepo() {
|
|
|
17951
18127
|
try {
|
|
17952
18128
|
_id = new import_mongodb37.ObjectId(_id);
|
|
17953
18129
|
} catch (error) {
|
|
17954
|
-
throw new
|
|
18130
|
+
throw new import_node_server_utils42.BadRequestError("Invalid person transaction ID format.");
|
|
17955
18131
|
}
|
|
17956
18132
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
17957
18133
|
if (value.updatedBy) {
|
|
@@ -17967,11 +18143,11 @@ function usePersonRepo() {
|
|
|
17967
18143
|
{ session }
|
|
17968
18144
|
);
|
|
17969
18145
|
delNamespace().then(() => {
|
|
17970
|
-
|
|
18146
|
+
import_node_server_utils42.logger.info(
|
|
17971
18147
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
17972
18148
|
);
|
|
17973
18149
|
}).catch((err) => {
|
|
17974
|
-
|
|
18150
|
+
import_node_server_utils42.logger.error(
|
|
17975
18151
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
17976
18152
|
err
|
|
17977
18153
|
);
|
|
@@ -17985,7 +18161,7 @@ function usePersonRepo() {
|
|
|
17985
18161
|
try {
|
|
17986
18162
|
_id = new import_mongodb37.ObjectId(_id);
|
|
17987
18163
|
} catch (error) {
|
|
17988
|
-
throw new
|
|
18164
|
+
throw new import_node_server_utils42.BadRequestError("Invalid customer ID format.");
|
|
17989
18165
|
}
|
|
17990
18166
|
try {
|
|
17991
18167
|
const updateValue = {
|
|
@@ -17995,14 +18171,14 @@ function usePersonRepo() {
|
|
|
17995
18171
|
};
|
|
17996
18172
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
17997
18173
|
if (res.modifiedCount === 0) {
|
|
17998
|
-
throw new
|
|
18174
|
+
throw new import_node_server_utils42.InternalServerError("Unable to delete visitor transaction.");
|
|
17999
18175
|
}
|
|
18000
18176
|
delNamespace().then(() => {
|
|
18001
|
-
|
|
18177
|
+
import_node_server_utils42.logger.info(
|
|
18002
18178
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
18003
18179
|
);
|
|
18004
18180
|
}).catch((err) => {
|
|
18005
|
-
|
|
18181
|
+
import_node_server_utils42.logger.error(
|
|
18006
18182
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
18007
18183
|
err
|
|
18008
18184
|
);
|
|
@@ -18016,15 +18192,15 @@ function usePersonRepo() {
|
|
|
18016
18192
|
try {
|
|
18017
18193
|
_id = new import_mongodb37.ObjectId(_id);
|
|
18018
18194
|
} catch (error) {
|
|
18019
|
-
throw new
|
|
18195
|
+
throw new import_node_server_utils42.BadRequestError("Invalid person ID.");
|
|
18020
18196
|
}
|
|
18021
|
-
const cacheKey = (0,
|
|
18197
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18022
18198
|
_id: String(_id)
|
|
18023
18199
|
});
|
|
18024
18200
|
try {
|
|
18025
18201
|
const cached = await getCache(cacheKey);
|
|
18026
18202
|
if (cached) {
|
|
18027
|
-
|
|
18203
|
+
import_node_server_utils42.logger.log({
|
|
18028
18204
|
level: "info",
|
|
18029
18205
|
message: `Cache hit for getById person: ${cacheKey}`
|
|
18030
18206
|
});
|
|
@@ -18034,34 +18210,34 @@ function usePersonRepo() {
|
|
|
18034
18210
|
_id
|
|
18035
18211
|
});
|
|
18036
18212
|
setCache(cacheKey, result, 300).then(() => {
|
|
18037
|
-
|
|
18213
|
+
import_node_server_utils42.logger.log({
|
|
18038
18214
|
level: "info",
|
|
18039
18215
|
message: `Cache set for person by id: ${cacheKey}`
|
|
18040
18216
|
});
|
|
18041
18217
|
}).catch((err) => {
|
|
18042
|
-
|
|
18218
|
+
import_node_server_utils42.logger.log({
|
|
18043
18219
|
level: "error",
|
|
18044
18220
|
message: `Failed to set cache for person by id: ${err.message}`
|
|
18045
18221
|
});
|
|
18046
18222
|
});
|
|
18047
18223
|
return result;
|
|
18048
18224
|
} catch (error) {
|
|
18049
|
-
if (error instanceof
|
|
18225
|
+
if (error instanceof import_node_server_utils42.AppError) {
|
|
18050
18226
|
throw error;
|
|
18051
18227
|
} else {
|
|
18052
|
-
throw new
|
|
18228
|
+
throw new import_node_server_utils42.InternalServerError("Failed to get person by id.");
|
|
18053
18229
|
}
|
|
18054
18230
|
}
|
|
18055
18231
|
}
|
|
18056
18232
|
async function getPersonByPlateNumber(plateNumber) {
|
|
18057
|
-
const cacheKey = (0,
|
|
18233
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18058
18234
|
plateNumber,
|
|
18059
18235
|
key: "get-person-plate-number"
|
|
18060
18236
|
});
|
|
18061
18237
|
try {
|
|
18062
18238
|
const cacheData = await getCache(cacheKey);
|
|
18063
18239
|
if (cacheData) {
|
|
18064
|
-
|
|
18240
|
+
import_node_server_utils42.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
18065
18241
|
return await withoutDeletedPlatesOne(cacheData);
|
|
18066
18242
|
}
|
|
18067
18243
|
const data = await collection.findOne(
|
|
@@ -18069,13 +18245,13 @@ function usePersonRepo() {
|
|
|
18069
18245
|
{ sort: { _id: -1 } }
|
|
18070
18246
|
);
|
|
18071
18247
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18072
|
-
|
|
18248
|
+
import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18073
18249
|
}).catch((err) => {
|
|
18074
|
-
|
|
18250
|
+
import_node_server_utils42.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18075
18251
|
});
|
|
18076
18252
|
return await withoutDeletedPlatesOne(data);
|
|
18077
18253
|
} catch (error) {
|
|
18078
|
-
throw new
|
|
18254
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
18079
18255
|
"Failed to fetch individual by plate number."
|
|
18080
18256
|
);
|
|
18081
18257
|
}
|
|
@@ -18087,11 +18263,11 @@ function usePersonRepo() {
|
|
|
18087
18263
|
status: "approved"
|
|
18088
18264
|
};
|
|
18089
18265
|
if (excludePersonId) {
|
|
18090
|
-
query2._id = { $ne: (0,
|
|
18266
|
+
query2._id = { $ne: (0, import_node_server_utils42.toObjectId)(excludePersonId) };
|
|
18091
18267
|
}
|
|
18092
18268
|
return await collection.findOne(query2);
|
|
18093
18269
|
} catch (error) {
|
|
18094
|
-
throw new
|
|
18270
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
18095
18271
|
"Failed to fetch approved person by plate number."
|
|
18096
18272
|
);
|
|
18097
18273
|
}
|
|
@@ -18099,47 +18275,47 @@ function usePersonRepo() {
|
|
|
18099
18275
|
async function getByNRIC(value) {
|
|
18100
18276
|
try {
|
|
18101
18277
|
if (!value || value.trim() === "") {
|
|
18102
|
-
|
|
18278
|
+
import_node_server_utils42.logger.warn("getByNRIC called with an empty or invalid NRIC value.");
|
|
18103
18279
|
return null;
|
|
18104
18280
|
}
|
|
18105
|
-
const cacheKey = (0,
|
|
18281
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18106
18282
|
nric: value
|
|
18107
18283
|
});
|
|
18108
18284
|
const cachedData = await getCache(cacheKey);
|
|
18109
18285
|
if (cachedData) {
|
|
18110
|
-
|
|
18286
|
+
import_node_server_utils42.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
18111
18287
|
return await withoutDeletedPlatesOne(cachedData);
|
|
18112
18288
|
}
|
|
18113
18289
|
const data = await collection.findOne({ nric: value });
|
|
18114
18290
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18115
|
-
|
|
18291
|
+
import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18116
18292
|
}).catch((err) => {
|
|
18117
|
-
|
|
18293
|
+
import_node_server_utils42.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18118
18294
|
});
|
|
18119
18295
|
return await withoutDeletedPlatesOne(data);
|
|
18120
18296
|
} catch (error) {
|
|
18121
|
-
throw new
|
|
18297
|
+
throw new import_node_server_utils42.InternalServerError("Failed to retrieve person by NRIC.");
|
|
18122
18298
|
}
|
|
18123
18299
|
}
|
|
18124
18300
|
async function getPersonByPhoneNumber(value) {
|
|
18125
18301
|
try {
|
|
18126
|
-
const cacheKey = (0,
|
|
18302
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18127
18303
|
contact: value
|
|
18128
18304
|
});
|
|
18129
18305
|
const cachedData = await getCache(cacheKey);
|
|
18130
18306
|
if (cachedData) {
|
|
18131
|
-
|
|
18307
|
+
import_node_server_utils42.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
18132
18308
|
return await withoutDeletedPlatesOne(cachedData);
|
|
18133
18309
|
}
|
|
18134
18310
|
const data = await collection.findOne({ contact: value });
|
|
18135
18311
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18136
|
-
|
|
18312
|
+
import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18137
18313
|
}).catch((err) => {
|
|
18138
|
-
|
|
18314
|
+
import_node_server_utils42.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18139
18315
|
});
|
|
18140
18316
|
return await withoutDeletedPlatesOne(data);
|
|
18141
18317
|
} catch (error) {
|
|
18142
|
-
throw new
|
|
18318
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
18143
18319
|
"Failed to retrieve person by Phone Number."
|
|
18144
18320
|
);
|
|
18145
18321
|
}
|
|
@@ -18151,7 +18327,7 @@ function usePersonRepo() {
|
|
|
18151
18327
|
}, session) {
|
|
18152
18328
|
try {
|
|
18153
18329
|
if (!unit || !import_mongodb37.ObjectId.isValid(unit)) {
|
|
18154
|
-
throw new
|
|
18330
|
+
throw new import_node_server_utils42.BadRequestError("Invalid unit ID.");
|
|
18155
18331
|
}
|
|
18156
18332
|
const query2 = {
|
|
18157
18333
|
unit: new import_mongodb37.ObjectId(unit),
|
|
@@ -18196,14 +18372,14 @@ function usePersonRepo() {
|
|
|
18196
18372
|
]).toArray();
|
|
18197
18373
|
return await withoutDeletedPlates(data);
|
|
18198
18374
|
} catch (error) {
|
|
18199
|
-
throw new
|
|
18375
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
18200
18376
|
"Failed to fetch people type residents by unit."
|
|
18201
18377
|
);
|
|
18202
18378
|
}
|
|
18203
18379
|
}
|
|
18204
18380
|
async function getCompany(search, orgs) {
|
|
18205
18381
|
try {
|
|
18206
|
-
const cacheKey = (0,
|
|
18382
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18207
18383
|
company: search
|
|
18208
18384
|
});
|
|
18209
18385
|
const baseQuery = {
|
|
@@ -18273,18 +18449,18 @@ function usePersonRepo() {
|
|
|
18273
18449
|
]).toArray();
|
|
18274
18450
|
return data;
|
|
18275
18451
|
} catch (error) {
|
|
18276
|
-
throw new
|
|
18452
|
+
throw new import_node_server_utils42.InternalServerError("Failed to fetch visitor by company.");
|
|
18277
18453
|
}
|
|
18278
18454
|
}
|
|
18279
18455
|
async function getPeopleByPlateNumber(plateNumber) {
|
|
18280
|
-
const cacheKey = (0,
|
|
18456
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18281
18457
|
plateNumber,
|
|
18282
18458
|
key: "get-people-plate-number"
|
|
18283
18459
|
});
|
|
18284
18460
|
try {
|
|
18285
18461
|
const cacheData = await getCache(cacheKey);
|
|
18286
18462
|
if (cacheData) {
|
|
18287
|
-
|
|
18463
|
+
import_node_server_utils42.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
18288
18464
|
return await withoutDeletedPlates(cacheData);
|
|
18289
18465
|
}
|
|
18290
18466
|
const data = await collection.find(
|
|
@@ -18292,13 +18468,13 @@ function usePersonRepo() {
|
|
|
18292
18468
|
{ sort: { _id: -1 } }
|
|
18293
18469
|
).toArray();
|
|
18294
18470
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18295
|
-
|
|
18471
|
+
import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18296
18472
|
}).catch((err) => {
|
|
18297
|
-
|
|
18473
|
+
import_node_server_utils42.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18298
18474
|
});
|
|
18299
18475
|
return await withoutDeletedPlates(data);
|
|
18300
18476
|
} catch (error) {
|
|
18301
|
-
throw new
|
|
18477
|
+
throw new import_node_server_utils42.InternalServerError("Failed to fetch people by plate number.");
|
|
18302
18478
|
}
|
|
18303
18479
|
}
|
|
18304
18480
|
async function getPeopleByNRIC({
|
|
@@ -18323,13 +18499,13 @@ function usePersonRepo() {
|
|
|
18323
18499
|
sort: JSON.stringify(sort)
|
|
18324
18500
|
};
|
|
18325
18501
|
try {
|
|
18326
|
-
const cacheKey = (0,
|
|
18502
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(
|
|
18327
18503
|
site_people_namespace_collection,
|
|
18328
18504
|
cacheOptions
|
|
18329
18505
|
);
|
|
18330
18506
|
const cachedData = await getCache(cacheKey);
|
|
18331
18507
|
if (cachedData) {
|
|
18332
|
-
|
|
18508
|
+
import_node_server_utils42.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
18333
18509
|
const cachedPage = cachedData;
|
|
18334
18510
|
return {
|
|
18335
18511
|
...cachedPage,
|
|
@@ -18338,26 +18514,26 @@ function usePersonRepo() {
|
|
|
18338
18514
|
}
|
|
18339
18515
|
const items = await collection.find(query2).sort(sort).skip(page * limit).limit(limit).toArray();
|
|
18340
18516
|
const length = await collection.countDocuments(query2);
|
|
18341
|
-
const data = (0,
|
|
18517
|
+
const data = (0, import_node_server_utils42.paginate)(
|
|
18342
18518
|
await withoutDeletedPlates(items),
|
|
18343
18519
|
page,
|
|
18344
18520
|
limit,
|
|
18345
18521
|
length
|
|
18346
18522
|
);
|
|
18347
18523
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18348
|
-
|
|
18524
|
+
import_node_server_utils42.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18349
18525
|
}).catch((err) => {
|
|
18350
|
-
|
|
18526
|
+
import_node_server_utils42.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18351
18527
|
});
|
|
18352
18528
|
return data;
|
|
18353
18529
|
} catch (error) {
|
|
18354
|
-
throw new
|
|
18530
|
+
throw new import_node_server_utils42.InternalServerError("Failed to retrieve person by NRIC.");
|
|
18355
18531
|
}
|
|
18356
18532
|
}
|
|
18357
18533
|
async function pushVehicleById(id, plate, session) {
|
|
18358
18534
|
const { plateNumber, recNo } = plate;
|
|
18359
18535
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
18360
|
-
const _id = (0,
|
|
18536
|
+
const _id = (0, import_node_server_utils42.toObjectId)(id);
|
|
18361
18537
|
try {
|
|
18362
18538
|
const updateExisting = await collection.updateOne(
|
|
18363
18539
|
{
|
|
@@ -18390,15 +18566,15 @@ function usePersonRepo() {
|
|
|
18390
18566
|
);
|
|
18391
18567
|
}
|
|
18392
18568
|
} catch (error) {
|
|
18393
|
-
throw new
|
|
18569
|
+
throw new import_node_server_utils42.InternalServerError("Failed to push vehicle plates by nric.");
|
|
18394
18570
|
}
|
|
18395
18571
|
}
|
|
18396
18572
|
async function pullVehicleByRecNo(recNo, scope, session) {
|
|
18397
18573
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
18398
|
-
const owner = scope?.peopleId ? (0,
|
|
18399
|
-
const site = scope?.site ? (0,
|
|
18574
|
+
const owner = scope?.peopleId ? (0, import_node_server_utils42.toObjectId)(scope.peopleId) : null;
|
|
18575
|
+
const site = scope?.site ? (0, import_node_server_utils42.toObjectId)(scope.site) : null;
|
|
18400
18576
|
if (!owner && !site) {
|
|
18401
|
-
throw new
|
|
18577
|
+
throw new import_node_server_utils42.BadRequestError(
|
|
18402
18578
|
"Cannot remove a vehicle plate without a person or a site."
|
|
18403
18579
|
);
|
|
18404
18580
|
}
|
|
@@ -18439,24 +18615,24 @@ function usePersonRepo() {
|
|
|
18439
18615
|
{ session }
|
|
18440
18616
|
);
|
|
18441
18617
|
} catch (error) {
|
|
18442
|
-
|
|
18618
|
+
import_node_server_utils42.logger.log({
|
|
18443
18619
|
level: "error",
|
|
18444
18620
|
message: `pullVehicleByRecNo failed on ${matchKey} for ${owner ? "person" : "site"} ${String(owner ?? site)}: ${error?.message ?? error}`
|
|
18445
18621
|
});
|
|
18446
|
-
throw new
|
|
18622
|
+
throw new import_node_server_utils42.InternalServerError(
|
|
18447
18623
|
"Could not take the plate off the resident's record."
|
|
18448
18624
|
);
|
|
18449
18625
|
}
|
|
18450
18626
|
}
|
|
18451
18627
|
async function getByUserId(userId) {
|
|
18452
|
-
const user = (0,
|
|
18453
|
-
const cacheKey = (0,
|
|
18628
|
+
const user = (0, import_node_server_utils42.toObjectId)(userId);
|
|
18629
|
+
const cacheKey = (0, import_node_server_utils42.makeCacheKey)(site_people_namespace_collection, {
|
|
18454
18630
|
user: userId
|
|
18455
18631
|
});
|
|
18456
18632
|
try {
|
|
18457
18633
|
const cached = await getCache(cacheKey);
|
|
18458
18634
|
if (cached) {
|
|
18459
|
-
|
|
18635
|
+
import_node_server_utils42.logger.log({
|
|
18460
18636
|
level: "info",
|
|
18461
18637
|
message: `Cache hit for getByUserId person: ${cacheKey}`
|
|
18462
18638
|
});
|
|
@@ -18466,22 +18642,22 @@ function usePersonRepo() {
|
|
|
18466
18642
|
user
|
|
18467
18643
|
});
|
|
18468
18644
|
setCache(cacheKey, result, 15 * 60).then(() => {
|
|
18469
|
-
|
|
18645
|
+
import_node_server_utils42.logger.log({
|
|
18470
18646
|
level: "info",
|
|
18471
18647
|
message: `Cache set for person by user: ${cacheKey}`
|
|
18472
18648
|
});
|
|
18473
18649
|
}).catch((err) => {
|
|
18474
|
-
|
|
18650
|
+
import_node_server_utils42.logger.log({
|
|
18475
18651
|
level: "error",
|
|
18476
18652
|
message: `Failed to set cache for person by user: ${err.message}`
|
|
18477
18653
|
});
|
|
18478
18654
|
});
|
|
18479
18655
|
return result;
|
|
18480
18656
|
} catch (error) {
|
|
18481
|
-
if (error instanceof
|
|
18657
|
+
if (error instanceof import_node_server_utils42.AppError) {
|
|
18482
18658
|
throw error;
|
|
18483
18659
|
} else {
|
|
18484
|
-
throw new
|
|
18660
|
+
throw new import_node_server_utils42.InternalServerError("Failed to get person by user.");
|
|
18485
18661
|
}
|
|
18486
18662
|
}
|
|
18487
18663
|
}
|
|
@@ -18490,7 +18666,7 @@ function usePersonRepo() {
|
|
|
18490
18666
|
try {
|
|
18491
18667
|
_id = new import_mongodb37.ObjectId(_id);
|
|
18492
18668
|
} catch (error) {
|
|
18493
|
-
throw new
|
|
18669
|
+
throw new import_node_server_utils42.BadRequestError("Invalid ID format.");
|
|
18494
18670
|
}
|
|
18495
18671
|
try {
|
|
18496
18672
|
const res = await collection.updateOne(
|
|
@@ -18499,14 +18675,14 @@ function usePersonRepo() {
|
|
|
18499
18675
|
{ session }
|
|
18500
18676
|
);
|
|
18501
18677
|
if (res.modifiedCount === 0) {
|
|
18502
|
-
throw new
|
|
18678
|
+
throw new import_node_server_utils42.InternalServerError(`Unable to ${value.status} person.`);
|
|
18503
18679
|
}
|
|
18504
18680
|
delNamespace().then(() => {
|
|
18505
|
-
|
|
18681
|
+
import_node_server_utils42.logger.info(
|
|
18506
18682
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
18507
18683
|
);
|
|
18508
18684
|
}).catch((err) => {
|
|
18509
|
-
|
|
18685
|
+
import_node_server_utils42.logger.error(
|
|
18510
18686
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
18511
18687
|
err
|
|
18512
18688
|
);
|
|
@@ -18522,7 +18698,7 @@ function usePersonRepo() {
|
|
|
18522
18698
|
const data = await collection.find(query2, { session }).limit(10).toArray();
|
|
18523
18699
|
return data;
|
|
18524
18700
|
} catch (error) {
|
|
18525
|
-
throw new
|
|
18701
|
+
throw new import_node_server_utils42.InternalServerError("Failed to find persons" + error);
|
|
18526
18702
|
}
|
|
18527
18703
|
}
|
|
18528
18704
|
async function addFromVisitor(value, session) {
|
|
@@ -18557,7 +18733,7 @@ function usePersonRepo() {
|
|
|
18557
18733
|
_id = new import_mongodb37.ObjectId(personId);
|
|
18558
18734
|
acceptedTerms = new import_mongodb37.ObjectId(termsId);
|
|
18559
18735
|
} catch {
|
|
18560
|
-
throw new
|
|
18736
|
+
throw new import_node_server_utils42.BadRequestError("Invalid ID format.");
|
|
18561
18737
|
}
|
|
18562
18738
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
18563
18739
|
try {
|
|
@@ -18566,7 +18742,7 @@ function usePersonRepo() {
|
|
|
18566
18742
|
{ $set: { acceptedTerms, acceptedTermsAt: now, updatedAt: now } }
|
|
18567
18743
|
);
|
|
18568
18744
|
} catch (error) {
|
|
18569
|
-
throw new
|
|
18745
|
+
throw new import_node_server_utils42.InternalServerError("Failed to record terms acceptance.");
|
|
18570
18746
|
}
|
|
18571
18747
|
}
|
|
18572
18748
|
async function getAcceptedTerms(personId) {
|
|
@@ -18574,7 +18750,7 @@ function usePersonRepo() {
|
|
|
18574
18750
|
try {
|
|
18575
18751
|
_id = new import_mongodb37.ObjectId(personId);
|
|
18576
18752
|
} catch {
|
|
18577
|
-
throw new
|
|
18753
|
+
throw new import_node_server_utils42.BadRequestError("Invalid person ID format.");
|
|
18578
18754
|
}
|
|
18579
18755
|
try {
|
|
18580
18756
|
return await collection.findOne(
|
|
@@ -18582,11 +18758,11 @@ function usePersonRepo() {
|
|
|
18582
18758
|
{ projection: { acceptedTerms: 1, acceptedTermsAt: 1, _id: 0 } }
|
|
18583
18759
|
);
|
|
18584
18760
|
} catch (error) {
|
|
18585
|
-
throw new
|
|
18761
|
+
throw new import_node_server_utils42.InternalServerError("Failed to read terms acceptance.");
|
|
18586
18762
|
}
|
|
18587
18763
|
}
|
|
18588
18764
|
async function updatePlateNumberByUserId(userId, plateNumber, session) {
|
|
18589
|
-
const user = (0,
|
|
18765
|
+
const user = (0, import_node_server_utils42.toObjectId)(userId);
|
|
18590
18766
|
try {
|
|
18591
18767
|
const result = await collection.updateOne(
|
|
18592
18768
|
{ user },
|
|
@@ -18600,25 +18776,25 @@ function usePersonRepo() {
|
|
|
18600
18776
|
{ session }
|
|
18601
18777
|
);
|
|
18602
18778
|
if (result.matchedCount === 0) {
|
|
18603
|
-
throw new
|
|
18779
|
+
throw new import_node_server_utils42.BadRequestError("Person not found for this user.");
|
|
18604
18780
|
}
|
|
18605
18781
|
try {
|
|
18606
18782
|
await delNamespace();
|
|
18607
|
-
|
|
18783
|
+
import_node_server_utils42.logger.info(
|
|
18608
18784
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
18609
18785
|
);
|
|
18610
18786
|
} catch (err) {
|
|
18611
|
-
|
|
18787
|
+
import_node_server_utils42.logger.error(
|
|
18612
18788
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
18613
18789
|
err
|
|
18614
18790
|
);
|
|
18615
18791
|
}
|
|
18616
18792
|
return "Successfully updated plate number.";
|
|
18617
18793
|
} catch (error) {
|
|
18618
|
-
if (error instanceof
|
|
18794
|
+
if (error instanceof import_node_server_utils42.BadRequestError) {
|
|
18619
18795
|
throw error;
|
|
18620
18796
|
}
|
|
18621
|
-
throw new
|
|
18797
|
+
throw new import_node_server_utils42.InternalServerError("Failed to update plate number.");
|
|
18622
18798
|
}
|
|
18623
18799
|
}
|
|
18624
18800
|
return {
|
|
@@ -18649,161 +18825,6 @@ function usePersonRepo() {
|
|
|
18649
18825
|
};
|
|
18650
18826
|
}
|
|
18651
18827
|
|
|
18652
|
-
// src/utils/console-authz.util.ts
|
|
18653
|
-
var import_node_server_utils42 = require("@7365admin1/node-server-utils");
|
|
18654
|
-
|
|
18655
|
-
// src/utils/console-permission.util.ts
|
|
18656
|
-
var CONSOLE_PERMISSIONS = Object.freeze({
|
|
18657
|
-
organizations: Object.freeze([
|
|
18658
|
-
"see-all-organizations",
|
|
18659
|
-
"see-organization-details"
|
|
18660
|
-
]),
|
|
18661
|
-
"promo-codes": Object.freeze([
|
|
18662
|
-
"create-promo-code",
|
|
18663
|
-
"see-promo-code-details",
|
|
18664
|
-
"edit-promo-code-details",
|
|
18665
|
-
"change-promo-code-status",
|
|
18666
|
-
"delete-promo-code"
|
|
18667
|
-
]),
|
|
18668
|
-
users: Object.freeze(["see-all-users", "see-user-details"]),
|
|
18669
|
-
invitations: Object.freeze([
|
|
18670
|
-
"create-invitation",
|
|
18671
|
-
"view-invitations",
|
|
18672
|
-
"cancel-invitation"
|
|
18673
|
-
]),
|
|
18674
|
-
subscriptions: Object.freeze([
|
|
18675
|
-
"see-all-subscriptions",
|
|
18676
|
-
"see-subscription-details",
|
|
18677
|
-
"manage-subscription"
|
|
18678
|
-
]),
|
|
18679
|
-
"sp-approvals": Object.freeze([
|
|
18680
|
-
"see-all-sp-approvals",
|
|
18681
|
-
"approve-sp",
|
|
18682
|
-
"reject-sp",
|
|
18683
|
-
"delete-sp-approval"
|
|
18684
|
-
]),
|
|
18685
|
-
"marketplace-vendors": Object.freeze([
|
|
18686
|
-
"see-all-marketplace-vendors",
|
|
18687
|
-
"see-marketplace-vendor-details"
|
|
18688
|
-
]),
|
|
18689
|
-
"platform-terms": Object.freeze([
|
|
18690
|
-
"see-platform-terms",
|
|
18691
|
-
"edit-platform-terms"
|
|
18692
|
-
]),
|
|
18693
|
-
"activity-history": Object.freeze(["see-activity-history"]),
|
|
18694
|
-
members: Object.freeze([
|
|
18695
|
-
"view-members",
|
|
18696
|
-
"assign-member-role",
|
|
18697
|
-
"suspend-member",
|
|
18698
|
-
"activate-member",
|
|
18699
|
-
"delete-member"
|
|
18700
|
-
]),
|
|
18701
|
-
"roles-and-permissions": Object.freeze([
|
|
18702
|
-
"add-role",
|
|
18703
|
-
"see-all-roles",
|
|
18704
|
-
"see-role-details",
|
|
18705
|
-
"update-role",
|
|
18706
|
-
"delete-role"
|
|
18707
|
-
])
|
|
18708
|
-
});
|
|
18709
|
-
var RESOURCE_SPELLINGS = Object.freeze({
|
|
18710
|
-
"roles-and-permissions": Object.freeze([
|
|
18711
|
-
"roles-and-permissions",
|
|
18712
|
-
"roles"
|
|
18713
|
-
]),
|
|
18714
|
-
roles: Object.freeze(["roles", "roles-and-permissions"])
|
|
18715
|
-
});
|
|
18716
|
-
function consoleSpellings(resource, action) {
|
|
18717
|
-
const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
|
|
18718
|
-
return resources.map((name) => `${name}:${action}`);
|
|
18719
|
-
}
|
|
18720
|
-
function consoleRoleAllowsAll(held) {
|
|
18721
|
-
if (!Array.isArray(held) || held.length === 0)
|
|
18722
|
-
return true;
|
|
18723
|
-
return held.includes("*");
|
|
18724
|
-
}
|
|
18725
|
-
function consoleRoleAllows(held, resource, action) {
|
|
18726
|
-
if (consoleRoleAllowsAll(held))
|
|
18727
|
-
return true;
|
|
18728
|
-
const actions = CONSOLE_PERMISSIONS[resource];
|
|
18729
|
-
if (!actions?.length)
|
|
18730
|
-
return false;
|
|
18731
|
-
const wanted = action ? actions.includes(action) ? [action] : [] : actions;
|
|
18732
|
-
return wanted.some(
|
|
18733
|
-
(name) => consoleSpellings(resource, name).some(
|
|
18734
|
-
(spelling) => held.includes(spelling)
|
|
18735
|
-
)
|
|
18736
|
-
);
|
|
18737
|
-
}
|
|
18738
|
-
|
|
18739
|
-
// src/utils/console-authz.util.ts
|
|
18740
|
-
function callerId(req) {
|
|
18741
|
-
const user = req.user;
|
|
18742
|
-
return user?.user?.toString?.() || user?._id?.toString?.() || "";
|
|
18743
|
-
}
|
|
18744
|
-
async function requirePlatformStaff(req, grant) {
|
|
18745
|
-
const id = callerId(req);
|
|
18746
|
-
const role = id ? await resolveStaffRole(id) : null;
|
|
18747
|
-
if (!role) {
|
|
18748
|
-
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18749
|
-
}
|
|
18750
|
-
if (grant && !consoleRoleAllows(role.permissions, grant.resource, grant.action)) {
|
|
18751
|
-
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18752
|
-
}
|
|
18753
|
-
return id;
|
|
18754
|
-
}
|
|
18755
|
-
async function requireConsolePermission(req, resource, action) {
|
|
18756
|
-
return await requirePlatformStaff(req, { resource, action });
|
|
18757
|
-
}
|
|
18758
|
-
async function requireSelfOrPlatformStaff(req, userId, grant) {
|
|
18759
|
-
const id = callerId(req);
|
|
18760
|
-
const target = userId?.toString() ?? "";
|
|
18761
|
-
if (id && target && target === id)
|
|
18762
|
-
return id;
|
|
18763
|
-
return await requirePlatformStaff(req, grant);
|
|
18764
|
-
}
|
|
18765
|
-
async function requireOrgAccess(req, orgId) {
|
|
18766
|
-
return await requireOrgReach(req, orgId);
|
|
18767
|
-
}
|
|
18768
|
-
async function requirePlatformOwner(req, grant) {
|
|
18769
|
-
const id = callerId(req);
|
|
18770
|
-
if (!id || !await isPlatformOwner(id)) {
|
|
18771
|
-
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18772
|
-
}
|
|
18773
|
-
if (grant)
|
|
18774
|
-
await requirePlatformStaff(req, grant);
|
|
18775
|
-
return id;
|
|
18776
|
-
}
|
|
18777
|
-
async function requireOrgReach(req, orgId) {
|
|
18778
|
-
const id = callerId(req);
|
|
18779
|
-
if (!id)
|
|
18780
|
-
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18781
|
-
const org = orgId?.toString() ?? "";
|
|
18782
|
-
const actor = await resolveInviteActor(id);
|
|
18783
|
-
if (actor.isSuperAdmin)
|
|
18784
|
-
return id;
|
|
18785
|
-
if (org && actor.orgIds.includes(org))
|
|
18786
|
-
return id;
|
|
18787
|
-
if (org && await hasOrgInvitation(id, org))
|
|
18788
|
-
return id;
|
|
18789
|
-
if (org && await hasOrgOwnership(id, org))
|
|
18790
|
-
return id;
|
|
18791
|
-
throw new import_node_server_utils42.UnauthorizedError("Not authorized.");
|
|
18792
|
-
}
|
|
18793
|
-
async function requireInviteReach(req, org, app) {
|
|
18794
|
-
const apps = Array.isArray(app) ? app : [app];
|
|
18795
|
-
if (apps.some((a) => a === PLATFORM_STAFF_MEMBER_TYPE)) {
|
|
18796
|
-
await requirePlatformStaff(req);
|
|
18797
|
-
}
|
|
18798
|
-
if (org)
|
|
18799
|
-
await requireOrgReach(req, org);
|
|
18800
|
-
}
|
|
18801
|
-
async function requireUserFieldWrite(req, userId, field, grant) {
|
|
18802
|
-
if (field === "email")
|
|
18803
|
-
return await requirePlatformStaff(req, grant);
|
|
18804
|
-
return await requireSelfOrPlatformStaff(req, userId, grant);
|
|
18805
|
-
}
|
|
18806
|
-
|
|
18807
18828
|
// src/utils/user-response.util.ts
|
|
18808
18829
|
function publicIdentity(user) {
|
|
18809
18830
|
if (!user || typeof user !== "object")
|
|
@@ -26731,7 +26752,7 @@ async function requireSiteReach(req, site, permission) {
|
|
|
26731
26752
|
if (!siteId)
|
|
26732
26753
|
throw new import_node_server_utils56.UnauthorizedError("Not authorized.");
|
|
26733
26754
|
const actor = await resolveInviteActor(callerId(req));
|
|
26734
|
-
if (actor
|
|
26755
|
+
if (staffMayBypass(actor))
|
|
26735
26756
|
return;
|
|
26736
26757
|
if (permission) {
|
|
26737
26758
|
await useCameraViewService().authorizeSite({
|
|
@@ -26746,8 +26767,9 @@ async function requireSiteReach(req, site, permission) {
|
|
|
26746
26767
|
async function siteReachOf(req) {
|
|
26747
26768
|
const actor = await resolveInviteActor(callerId(req));
|
|
26748
26769
|
const reachable = /* @__PURE__ */ new Map();
|
|
26770
|
+
const bypass = staffMayBypass(actor);
|
|
26749
26771
|
function canReach(record) {
|
|
26750
|
-
if (
|
|
26772
|
+
if (bypass)
|
|
26751
26773
|
return Promise.resolve(true);
|
|
26752
26774
|
if (!record)
|
|
26753
26775
|
return Promise.resolve(false);
|
|
@@ -26768,7 +26790,7 @@ async function siteReachOf(req) {
|
|
|
26768
26790
|
return reachable.get(site);
|
|
26769
26791
|
}
|
|
26770
26792
|
async function only(records) {
|
|
26771
|
-
if (
|
|
26793
|
+
if (bypass)
|
|
26772
26794
|
return records;
|
|
26773
26795
|
const verdicts = await Promise.all(records.map((r) => canReach(r)));
|
|
26774
26796
|
return records.filter((_, i) => verdicts[i]);
|
|
@@ -26782,7 +26804,7 @@ async function requireSiteReachIfSignedIn(req, site) {
|
|
|
26782
26804
|
}
|
|
26783
26805
|
async function entitledSites(req) {
|
|
26784
26806
|
const actor = await resolveInviteActor(callerId(req));
|
|
26785
|
-
if (actor
|
|
26807
|
+
if (staffMayBypass(actor))
|
|
26786
26808
|
return null;
|
|
26787
26809
|
if (actor.memberships.length === 0)
|
|
26788
26810
|
return [];
|
|
@@ -37351,13 +37373,13 @@ var import_node_server_utils101 = require("@7365admin1/node-server-utils");
|
|
|
37351
37373
|
var import_joi50 = __toESM(require("joi"));
|
|
37352
37374
|
async function requireSiteWrite(req, siteId) {
|
|
37353
37375
|
const actor = await resolveInviteActor(callerId(req));
|
|
37354
|
-
if (actor
|
|
37376
|
+
if (staffMayBypass(actor))
|
|
37355
37377
|
return;
|
|
37356
37378
|
await useCameraViewService().entitleSite({ siteId, userId: actor.id });
|
|
37357
37379
|
}
|
|
37358
37380
|
async function requireSiteRead(req, siteId, site) {
|
|
37359
37381
|
const actor = await resolveInviteActor(callerId(req));
|
|
37360
|
-
if (actor
|
|
37382
|
+
if (staffMayBypass(actor))
|
|
37361
37383
|
return;
|
|
37362
37384
|
const owner = (site?.orgId ?? site?.org)?.toString?.() ?? "";
|
|
37363
37385
|
if (owner && actor.orgIds.includes(owner))
|
|
@@ -42182,7 +42204,7 @@ var import_node_server_utils118 = require("@7365admin1/node-server-utils");
|
|
|
42182
42204
|
async function requireEitherOrg(req, ...orgs) {
|
|
42183
42205
|
const wanted = orgs.map((org) => org?.toString?.() ?? "").filter((org) => Boolean(org));
|
|
42184
42206
|
const actor = await resolveInviteActor(callerId(req));
|
|
42185
|
-
if (actor
|
|
42207
|
+
if (staffMayBypass(actor))
|
|
42186
42208
|
return;
|
|
42187
42209
|
if (wanted.length === 0 || !wanted.some((org) => actor.orgIds.includes(org))) {
|
|
42188
42210
|
throw new import_node_server_utils118.UnauthorizedError("Not authorized.");
|
|
@@ -42278,7 +42300,7 @@ function useCustomerSiteController() {
|
|
|
42278
42300
|
try {
|
|
42279
42301
|
await requireOrgAccess(req, org);
|
|
42280
42302
|
const actor = await resolveInviteActor(callerId(req));
|
|
42281
|
-
const siteScope = actor
|
|
42303
|
+
const siteScope = staffMayBypass(actor) ? null : orgSiteScope({ memberships: actor.memberships, org });
|
|
42282
42304
|
const data = await _getAll({
|
|
42283
42305
|
search,
|
|
42284
42306
|
page,
|
|
@@ -42312,7 +42334,7 @@ function useCustomerSiteController() {
|
|
|
42312
42334
|
}
|
|
42313
42335
|
try {
|
|
42314
42336
|
const actor = await resolveInviteActor(callerId(req));
|
|
42315
|
-
if (!actor
|
|
42337
|
+
if (!staffMayBypass(actor)) {
|
|
42316
42338
|
await useCameraViewService().entitleSite({
|
|
42317
42339
|
siteId: site,
|
|
42318
42340
|
userId: actor.id
|
|
@@ -58248,7 +58270,7 @@ function usePersonController() {
|
|
|
58248
58270
|
} = usePersonService();
|
|
58249
58271
|
async function entitlePerson(req, _id) {
|
|
58250
58272
|
const actor = await resolveInviteActor(callerId(req));
|
|
58251
|
-
if (actor
|
|
58273
|
+
if (staffMayBypass(actor))
|
|
58252
58274
|
return actor;
|
|
58253
58275
|
const person = await _getById(_id);
|
|
58254
58276
|
if (!person)
|
|
@@ -64809,7 +64831,7 @@ function useDocumentManagementController() {
|
|
|
64809
64831
|
return;
|
|
64810
64832
|
}
|
|
64811
64833
|
const actor = await resolveInviteActor(callerId(req));
|
|
64812
|
-
if (actor
|
|
64834
|
+
if (staffMayBypass(actor))
|
|
64813
64835
|
return;
|
|
64814
64836
|
const org = doc?.org?.toString() ?? "";
|
|
64815
64837
|
if (!org || !actor.orgIds.includes(org)) {
|
|
@@ -68773,7 +68795,7 @@ var import_mongodb123 = require("mongodb");
|
|
|
68773
68795
|
var import_node_server_utils193 = require("@7365admin1/node-server-utils");
|
|
68774
68796
|
async function requireOwnUnit(req, site, unitId) {
|
|
68775
68797
|
const actor = await resolveInviteActor(callerId(req));
|
|
68776
|
-
if (actor
|
|
68798
|
+
if (staffMayBypass(actor))
|
|
68777
68799
|
return;
|
|
68778
68800
|
const unit = unitId?.toString?.() ?? "";
|
|
68779
68801
|
const siteId = site?.toString?.() ?? "";
|
|
@@ -77288,10 +77310,10 @@ function useOnlineFormController() {
|
|
|
77288
77310
|
const { actor } = await siteReachOf(req);
|
|
77289
77311
|
if (site) {
|
|
77290
77312
|
await requireSiteReach(req, site);
|
|
77291
|
-
} else if (!actor
|
|
77313
|
+
} else if (!staffMayBypass(actor)) {
|
|
77292
77314
|
throw new import_node_server_utils230.UnauthorizedError("Not authorized.");
|
|
77293
77315
|
}
|
|
77294
|
-
if (org && !actor
|
|
77316
|
+
if (org && !staffMayBypass(actor) && !actor.orgIds.includes(org)) {
|
|
77295
77317
|
throw new import_node_server_utils230.UnauthorizedError("Not authorized.");
|
|
77296
77318
|
}
|
|
77297
77319
|
const data = await _getAll({ search, page, limit, status, org, site });
|
|
@@ -77356,7 +77378,7 @@ function useOnlineFormController() {
|
|
|
77356
77378
|
}
|
|
77357
77379
|
if (payload.org) {
|
|
77358
77380
|
const { actor } = await siteReachOf(req);
|
|
77359
|
-
if (!actor
|
|
77381
|
+
if (!staffMayBypass(actor) && !actor.orgIds.includes(payload.org)) {
|
|
77360
77382
|
throw new import_node_server_utils230.UnauthorizedError("Not authorized.");
|
|
77361
77383
|
}
|
|
77362
77384
|
}
|
|
@@ -84778,7 +84800,7 @@ function useVerificationServiceV2() {
|
|
|
84778
84800
|
if (!actor.id) {
|
|
84779
84801
|
throw new import_node_server_utils262.UnauthorizedError("Sign in to continue.");
|
|
84780
84802
|
}
|
|
84781
|
-
if (!actor
|
|
84803
|
+
if (!staffMayBypass(actor) && !actor.orgIds.includes(orgId)) {
|
|
84782
84804
|
throw new import_node_server_utils262.UnauthorizedError(
|
|
84783
84805
|
"You can only invite service providers to your own organisation's sites."
|
|
84784
84806
|
);
|
|
@@ -85280,6 +85302,11 @@ function useServiceProviderInviteController() {
|
|
|
85280
85302
|
}
|
|
85281
85303
|
async function approvals(req, res, next) {
|
|
85282
85304
|
try {
|
|
85305
|
+
await requireConsolePermission(
|
|
85306
|
+
req,
|
|
85307
|
+
"sp-approvals",
|
|
85308
|
+
"see-all-sp-approvals"
|
|
85309
|
+
);
|
|
85283
85310
|
const schema2 = import_joi143.default.object({
|
|
85284
85311
|
status: import_joi143.default.string().valid(
|
|
85285
85312
|
"awaiting-approval",
|
|
@@ -85306,6 +85333,11 @@ function useServiceProviderInviteController() {
|
|
|
85306
85333
|
}
|
|
85307
85334
|
async function pendingApprovalCount(req, res, next) {
|
|
85308
85335
|
try {
|
|
85336
|
+
await requireConsolePermission(
|
|
85337
|
+
req,
|
|
85338
|
+
"sp-approvals",
|
|
85339
|
+
"see-all-sp-approvals"
|
|
85340
|
+
);
|
|
85309
85341
|
res.json(await approvalCount({ userId: callerId5(req) }));
|
|
85310
85342
|
} catch (error) {
|
|
85311
85343
|
next(error);
|
|
@@ -85313,6 +85345,7 @@ function useServiceProviderInviteController() {
|
|
|
85313
85345
|
}
|
|
85314
85346
|
async function approve(req, res, next) {
|
|
85315
85347
|
try {
|
|
85348
|
+
await requireConsolePermission(req, "sp-approvals", "approve-sp");
|
|
85316
85349
|
res.json(await _approve({ id: inviteId(req), userId: callerId5(req) }));
|
|
85317
85350
|
} catch (error) {
|
|
85318
85351
|
import_node_server_utils264.logger.log({ level: "error", message: `${error.message}` });
|
|
@@ -85321,6 +85354,7 @@ function useServiceProviderInviteController() {
|
|
|
85321
85354
|
}
|
|
85322
85355
|
async function reject(req, res, next) {
|
|
85323
85356
|
try {
|
|
85357
|
+
await requireConsolePermission(req, "sp-approvals", "reject-sp");
|
|
85324
85358
|
const { error, value } = import_joi143.default.object({
|
|
85325
85359
|
reason: import_joi143.default.string().trim().min(1).max(1e3).required()
|
|
85326
85360
|
}).validate(req.body ?? {});
|
|
@@ -92035,7 +92069,9 @@ function useNotificationPreferenceController() {
|
|
|
92035
92069
|
CLIENT_ACTIONS,
|
|
92036
92070
|
CLOCK_DRIFT_WARN_SECONDS,
|
|
92037
92071
|
CONSOLE_AUDIT_LABELS,
|
|
92072
|
+
CONSOLE_PERMISSIONS,
|
|
92038
92073
|
CONTRACTOR_TYPE_LABELS,
|
|
92074
|
+
CROSS_CLIENT_GRANT,
|
|
92039
92075
|
CURRENT_TIME_ENDPOINT,
|
|
92040
92076
|
CameraType,
|
|
92041
92077
|
ConsoleAuditAction,
|
|
@@ -92247,6 +92283,9 @@ function useNotificationPreferenceController() {
|
|
|
92247
92283
|
chatSchema,
|
|
92248
92284
|
clampPtzSpeed,
|
|
92249
92285
|
clockDriftSeconds,
|
|
92286
|
+
consoleRoleAllows,
|
|
92287
|
+
consoleRoleAllowsAll,
|
|
92288
|
+
consoleSpellings,
|
|
92250
92289
|
console_audit_namespace_collection,
|
|
92251
92290
|
createManpowerRemarksDaily,
|
|
92252
92291
|
customerSchema,
|
|
@@ -92346,6 +92385,8 @@ function useNotificationPreferenceController() {
|
|
|
92346
92385
|
relayForRecorder,
|
|
92347
92386
|
remarksSchema,
|
|
92348
92387
|
renderPagePdf,
|
|
92388
|
+
requireConsolePermission,
|
|
92389
|
+
requirePlatformStaff,
|
|
92349
92390
|
resetCameraTransports,
|
|
92350
92391
|
residentAppModuleKeys,
|
|
92351
92392
|
residentFormEntry,
|
|
@@ -92517,6 +92558,7 @@ function useNotificationPreferenceController() {
|
|
|
92517
92558
|
site_people_namespace_collection,
|
|
92518
92559
|
snapshotEndpoint,
|
|
92519
92560
|
snapshotRefusalReason,
|
|
92561
|
+
staffMayBypass,
|
|
92520
92562
|
stringifyHidJson,
|
|
92521
92563
|
stripFacialImageMetadata,
|
|
92522
92564
|
subscriptionPlanSchema,
|