@7365admin1/core 3.53.0 → 3.53.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +67 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/e2e/role-site-scope.e2e.test.mjs +204 -0
- package/test/file-delete-scope.test.mjs +64 -0
package/dist/index.mjs
CHANGED
|
@@ -16002,7 +16002,8 @@ function useRoleRepo() {
|
|
|
16002
16002
|
limit = 10,
|
|
16003
16003
|
sort = {},
|
|
16004
16004
|
type = "",
|
|
16005
|
-
org = ""
|
|
16005
|
+
org = "",
|
|
16006
|
+
site = ""
|
|
16006
16007
|
}) {
|
|
16007
16008
|
page = page > 0 ? page - 1 : 0;
|
|
16008
16009
|
if (org && typeof org === "string" && org.length === 24) {
|
|
@@ -16012,8 +16013,19 @@ function useRoleRepo() {
|
|
|
16012
16013
|
throw new BadRequestError31("Invalid organization ID format.");
|
|
16013
16014
|
}
|
|
16014
16015
|
}
|
|
16016
|
+
if (site && typeof site === "string" && site.length === 24) {
|
|
16017
|
+
try {
|
|
16018
|
+
site = new ObjectId33(site);
|
|
16019
|
+
} catch (error) {
|
|
16020
|
+
throw new BadRequestError31("Invalid site ID format.");
|
|
16021
|
+
}
|
|
16022
|
+
}
|
|
16015
16023
|
const query2 = { status: "active", org };
|
|
16016
16024
|
const cacheOptions = { status: "active", org };
|
|
16025
|
+
if (site) {
|
|
16026
|
+
query2.$or = [{ site }, { site: "" }, { site: null }];
|
|
16027
|
+
cacheOptions.site = site.toString();
|
|
16028
|
+
}
|
|
16017
16029
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
16018
16030
|
cacheOptions.sort = JSON.stringify(sort);
|
|
16019
16031
|
if (search) {
|
|
@@ -16225,6 +16237,8 @@ var MFile = class {
|
|
|
16225
16237
|
this.size = value.size ?? 0;
|
|
16226
16238
|
this.status = value.status ?? "draft";
|
|
16227
16239
|
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
16240
|
+
if (value.createdBy)
|
|
16241
|
+
this.createdBy = value.createdBy.toString();
|
|
16228
16242
|
}
|
|
16229
16243
|
};
|
|
16230
16244
|
|
|
@@ -18588,7 +18602,8 @@ function useRoleController() {
|
|
|
18588
18602
|
page: Joi19.number().integer().min(1).allow("", null).default(1),
|
|
18589
18603
|
limit: Joi19.number().integer().min(1).max(100).allow("", null).default(10),
|
|
18590
18604
|
type: Joi19.string().optional().allow("", null),
|
|
18591
|
-
org: Joi19.string().hex().optional().allow("", null)
|
|
18605
|
+
org: Joi19.string().hex().optional().allow("", null),
|
|
18606
|
+
site: Joi19.string().hex().optional().allow("", null)
|
|
18592
18607
|
});
|
|
18593
18608
|
const query2 = { ...req.query };
|
|
18594
18609
|
const { error } = validation.validate(query2);
|
|
@@ -18602,11 +18617,12 @@ function useRoleController() {
|
|
|
18602
18617
|
const limit = parseInt(req.query.limit ?? "10");
|
|
18603
18618
|
const type = req.query.type ?? "";
|
|
18604
18619
|
const org = req.query.org ?? "";
|
|
18620
|
+
const site = req.query.site ?? "";
|
|
18605
18621
|
try {
|
|
18606
18622
|
if (org) {
|
|
18607
18623
|
await requireOrgReach(req, org);
|
|
18608
18624
|
}
|
|
18609
|
-
const data = await _getRoles({ search, page, limit, type, org });
|
|
18625
|
+
const data = await _getRoles({ search, page, limit, type, org, site });
|
|
18610
18626
|
res.json(data);
|
|
18611
18627
|
return;
|
|
18612
18628
|
} catch (error2) {
|
|
@@ -21974,13 +21990,14 @@ function useFileService() {
|
|
|
21974
21990
|
bucket: SPACES_BUCKET,
|
|
21975
21991
|
forcePathStyle: true
|
|
21976
21992
|
});
|
|
21977
|
-
async function createFile(value, folder = "default") {
|
|
21993
|
+
async function createFile(value, folder = "default", createdBy) {
|
|
21978
21994
|
const session = useAtlas29.getClient()?.startSession();
|
|
21979
21995
|
session?.startTransaction();
|
|
21980
21996
|
const file = {
|
|
21981
21997
|
name: value.originalname,
|
|
21982
21998
|
size: value.size ?? (value.buffer ? value.buffer.length : 0),
|
|
21983
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
21999
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22000
|
+
...createdBy ? { createdBy } : {}
|
|
21984
22001
|
};
|
|
21985
22002
|
try {
|
|
21986
22003
|
const id = await _createFile(file, session);
|
|
@@ -27064,8 +27081,55 @@ function useVerificationController() {
|
|
|
27064
27081
|
}
|
|
27065
27082
|
|
|
27066
27083
|
// src/controllers/file.controller.ts
|
|
27067
|
-
import {
|
|
27084
|
+
import {
|
|
27085
|
+
BadRequestError as BadRequestError50,
|
|
27086
|
+
UnauthorizedError as UnauthorizedError7,
|
|
27087
|
+
logger as logger35
|
|
27088
|
+
} from "@7365admin1/node-server-utils";
|
|
27068
27089
|
import Joi27 from "joi";
|
|
27090
|
+
|
|
27091
|
+
// src/utils/file-owner.util.ts
|
|
27092
|
+
function fileOwnerId(file) {
|
|
27093
|
+
return file?.createdBy?.toString?.() ?? "";
|
|
27094
|
+
}
|
|
27095
|
+
function mayDeleteFile(params) {
|
|
27096
|
+
if (!params.ownerId)
|
|
27097
|
+
return true;
|
|
27098
|
+
if (!params.callerId)
|
|
27099
|
+
return false;
|
|
27100
|
+
if (params.callerId === params.ownerId)
|
|
27101
|
+
return true;
|
|
27102
|
+
if (params.callerIsSuperAdmin)
|
|
27103
|
+
return true;
|
|
27104
|
+
const ownerOrgs = new Set((params.ownerOrgIds ?? []).map(String));
|
|
27105
|
+
return (params.callerOrgIds ?? []).some((org) => ownerOrgs.has(String(org)));
|
|
27106
|
+
}
|
|
27107
|
+
|
|
27108
|
+
// src/controllers/file.controller.ts
|
|
27109
|
+
async function requireFileDelete(req, file) {
|
|
27110
|
+
const ownerId = fileOwnerId(file);
|
|
27111
|
+
if (!ownerId)
|
|
27112
|
+
return;
|
|
27113
|
+
const caller = callerId(req);
|
|
27114
|
+
if (!caller)
|
|
27115
|
+
throw new UnauthorizedError7("Not authorized.");
|
|
27116
|
+
if (caller === ownerId)
|
|
27117
|
+
return;
|
|
27118
|
+
const [me, owner] = await Promise.all([
|
|
27119
|
+
resolveInviteActor(caller),
|
|
27120
|
+
resolveInviteActor(ownerId)
|
|
27121
|
+
]);
|
|
27122
|
+
if (mayDeleteFile({
|
|
27123
|
+
ownerId,
|
|
27124
|
+
callerId: caller,
|
|
27125
|
+
callerIsSuperAdmin: me.isSuperAdmin,
|
|
27126
|
+
callerOrgIds: me.orgIds,
|
|
27127
|
+
ownerOrgIds: owner.orgIds
|
|
27128
|
+
})) {
|
|
27129
|
+
return;
|
|
27130
|
+
}
|
|
27131
|
+
throw new UnauthorizedError7("Not authorized.");
|
|
27132
|
+
}
|
|
27069
27133
|
function useFileController() {
|
|
27070
27134
|
const { createFile, deleteFile: _deleteFile } = useFileService();
|
|
27071
27135
|
const { getFileById: _getFileById } = useFileRepo();
|
|
@@ -27075,7 +27139,7 @@ function useFileController() {
|
|
|
27075
27139
|
return;
|
|
27076
27140
|
}
|
|
27077
27141
|
try {
|
|
27078
|
-
const id = await createFile(req.file);
|
|
27142
|
+
const id = await createFile(req.file, "default", callerId(req) || void 0);
|
|
27079
27143
|
res.status(201).json({ message: "Successfully uploaded file", id });
|
|
27080
27144
|
return;
|
|
27081
27145
|
} catch (error) {
|
|
@@ -27094,6 +27158,7 @@ function useFileController() {
|
|
|
27094
27158
|
return;
|
|
27095
27159
|
}
|
|
27096
27160
|
try {
|
|
27161
|
+
await requireFileDelete(req, await _getFileById(_id));
|
|
27097
27162
|
const message = await _deleteFile(_id);
|
|
27098
27163
|
res.json({ message });
|
|
27099
27164
|
return;
|
|
@@ -27136,7 +27201,7 @@ import {
|
|
|
27136
27201
|
BadRequestError as BadRequestError54,
|
|
27137
27202
|
logger as logger38,
|
|
27138
27203
|
NotFoundError as NotFoundError17,
|
|
27139
|
-
UnauthorizedError as
|
|
27204
|
+
UnauthorizedError as UnauthorizedError8
|
|
27140
27205
|
} from "@7365admin1/node-server-utils";
|
|
27141
27206
|
import Joi31 from "joi";
|
|
27142
27207
|
|
|
@@ -28409,7 +28474,7 @@ function useOrgController() {
|
|
|
28409
28474
|
try {
|
|
28410
28475
|
const createdBy = callerId(req);
|
|
28411
28476
|
if (!createdBy)
|
|
28412
|
-
throw new
|
|
28477
|
+
throw new UnauthorizedError8("Not authorized.");
|
|
28413
28478
|
const _id = await _add({ ...req.body, createdBy });
|
|
28414
28479
|
const data = await _getById(_id);
|
|
28415
28480
|
res.status(201).json({
|
|
@@ -30910,7 +30975,7 @@ function useSubscriptionService() {
|
|
|
30910
30975
|
import Joi36 from "joi";
|
|
30911
30976
|
import {
|
|
30912
30977
|
BadRequestError as BadRequestError70,
|
|
30913
|
-
UnauthorizedError as
|
|
30978
|
+
UnauthorizedError as UnauthorizedError9,
|
|
30914
30979
|
logger as logger48
|
|
30915
30980
|
} from "@7365admin1/node-server-utils";
|
|
30916
30981
|
|
|
@@ -31331,7 +31396,7 @@ function useSubscriptionController() {
|
|
|
31331
31396
|
try {
|
|
31332
31397
|
const subscription = await _getSubscriptionById(subscriptionId);
|
|
31333
31398
|
if (!subscription) {
|
|
31334
|
-
throw new
|
|
31399
|
+
throw new UnauthorizedError9("Not authorized.");
|
|
31335
31400
|
}
|
|
31336
31401
|
await requireOrgAccess(req, subscription.org?.toString());
|
|
31337
31402
|
const _res = await _updateSubscriptionSeats({
|
|
@@ -41663,7 +41728,7 @@ function useCustomerSiteService() {
|
|
|
41663
41728
|
import Joi59 from "joi";
|
|
41664
41729
|
import {
|
|
41665
41730
|
BadRequestError as BadRequestError106,
|
|
41666
|
-
UnauthorizedError as
|
|
41731
|
+
UnauthorizedError as UnauthorizedError10,
|
|
41667
41732
|
logger as logger78
|
|
41668
41733
|
} from "@7365admin1/node-server-utils";
|
|
41669
41734
|
async function requireEitherOrg(req, ...orgs) {
|
|
@@ -41672,7 +41737,7 @@ async function requireEitherOrg(req, ...orgs) {
|
|
|
41672
41737
|
if (actor.isSuperAdmin)
|
|
41673
41738
|
return;
|
|
41674
41739
|
if (wanted.length === 0 || !wanted.some((org) => actor.orgIds.includes(org))) {
|
|
41675
|
-
throw new
|
|
41740
|
+
throw new UnauthorizedError10("Not authorized.");
|
|
41676
41741
|
}
|
|
41677
41742
|
}
|
|
41678
41743
|
function useCustomerSiteController() {
|
|
@@ -44885,7 +44950,7 @@ import {
|
|
|
44885
44950
|
BadRequestError as BadRequestError120,
|
|
44886
44951
|
InternalServerError as InternalServerError42,
|
|
44887
44952
|
NotFoundError as NotFoundError34,
|
|
44888
|
-
UnauthorizedError as
|
|
44953
|
+
UnauthorizedError as UnauthorizedError11,
|
|
44889
44954
|
logger as logger90
|
|
44890
44955
|
} from "@7365admin1/node-server-utils";
|
|
44891
44956
|
|
|
@@ -48419,8 +48484,8 @@ function useHidAmicoService() {
|
|
|
48419
48484
|
await siteAccess.authorizeSite({ siteId, userId: value.userId, permissions });
|
|
48420
48485
|
}
|
|
48421
48486
|
} catch (error) {
|
|
48422
|
-
if (error instanceof
|
|
48423
|
-
throw new
|
|
48487
|
+
if (error instanceof UnauthorizedError11) {
|
|
48488
|
+
throw new UnauthorizedError11("You do not have permission to manage HID access at this site.");
|
|
48424
48489
|
}
|
|
48425
48490
|
throw error;
|
|
48426
48491
|
}
|
|
@@ -48444,7 +48509,7 @@ function useHidAmicoService() {
|
|
|
48444
48509
|
try {
|
|
48445
48510
|
await authorizeSiteForCaller(String(reader.site || ""), userId);
|
|
48446
48511
|
} catch (error) {
|
|
48447
|
-
if (error instanceof
|
|
48512
|
+
if (error instanceof UnauthorizedError11)
|
|
48448
48513
|
throw error;
|
|
48449
48514
|
throw new NotFoundError34(HID_READER_NOT_FOUND);
|
|
48450
48515
|
}
|
|
@@ -48496,10 +48561,10 @@ function useHidAmicoService() {
|
|
|
48496
48561
|
async function assertUserReaderPermission(reader, userId, options = {}) {
|
|
48497
48562
|
const permission = await getReaderPermissionForUser(reader, userId);
|
|
48498
48563
|
if (!permission.granted) {
|
|
48499
|
-
throw new
|
|
48564
|
+
throw new UnauthorizedError11("You do not have HID access permission for this reader.");
|
|
48500
48565
|
}
|
|
48501
48566
|
if (options.intercom && !permission.intercom) {
|
|
48502
|
-
throw new
|
|
48567
|
+
throw new UnauthorizedError11("You do not have HID intercom permission for this reader.");
|
|
48503
48568
|
}
|
|
48504
48569
|
return permission;
|
|
48505
48570
|
}
|
|
@@ -49837,10 +49902,10 @@ function useHidAmicoService() {
|
|
|
49837
49902
|
const hasActiveMembership = memberships.some((membership) => membership.status !== "deleted" && membership.status !== "inactive");
|
|
49838
49903
|
const resolvedIssuer = issuer || (hasResidentMembership ? "resident" : "property_management");
|
|
49839
49904
|
if (resolvedIssuer === "resident" && !hasResidentMembership) {
|
|
49840
|
-
throw new
|
|
49905
|
+
throw new UnauthorizedError11("Only a Resident account can issue a Resident visitor QR code.");
|
|
49841
49906
|
}
|
|
49842
49907
|
if (resolvedIssuer === "property_management" && !hasActiveMembership) {
|
|
49843
|
-
throw new
|
|
49908
|
+
throw new UnauthorizedError11("Only a site Property Management account can issue this visitor QR code.");
|
|
49844
49909
|
}
|
|
49845
49910
|
const configuredGateIds = site?.metadata?.hidQrCodePass?.qrGatePermissions?.[resolvedIssuer === "resident" ? "resident" : "propertyManagement"] || [];
|
|
49846
49911
|
const gateReaderIds = configuredGateIds.filter((readerId) => typeof readerId === "string" && /^[a-f0-9]{24}$/i.test(readerId)).map(String);
|
|
@@ -52433,7 +52498,7 @@ function useVisitorTransactionService() {
|
|
|
52433
52498
|
import Joi68 from "joi";
|
|
52434
52499
|
import moment5 from "moment-timezone";
|
|
52435
52500
|
import { ObjectId as ObjectId89 } from "mongodb";
|
|
52436
|
-
import { BadRequestError as BadRequestError123, NotFoundError as NotFoundError36, InternalServerError as InternalServerError44, UnauthorizedError as
|
|
52501
|
+
import { BadRequestError as BadRequestError123, NotFoundError as NotFoundError36, InternalServerError as InternalServerError44, UnauthorizedError as UnauthorizedError12, logger as logger94 } from "@7365admin1/node-server-utils";
|
|
52437
52502
|
|
|
52438
52503
|
// src/models/visitor-invite.model.ts
|
|
52439
52504
|
import Joi66 from "joi";
|
|
@@ -57217,7 +57282,7 @@ function useVisitorTransactionController() {
|
|
|
57217
57282
|
}
|
|
57218
57283
|
const inviterUserId = callerId(req);
|
|
57219
57284
|
if (!inviterUserId) {
|
|
57220
|
-
next(new
|
|
57285
|
+
next(new UnauthorizedError12("Not authorized."));
|
|
57221
57286
|
return;
|
|
57222
57287
|
}
|
|
57223
57288
|
try {
|
|
@@ -57781,7 +57846,7 @@ function useGuestManagementController() {
|
|
|
57781
57846
|
// src/controllers/person.controller.ts
|
|
57782
57847
|
import Joi71 from "joi";
|
|
57783
57848
|
import { BadRequestError as BadRequestError126, logger as logger97 } from "@7365admin1/node-server-utils";
|
|
57784
|
-
import { NotFoundError as NotFoundError37, UnauthorizedError as
|
|
57849
|
+
import { NotFoundError as NotFoundError37, UnauthorizedError as UnauthorizedError13 } from "@7365admin1/node-server-utils";
|
|
57785
57850
|
function usePersonController() {
|
|
57786
57851
|
const {
|
|
57787
57852
|
getAll: _getAll,
|
|
@@ -57815,7 +57880,7 @@ function usePersonController() {
|
|
|
57815
57880
|
}
|
|
57816
57881
|
const org = person.org?.toString() ?? "";
|
|
57817
57882
|
if (!org || !actor.orgIds.includes(org)) {
|
|
57818
|
-
throw new
|
|
57883
|
+
throw new UnauthorizedError13("Not authorized.");
|
|
57819
57884
|
}
|
|
57820
57885
|
return actor;
|
|
57821
57886
|
}
|
|
@@ -57941,7 +58006,7 @@ function usePersonController() {
|
|
|
57941
58006
|
});
|
|
57942
58007
|
} else if (org) {
|
|
57943
58008
|
if (!actor.orgIds.includes(org)) {
|
|
57944
|
-
throw new
|
|
58009
|
+
throw new UnauthorizedError13("Not authorized.");
|
|
57945
58010
|
}
|
|
57946
58011
|
} else {
|
|
57947
58012
|
orgs = actor.orgIds;
|
|
@@ -62261,7 +62326,7 @@ function useSiteFacilityService() {
|
|
|
62261
62326
|
import {
|
|
62262
62327
|
BadRequestError as BadRequestError148,
|
|
62263
62328
|
NotFoundError as NotFoundError43,
|
|
62264
|
-
UnauthorizedError as
|
|
62329
|
+
UnauthorizedError as UnauthorizedError14,
|
|
62265
62330
|
logger as logger116
|
|
62266
62331
|
} from "@7365admin1/node-server-utils";
|
|
62267
62332
|
import Joi83 from "joi";
|
|
@@ -62348,7 +62413,7 @@ function useSiteFacilityController() {
|
|
|
62348
62413
|
} else {
|
|
62349
62414
|
const { actor } = await siteReachOf(req);
|
|
62350
62415
|
if (!actor.isSuperAdmin)
|
|
62351
|
-
throw new
|
|
62416
|
+
throw new UnauthorizedError14("Not authorized.");
|
|
62352
62417
|
}
|
|
62353
62418
|
const data = await _getAll({
|
|
62354
62419
|
search,
|
|
@@ -65383,7 +65448,7 @@ function useBulletinBoardService() {
|
|
|
65383
65448
|
import {
|
|
65384
65449
|
BadRequestError as BadRequestError157,
|
|
65385
65450
|
NotFoundError as NotFoundError51,
|
|
65386
|
-
UnauthorizedError as
|
|
65451
|
+
UnauthorizedError as UnauthorizedError15,
|
|
65387
65452
|
logger as logger125
|
|
65388
65453
|
} from "@7365admin1/node-server-utils";
|
|
65389
65454
|
import Joi91 from "joi";
|
|
@@ -65419,7 +65484,7 @@ function useBulletinBoardController() {
|
|
|
65419
65484
|
} else {
|
|
65420
65485
|
const { canReach } = await siteReachOf(req);
|
|
65421
65486
|
if (!await canReach(scopeOf(value))) {
|
|
65422
|
-
throw new
|
|
65487
|
+
throw new UnauthorizedError15("Not authorized.");
|
|
65423
65488
|
}
|
|
65424
65489
|
}
|
|
65425
65490
|
const data = await _add(value);
|
|
@@ -65976,7 +66041,7 @@ import { BadRequestError as BadRequestError163, logger as logger131 } from "@736
|
|
|
65976
66041
|
import {
|
|
65977
66042
|
BadRequestError as BadRequestError162,
|
|
65978
66043
|
logger as logger130,
|
|
65979
|
-
UnauthorizedError as
|
|
66044
|
+
UnauthorizedError as UnauthorizedError16,
|
|
65980
66045
|
useAtlas as useAtlas88
|
|
65981
66046
|
} from "@7365admin1/node-server-utils";
|
|
65982
66047
|
|
|
@@ -66360,7 +66425,7 @@ function useSiteBillingItemService() {
|
|
|
66360
66425
|
function assertUnitAtSite(buildingUnit, site) {
|
|
66361
66426
|
const siteId = site?.toString?.() ?? "";
|
|
66362
66427
|
if (!siteId || (buildingUnit?.site?.toString() ?? "") !== siteId) {
|
|
66363
|
-
throw new
|
|
66428
|
+
throw new UnauthorizedError16("Not authorized.");
|
|
66364
66429
|
}
|
|
66365
66430
|
}
|
|
66366
66431
|
async function add(value) {
|
|
@@ -66531,7 +66596,7 @@ function useSiteBillingItemService() {
|
|
|
66531
66596
|
message: error.message
|
|
66532
66597
|
});
|
|
66533
66598
|
await session.abortTransaction();
|
|
66534
|
-
if (error instanceof BadRequestError162 || error instanceof
|
|
66599
|
+
if (error instanceof BadRequestError162 || error instanceof UnauthorizedError16) {
|
|
66535
66600
|
throw error;
|
|
66536
66601
|
}
|
|
66537
66602
|
throw new BadRequestError162("Failed to update Site Billing Item.");
|
|
@@ -68500,7 +68565,7 @@ import Joi99 from "joi";
|
|
|
68500
68565
|
|
|
68501
68566
|
// src/utils/resident-unit.util.ts
|
|
68502
68567
|
import { ObjectId as ObjectId123 } from "mongodb";
|
|
68503
|
-
import { UnauthorizedError as
|
|
68568
|
+
import { UnauthorizedError as UnauthorizedError17, useAtlas as useAtlas94 } from "@7365admin1/node-server-utils";
|
|
68504
68569
|
async function requireOwnUnit(req, site, unitId) {
|
|
68505
68570
|
const actor = await resolveInviteActor(callerId(req));
|
|
68506
68571
|
if (actor.isSuperAdmin)
|
|
@@ -68508,7 +68573,7 @@ async function requireOwnUnit(req, site, unitId) {
|
|
|
68508
68573
|
const unit = unitId?.toString?.() ?? "";
|
|
68509
68574
|
const siteId = site?.toString?.() ?? "";
|
|
68510
68575
|
if (!ObjectId123.isValid(unit) || !ObjectId123.isValid(siteId) || !actor.id) {
|
|
68511
|
-
throw new
|
|
68576
|
+
throw new UnauthorizedError17("Not authorized.");
|
|
68512
68577
|
}
|
|
68513
68578
|
const db2 = useAtlas94.getDb();
|
|
68514
68579
|
if (!db2)
|
|
@@ -68520,7 +68585,7 @@ async function requireOwnUnit(req, site, unitId) {
|
|
|
68520
68585
|
status: { $ne: "deleted" }
|
|
68521
68586
|
});
|
|
68522
68587
|
if (!own)
|
|
68523
|
-
throw new
|
|
68588
|
+
throw new UnauthorizedError17("Not authorized.");
|
|
68524
68589
|
}
|
|
68525
68590
|
|
|
68526
68591
|
// src/controllers/site-unit-billing.controller.ts
|
|
@@ -77072,7 +77137,7 @@ function useOnlineFormRepo() {
|
|
|
77072
77137
|
import {
|
|
77073
77138
|
BadRequestError as BadRequestError203,
|
|
77074
77139
|
NotFoundError as NotFoundError71,
|
|
77075
|
-
UnauthorizedError as
|
|
77140
|
+
UnauthorizedError as UnauthorizedError18,
|
|
77076
77141
|
logger as logger169
|
|
77077
77142
|
} from "@7365admin1/node-server-utils";
|
|
77078
77143
|
import Joi122 from "joi";
|
|
@@ -77144,10 +77209,10 @@ function useOnlineFormController() {
|
|
|
77144
77209
|
if (site) {
|
|
77145
77210
|
await requireSiteReach(req, site);
|
|
77146
77211
|
} else if (!actor.isSuperAdmin) {
|
|
77147
|
-
throw new
|
|
77212
|
+
throw new UnauthorizedError18("Not authorized.");
|
|
77148
77213
|
}
|
|
77149
77214
|
if (org && !actor.isSuperAdmin && !actor.orgIds.includes(org)) {
|
|
77150
|
-
throw new
|
|
77215
|
+
throw new UnauthorizedError18("Not authorized.");
|
|
77151
77216
|
}
|
|
77152
77217
|
const data = await _getAll({ search, page, limit, status, org, site });
|
|
77153
77218
|
res.json(data);
|
|
@@ -77212,7 +77277,7 @@ function useOnlineFormController() {
|
|
|
77212
77277
|
if (payload.org) {
|
|
77213
77278
|
const { actor } = await siteReachOf(req);
|
|
77214
77279
|
if (!actor.isSuperAdmin && !actor.orgIds.includes(payload.org)) {
|
|
77215
|
-
throw new
|
|
77280
|
+
throw new UnauthorizedError18("Not authorized.");
|
|
77216
77281
|
}
|
|
77217
77282
|
}
|
|
77218
77283
|
await _updateOnlineFormById(_id, payload);
|
|
@@ -84458,7 +84523,7 @@ import {
|
|
|
84458
84523
|
BadRequestError as BadRequestError228,
|
|
84459
84524
|
NotFoundError as NotFoundError78,
|
|
84460
84525
|
InternalServerError as InternalServerError81,
|
|
84461
|
-
UnauthorizedError as
|
|
84526
|
+
UnauthorizedError as UnauthorizedError19,
|
|
84462
84527
|
useAtlas as useAtlas131,
|
|
84463
84528
|
hashPassword as hashPassword4
|
|
84464
84529
|
} from "@7365admin1/node-server-utils";
|
|
@@ -84727,10 +84792,10 @@ function useVerificationServiceV2() {
|
|
|
84727
84792
|
const org = await getOrgById(orgId);
|
|
84728
84793
|
const actor = await resolveInviteActor(invitedBy);
|
|
84729
84794
|
if (!actor.id) {
|
|
84730
|
-
throw new
|
|
84795
|
+
throw new UnauthorizedError19("Sign in to continue.");
|
|
84731
84796
|
}
|
|
84732
84797
|
if (!actor.isSuperAdmin && !actor.orgIds.includes(orgId)) {
|
|
84733
|
-
throw new
|
|
84798
|
+
throw new UnauthorizedError19(
|
|
84734
84799
|
"You can only invite service providers to your own organisation's sites."
|
|
84735
84800
|
);
|
|
84736
84801
|
}
|
|
@@ -89133,7 +89198,7 @@ import Joi158 from "joi";
|
|
|
89133
89198
|
import { ObjectId as ObjectId178 } from "mongodb";
|
|
89134
89199
|
import {
|
|
89135
89200
|
InternalServerError as InternalServerError93,
|
|
89136
|
-
UnauthorizedError as
|
|
89201
|
+
UnauthorizedError as UnauthorizedError20,
|
|
89137
89202
|
useAtlas as useAtlas145
|
|
89138
89203
|
} from "@7365admin1/node-server-utils";
|
|
89139
89204
|
function db() {
|
|
@@ -89149,7 +89214,7 @@ function asObjectId(value) {
|
|
|
89149
89214
|
function requireCaller(req) {
|
|
89150
89215
|
const id = callerId(req);
|
|
89151
89216
|
if (!id || !ObjectId178.isValid(id)) {
|
|
89152
|
-
throw new
|
|
89217
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89153
89218
|
}
|
|
89154
89219
|
return id;
|
|
89155
89220
|
}
|
|
@@ -89157,7 +89222,7 @@ function requireSelfId(req, claimed) {
|
|
|
89157
89222
|
const caller = requireCaller(req);
|
|
89158
89223
|
const asked = claimed?.toString?.() ?? "";
|
|
89159
89224
|
if (!asked || asked !== caller) {
|
|
89160
|
-
throw new
|
|
89225
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89161
89226
|
}
|
|
89162
89227
|
return caller;
|
|
89163
89228
|
}
|
|
@@ -89165,11 +89230,11 @@ async function requireOwnChannel(req, channelId) {
|
|
|
89165
89230
|
const caller = requireCaller(req);
|
|
89166
89231
|
const _id = asObjectId(channelId);
|
|
89167
89232
|
if (!_id)
|
|
89168
|
-
throw new
|
|
89233
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89169
89234
|
const channel = await db().collection("channel-preloved").findOne({ _id }, { projection: { senderId: 1, receiverId: 1, postId: 1 } });
|
|
89170
89235
|
const participants = [channel?.senderId, channel?.receiverId].map((id) => id?.toString?.() ?? "").filter(Boolean);
|
|
89171
89236
|
if (!channel || !participants.includes(caller)) {
|
|
89172
|
-
throw new
|
|
89237
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89173
89238
|
}
|
|
89174
89239
|
return { caller, channel };
|
|
89175
89240
|
}
|
|
@@ -89177,10 +89242,10 @@ async function requireOwnChatMessage(req, chatId) {
|
|
|
89177
89242
|
const caller = requireCaller(req);
|
|
89178
89243
|
const _id = asObjectId(chatId);
|
|
89179
89244
|
if (!_id)
|
|
89180
|
-
throw new
|
|
89245
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89181
89246
|
const message = await db().collection("chat-preloved").findOne({ _id }, { projection: { senderId: 1 } });
|
|
89182
89247
|
if (!message || message.senderId?.toString?.() !== caller) {
|
|
89183
|
-
throw new
|
|
89248
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
89184
89249
|
}
|
|
89185
89250
|
return caller;
|
|
89186
89251
|
}
|
|
@@ -89606,7 +89671,7 @@ function useBidPrelovedService() {
|
|
|
89606
89671
|
// src/controllers/bid-preloved.controller.ts
|
|
89607
89672
|
import {
|
|
89608
89673
|
BadRequestError as BadRequestError251,
|
|
89609
|
-
UnauthorizedError as
|
|
89674
|
+
UnauthorizedError as UnauthorizedError21,
|
|
89610
89675
|
logger as logger212
|
|
89611
89676
|
} from "@7365admin1/node-server-utils";
|
|
89612
89677
|
import Joi161 from "joi";
|
|
@@ -89658,7 +89723,7 @@ function useBidPrelovedController() {
|
|
|
89658
89723
|
const bid = await _getById(params.id);
|
|
89659
89724
|
const seller = await sellerOfPost(bid?.postId);
|
|
89660
89725
|
if (!seller || seller !== caller) {
|
|
89661
|
-
throw new
|
|
89726
|
+
throw new UnauthorizedError21("Not authorized.");
|
|
89662
89727
|
}
|
|
89663
89728
|
const data = await _updateStatus(params.id, body.status);
|
|
89664
89729
|
res.status(200).json(data);
|
|
@@ -89682,7 +89747,7 @@ function useBidPrelovedController() {
|
|
|
89682
89747
|
const data = await _getById(params.id);
|
|
89683
89748
|
const seller = await sellerOfPost(data?.postId);
|
|
89684
89749
|
if (data?.buyerId?.toString?.() !== caller && seller !== caller) {
|
|
89685
|
-
throw new
|
|
89750
|
+
throw new UnauthorizedError21("Not authorized.");
|
|
89686
89751
|
}
|
|
89687
89752
|
res.status(200).json(data);
|
|
89688
89753
|
} catch (error2) {
|
|
@@ -90080,7 +90145,7 @@ function useFormEntryRepo() {
|
|
|
90080
90145
|
import {
|
|
90081
90146
|
BadRequestError as BadRequestError253,
|
|
90082
90147
|
NotFoundError as NotFoundError89,
|
|
90083
|
-
UnauthorizedError as
|
|
90148
|
+
UnauthorizedError as UnauthorizedError22,
|
|
90084
90149
|
logger as logger214
|
|
90085
90150
|
} from "@7365admin1/node-server-utils";
|
|
90086
90151
|
import Joi163 from "joi";
|
|
@@ -90190,7 +90255,7 @@ function useFormEntryController() {
|
|
|
90190
90255
|
} else {
|
|
90191
90256
|
const { actor } = await siteReachOf(req);
|
|
90192
90257
|
if (!actor.isSuperAdmin)
|
|
90193
|
-
throw new
|
|
90258
|
+
throw new UnauthorizedError22("Not authorized.");
|
|
90194
90259
|
}
|
|
90195
90260
|
const data = await _getAll({ search, page, limit, status, org, site });
|
|
90196
90261
|
res.json(data);
|
|
@@ -90241,7 +90306,7 @@ function useFormEntryController() {
|
|
|
90241
90306
|
await requireSiteReach(req, rest.site);
|
|
90242
90307
|
delete rest.userId;
|
|
90243
90308
|
if (isOwner && rest.status && rest.status !== "pending") {
|
|
90244
|
-
throw new
|
|
90309
|
+
throw new UnauthorizedError22("Not authorized.");
|
|
90245
90310
|
}
|
|
90246
90311
|
await _updateFormEntryById(_id, rest);
|
|
90247
90312
|
res.json({ message: "Successfully updated online form." });
|
|
@@ -90298,7 +90363,7 @@ function useFormEntryController() {
|
|
|
90298
90363
|
async function residentFormSubmission(req, res, next) {
|
|
90299
90364
|
const userId = callerId(req);
|
|
90300
90365
|
if (!userId) {
|
|
90301
|
-
next(new
|
|
90366
|
+
next(new UnauthorizedError22("Not authorized."));
|
|
90302
90367
|
return;
|
|
90303
90368
|
}
|
|
90304
90369
|
const payload = { ...req.body, userId };
|
|
@@ -91529,7 +91594,7 @@ function useHidAmicoController() {
|
|
|
91529
91594
|
import {
|
|
91530
91595
|
BadRequestError as BadRequestError256,
|
|
91531
91596
|
logger as logger216,
|
|
91532
|
-
UnauthorizedError as
|
|
91597
|
+
UnauthorizedError as UnauthorizedError23
|
|
91533
91598
|
} from "@7365admin1/node-server-utils";
|
|
91534
91599
|
import Joi165 from "joi";
|
|
91535
91600
|
function usePlatformTermsController() {
|
|
@@ -91545,7 +91610,7 @@ function usePlatformTermsController() {
|
|
|
91545
91610
|
async function requireOwnRecord(req, user, { staffMayRead = false } = {}) {
|
|
91546
91611
|
const id = callerId(req);
|
|
91547
91612
|
if (!id) {
|
|
91548
|
-
throw new
|
|
91613
|
+
throw new UnauthorizedError23("Not authorized.");
|
|
91549
91614
|
}
|
|
91550
91615
|
if (id === user) {
|
|
91551
91616
|
return id;
|
|
@@ -91553,7 +91618,7 @@ function usePlatformTermsController() {
|
|
|
91553
91618
|
if (staffMayRead) {
|
|
91554
91619
|
return await requirePlatformStaff(req);
|
|
91555
91620
|
}
|
|
91556
|
-
throw new
|
|
91621
|
+
throw new UnauthorizedError23("Not authorized.");
|
|
91557
91622
|
}
|
|
91558
91623
|
async function getLatest(_req, res, next) {
|
|
91559
91624
|
try {
|
|
@@ -91759,7 +91824,7 @@ function useConsoleAuditController() {
|
|
|
91759
91824
|
// src/controllers/notification.controller.ts
|
|
91760
91825
|
import {
|
|
91761
91826
|
BadRequestError as BadRequestError258,
|
|
91762
|
-
UnauthorizedError as
|
|
91827
|
+
UnauthorizedError as UnauthorizedError24,
|
|
91763
91828
|
logger as logger218
|
|
91764
91829
|
} from "@7365admin1/node-server-utils";
|
|
91765
91830
|
function useNotificationController() {
|
|
@@ -91777,10 +91842,10 @@ function useNotificationController() {
|
|
|
91777
91842
|
function inboxOwner(req, claimed) {
|
|
91778
91843
|
const caller = callerId5(req);
|
|
91779
91844
|
if (!caller) {
|
|
91780
|
-
throw new
|
|
91845
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
91781
91846
|
}
|
|
91782
91847
|
if (claimed && claimed !== caller) {
|
|
91783
|
-
throw new
|
|
91848
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
91784
91849
|
}
|
|
91785
91850
|
return caller;
|
|
91786
91851
|
}
|
|
@@ -91792,7 +91857,7 @@ function useNotificationController() {
|
|
|
91792
91857
|
}
|
|
91793
91858
|
try {
|
|
91794
91859
|
if (!await isSuperAdmin(callerId5(req))) {
|
|
91795
|
-
throw new
|
|
91860
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
91796
91861
|
}
|
|
91797
91862
|
const inserted = await _addMany(value.to, {
|
|
91798
91863
|
title: value.title,
|