@7365admin1/core 3.129.1 → 3.129.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 +6 -0
- package/dist/index.js +36 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -262
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/role-inventory-presets.e2e.test.mjs +175 -0
- package/test/e2e/role-template-restore.e2e.test.mjs +7 -7
- package/test/org-modules.test.mjs +21 -0
- package/test/site-modules.test.mjs +13 -0
package/dist/index.mjs
CHANGED
|
@@ -4869,7 +4869,7 @@ import {
|
|
|
4869
4869
|
BadRequestError as BadRequestError47,
|
|
4870
4870
|
NotFoundError as NotFoundError16,
|
|
4871
4871
|
InternalServerError as InternalServerError21,
|
|
4872
|
-
UnauthorizedError as
|
|
4872
|
+
UnauthorizedError as UnauthorizedError5,
|
|
4873
4873
|
useAtlas as useAtlas37
|
|
4874
4874
|
} from "@7365admin1/node-server-utils";
|
|
4875
4875
|
|
|
@@ -5359,7 +5359,7 @@ var ROBOT_CLOUD_TIMEOUT_MS = Number(
|
|
|
5359
5359
|
|
|
5360
5360
|
// src/repositories/organization.repo.ts
|
|
5361
5361
|
import {
|
|
5362
|
-
AppError as
|
|
5362
|
+
AppError as AppError4,
|
|
5363
5363
|
BadRequestError as BadRequestError21,
|
|
5364
5364
|
InternalServerError as InternalServerError9,
|
|
5365
5365
|
logger as logger11,
|
|
@@ -5449,10 +5449,25 @@ function boundToOwnerGrant(ceiling, next, previous) {
|
|
|
5449
5449
|
return { permissions: [...ceiling], refused: [] };
|
|
5450
5450
|
const held = new Set(previous ?? []);
|
|
5451
5451
|
const refused = list.filter(
|
|
5452
|
-
(p) => !held.has(p) && !ceiling
|
|
5452
|
+
(p) => !held.has(p) && !ceilingCovers(ceiling, p) && !ALWAYS_ALLOWED.includes(p.split(":")[0])
|
|
5453
5453
|
);
|
|
5454
5454
|
return { permissions: list, refused };
|
|
5455
5455
|
}
|
|
5456
|
+
var PERMISSION_COVERS = Object.freeze({
|
|
5457
|
+
"inventory:manage-inventory": ["inventory:*"],
|
|
5458
|
+
"inventory:request-stock": ["inventory:record-usage"],
|
|
5459
|
+
"inventory:view-inventory": ["inventory:view-reports"],
|
|
5460
|
+
"inventory:approve-requests": ["inventory:view-reports"]
|
|
5461
|
+
});
|
|
5462
|
+
function ceilingCovers(ceiling, permission) {
|
|
5463
|
+
if (ceiling.includes(permission))
|
|
5464
|
+
return true;
|
|
5465
|
+
const moduleWide = `${permission.split(":")[0]}:*`;
|
|
5466
|
+
return ceiling.some((granted) => {
|
|
5467
|
+
const covers = PERMISSION_COVERS[granted];
|
|
5468
|
+
return !!covers && (covers.includes(permission) || covers.includes(moduleWide));
|
|
5469
|
+
});
|
|
5470
|
+
}
|
|
5456
5471
|
|
|
5457
5472
|
// src/models/site.model.ts
|
|
5458
5473
|
import {
|
|
@@ -5462,7 +5477,7 @@ import {
|
|
|
5462
5477
|
import Joi9 from "joi";
|
|
5463
5478
|
|
|
5464
5479
|
// src/utils/site-modules.util.ts
|
|
5465
|
-
import {
|
|
5480
|
+
import { AppError as AppError3 } from "@7365admin1/node-server-utils";
|
|
5466
5481
|
var siteModulesSchema = modulesSchema;
|
|
5467
5482
|
function narrows(modules) {
|
|
5468
5483
|
return Array.isArray(modules) && modules.length > 0;
|
|
@@ -5507,6 +5522,9 @@ function permissionsOutsideModules2(effective, next, previous) {
|
|
|
5507
5522
|
if (!Array.isArray(next) || !next.length || next.includes("*"))
|
|
5508
5523
|
return [];
|
|
5509
5524
|
const held = new Set(Array.isArray(previous) ? previous : []);
|
|
5525
|
+
const heldModules = new Set(
|
|
5526
|
+
[...held].map((p) => typeof p === "string" ? p.split(":")[0]?.trim() : "").filter(Boolean)
|
|
5527
|
+
);
|
|
5510
5528
|
const allowed = normaliseModules(effective);
|
|
5511
5529
|
const refused = [];
|
|
5512
5530
|
for (const permission of next) {
|
|
@@ -5515,6 +5533,8 @@ function permissionsOutsideModules2(effective, next, previous) {
|
|
|
5515
5533
|
if (held.has(permission))
|
|
5516
5534
|
continue;
|
|
5517
5535
|
const resource = permission.split(":")[0]?.trim();
|
|
5536
|
+
if (resource && heldModules.has(resource))
|
|
5537
|
+
continue;
|
|
5518
5538
|
if (!resource)
|
|
5519
5539
|
continue;
|
|
5520
5540
|
if (!orgAllowsModule(allowed, resource))
|
|
@@ -5526,8 +5546,9 @@ function requireWithinModules(effective, next, previous) {
|
|
|
5526
5546
|
const refused = permissionsOutsideModules2(effective, next, previous);
|
|
5527
5547
|
if (!refused.length)
|
|
5528
5548
|
return;
|
|
5529
|
-
throw new
|
|
5530
|
-
"This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first."
|
|
5549
|
+
throw new AppError3(
|
|
5550
|
+
"This site has not been given " + refused.join(", ") + ". Ask Seven365 to add the module to the organisation first.",
|
|
5551
|
+
403
|
|
5531
5552
|
);
|
|
5532
5553
|
}
|
|
5533
5554
|
|
|
@@ -5930,7 +5951,7 @@ function useOrgRepo() {
|
|
|
5930
5951
|
return res.insertedId;
|
|
5931
5952
|
} catch (error) {
|
|
5932
5953
|
logger11.log({ level: "error", message: error.message });
|
|
5933
|
-
if (error instanceof
|
|
5954
|
+
if (error instanceof AppError4) {
|
|
5934
5955
|
throw error;
|
|
5935
5956
|
} else {
|
|
5936
5957
|
const isDuplicated = error.message.includes("duplicate");
|
|
@@ -5960,7 +5981,7 @@ function useOrgRepo() {
|
|
|
5960
5981
|
level: "error",
|
|
5961
5982
|
message: `Organization update failed for ${id}: ${error?.name ?? "Error"}${error?.code !== void 0 ? ` code=${error.code}` : ""}${duplicatedField(error) ? ` key=${duplicatedField(error)}` : ""} fields=[${Object.keys(value ?? {}).join(",")}] ${error?.message ?? ""}`
|
|
5962
5983
|
});
|
|
5963
|
-
if (error instanceof
|
|
5984
|
+
if (error instanceof AppError4)
|
|
5964
5985
|
throw error;
|
|
5965
5986
|
const field = duplicatedField(error);
|
|
5966
5987
|
if (field) {
|
|
@@ -6094,7 +6115,7 @@ function useOrgRepo() {
|
|
|
6094
6115
|
});
|
|
6095
6116
|
return data;
|
|
6096
6117
|
} catch (error) {
|
|
6097
|
-
if (error instanceof
|
|
6118
|
+
if (error instanceof AppError4) {
|
|
6098
6119
|
throw error;
|
|
6099
6120
|
} else {
|
|
6100
6121
|
throw new InternalServerError9("Failed to get organization.");
|
|
@@ -6120,7 +6141,7 @@ function useOrgRepo() {
|
|
|
6120
6141
|
});
|
|
6121
6142
|
return data;
|
|
6122
6143
|
} catch (error) {
|
|
6123
|
-
if (error instanceof
|
|
6144
|
+
if (error instanceof AppError4) {
|
|
6124
6145
|
throw error;
|
|
6125
6146
|
} else {
|
|
6126
6147
|
throw new InternalServerError9("Failed to get organization.");
|
|
@@ -6253,7 +6274,7 @@ function useOrgRepo() {
|
|
|
6253
6274
|
});
|
|
6254
6275
|
return "Successfully updated organization status.";
|
|
6255
6276
|
} catch (error) {
|
|
6256
|
-
if (error instanceof
|
|
6277
|
+
if (error instanceof AppError4) {
|
|
6257
6278
|
throw error;
|
|
6258
6279
|
}
|
|
6259
6280
|
throw new InternalServerError9("Failed to update organization status.");
|
|
@@ -6439,7 +6460,7 @@ function useOrgRepo() {
|
|
|
6439
6460
|
await delNamespace();
|
|
6440
6461
|
return "Successfully completed organization onboarding.";
|
|
6441
6462
|
} catch (error) {
|
|
6442
|
-
if (error instanceof
|
|
6463
|
+
if (error instanceof AppError4) {
|
|
6443
6464
|
throw error;
|
|
6444
6465
|
}
|
|
6445
6466
|
throw new InternalServerError9(
|
|
@@ -6480,7 +6501,7 @@ import {
|
|
|
6480
6501
|
useCache as useCache10,
|
|
6481
6502
|
logger as logger12,
|
|
6482
6503
|
makeCacheKey as makeCacheKey8,
|
|
6483
|
-
AppError as
|
|
6504
|
+
AppError as AppError5,
|
|
6484
6505
|
toObjectId as toObjectId3
|
|
6485
6506
|
} from "@7365admin1/node-server-utils";
|
|
6486
6507
|
import Joi11 from "joi";
|
|
@@ -6661,7 +6682,7 @@ function useSiteRepo() {
|
|
|
6661
6682
|
});
|
|
6662
6683
|
return data;
|
|
6663
6684
|
} catch (error2) {
|
|
6664
|
-
if (error2 instanceof
|
|
6685
|
+
if (error2 instanceof AppError5) {
|
|
6665
6686
|
throw error2;
|
|
6666
6687
|
}
|
|
6667
6688
|
throw new InternalServerError10("Failed to retrieve site.");
|
|
@@ -8882,7 +8903,7 @@ async function holdsRole(userId, roleId, orgId) {
|
|
|
8882
8903
|
// src/services/service-provider-invite.service.ts
|
|
8883
8904
|
import {
|
|
8884
8905
|
BadRequestError as BadRequestError46,
|
|
8885
|
-
UnauthorizedError as
|
|
8906
|
+
UnauthorizedError as UnauthorizedError4,
|
|
8886
8907
|
NotFoundError as NotFoundError15,
|
|
8887
8908
|
compileHandlebar,
|
|
8888
8909
|
getDirectory,
|
|
@@ -9092,7 +9113,7 @@ function MNotification(value) {
|
|
|
9092
9113
|
|
|
9093
9114
|
// src/repositories/notification.repo.ts
|
|
9094
9115
|
import {
|
|
9095
|
-
AppError as
|
|
9116
|
+
AppError as AppError6,
|
|
9096
9117
|
BadRequestError as BadRequestError26,
|
|
9097
9118
|
InternalServerError as InternalServerError13,
|
|
9098
9119
|
NotFoundError as NotFoundError9,
|
|
@@ -9298,7 +9319,7 @@ function useNotificationRepo() {
|
|
|
9298
9319
|
]);
|
|
9299
9320
|
return paginate11(items, page2, limit, totalCount);
|
|
9300
9321
|
} catch (error) {
|
|
9301
|
-
if (error instanceof
|
|
9322
|
+
if (error instanceof AppError6)
|
|
9302
9323
|
throw error;
|
|
9303
9324
|
logger16.log({ level: "error", message: error.message });
|
|
9304
9325
|
throw new InternalServerError13("Failed to retrieve notifications.");
|
|
@@ -9327,7 +9348,7 @@ function useNotificationRepo() {
|
|
|
9327
9348
|
}
|
|
9328
9349
|
return doc;
|
|
9329
9350
|
} catch (error) {
|
|
9330
|
-
if (error instanceof
|
|
9351
|
+
if (error instanceof AppError6)
|
|
9331
9352
|
throw error;
|
|
9332
9353
|
logger16.log({ level: "error", message: error.message });
|
|
9333
9354
|
throw new InternalServerError13("Failed to update notification.");
|
|
@@ -9350,7 +9371,7 @@ function useNotificationRepo() {
|
|
|
9350
9371
|
);
|
|
9351
9372
|
return { modifiedCount: res.modifiedCount };
|
|
9352
9373
|
} catch (error) {
|
|
9353
|
-
if (error instanceof
|
|
9374
|
+
if (error instanceof AppError6)
|
|
9354
9375
|
throw error;
|
|
9355
9376
|
logger16.log({ level: "error", message: error.message });
|
|
9356
9377
|
throw new InternalServerError13("Failed to update notifications.");
|
|
@@ -9386,7 +9407,7 @@ function useNotificationRepo() {
|
|
|
9386
9407
|
// src/repositories/notification-preference.repo.ts
|
|
9387
9408
|
import { ObjectId as ObjectId30 } from "mongodb";
|
|
9388
9409
|
import {
|
|
9389
|
-
AppError as
|
|
9410
|
+
AppError as AppError7,
|
|
9390
9411
|
BadRequestError as BadRequestError28,
|
|
9391
9412
|
InternalServerError as InternalServerError14,
|
|
9392
9413
|
logger as logger17,
|
|
@@ -9877,7 +9898,7 @@ function useNotificationPreferenceRepo() {
|
|
|
9877
9898
|
const doc = await collection().findOne({ userId: new ObjectId30(userId) });
|
|
9878
9899
|
return doc?.off ?? [];
|
|
9879
9900
|
} catch (error) {
|
|
9880
|
-
if (error instanceof
|
|
9901
|
+
if (error instanceof AppError7)
|
|
9881
9902
|
throw error;
|
|
9882
9903
|
logger17.log({ level: "error", message: error.message });
|
|
9883
9904
|
throw new InternalServerError14("Failed to retrieve notification settings.");
|
|
@@ -9905,7 +9926,7 @@ function useNotificationPreferenceRepo() {
|
|
|
9905
9926
|
);
|
|
9906
9927
|
return doc.off;
|
|
9907
9928
|
} catch (error) {
|
|
9908
|
-
if (error instanceof
|
|
9929
|
+
if (error instanceof AppError7)
|
|
9909
9930
|
throw error;
|
|
9910
9931
|
logger17.log({ level: "error", message: error.message });
|
|
9911
9932
|
throw new InternalServerError14("Failed to save notification settings.");
|
|
@@ -13912,7 +13933,7 @@ function useCustomerSiteService() {
|
|
|
13912
13933
|
// src/utils/console-authz.util.ts
|
|
13913
13934
|
import {
|
|
13914
13935
|
BadRequestError as BadRequestError45,
|
|
13915
|
-
UnauthorizedError as
|
|
13936
|
+
UnauthorizedError as UnauthorizedError3,
|
|
13916
13937
|
useAtlas as useAtlas36
|
|
13917
13938
|
} from "@7365admin1/node-server-utils";
|
|
13918
13939
|
import { ObjectId as ObjectId54 } from "mongodb";
|
|
@@ -14030,15 +14051,15 @@ function assignRoleRefusal(role, member) {
|
|
|
14030
14051
|
}
|
|
14031
14052
|
|
|
14032
14053
|
// src/utils/site-reach.util.ts
|
|
14033
|
-
import { useAtlas as useAtlas35, UnauthorizedError as
|
|
14054
|
+
import { useAtlas as useAtlas35, UnauthorizedError as UnauthorizedError2 } from "@7365admin1/node-server-utils";
|
|
14034
14055
|
import { ObjectId as ObjectId53 } from "mongodb";
|
|
14035
14056
|
|
|
14036
14057
|
// src/services/camera-view.service.ts
|
|
14037
14058
|
import {
|
|
14038
|
-
AppError as
|
|
14059
|
+
AppError as AppError11,
|
|
14039
14060
|
BadRequestError as BadRequestError44,
|
|
14040
14061
|
NotFoundError as NotFoundError14,
|
|
14041
|
-
UnauthorizedError
|
|
14062
|
+
UnauthorizedError,
|
|
14042
14063
|
logger as logger33,
|
|
14043
14064
|
useAtlas as useAtlas34,
|
|
14044
14065
|
useCache as useCache19
|
|
@@ -14049,7 +14070,7 @@ import { ObjectId as ObjectId52 } from "mongodb";
|
|
|
14049
14070
|
|
|
14050
14071
|
// src/repositories/site-camera.repo.ts
|
|
14051
14072
|
import {
|
|
14052
|
-
AppError as
|
|
14073
|
+
AppError as AppError10,
|
|
14053
14074
|
BadRequestError as BadRequestError43,
|
|
14054
14075
|
logger as logger32,
|
|
14055
14076
|
makeCacheKey as makeCacheKey15,
|
|
@@ -16162,7 +16183,7 @@ function useVisitorTransactionRepo() {
|
|
|
16162
16183
|
|
|
16163
16184
|
// src/repositories/vehicle.repo.ts
|
|
16164
16185
|
import {
|
|
16165
|
-
AppError as
|
|
16186
|
+
AppError as AppError8,
|
|
16166
16187
|
BadRequestError as BadRequestError40,
|
|
16167
16188
|
InternalServerError as InternalServerError19,
|
|
16168
16189
|
logger as logger29,
|
|
@@ -16583,7 +16604,7 @@ function useVehicleRepo() {
|
|
|
16583
16604
|
level: "error",
|
|
16584
16605
|
message: error.message
|
|
16585
16606
|
});
|
|
16586
|
-
if (error instanceof
|
|
16607
|
+
if (error instanceof AppError8) {
|
|
16587
16608
|
throw error;
|
|
16588
16609
|
} else {
|
|
16589
16610
|
throw new Error("Failed to create vehicle.");
|
|
@@ -17565,7 +17586,7 @@ function useVehicleRepo() {
|
|
|
17565
17586
|
level: "error",
|
|
17566
17587
|
message: error.message
|
|
17567
17588
|
});
|
|
17568
|
-
if (error instanceof
|
|
17589
|
+
if (error instanceof AppError8) {
|
|
17569
17590
|
throw error;
|
|
17570
17591
|
}
|
|
17571
17592
|
throw new Error("Failed to bulk upsert vehicles.");
|
|
@@ -17731,7 +17752,7 @@ import {
|
|
|
17731
17752
|
makeCacheKey as makeCacheKey14,
|
|
17732
17753
|
useAtlas as useAtlas30,
|
|
17733
17754
|
useCache as useCache17,
|
|
17734
|
-
AppError as
|
|
17755
|
+
AppError as AppError9
|
|
17735
17756
|
} from "@7365admin1/node-server-utils";
|
|
17736
17757
|
|
|
17737
17758
|
// src/models/file.model.ts
|
|
@@ -17884,7 +17905,7 @@ function useFileRepo() {
|
|
|
17884
17905
|
});
|
|
17885
17906
|
return result;
|
|
17886
17907
|
} catch (error) {
|
|
17887
|
-
if (error instanceof
|
|
17908
|
+
if (error instanceof AppError9) {
|
|
17888
17909
|
throw error;
|
|
17889
17910
|
} else {
|
|
17890
17911
|
throw new InternalServerError20("Failed to get file by id.");
|
|
@@ -19777,7 +19798,7 @@ function useSiteCameraRepo() {
|
|
|
19777
19798
|
if (isDuplicated) {
|
|
19778
19799
|
throw new BadRequestError43("ANPR already exist.");
|
|
19779
19800
|
}
|
|
19780
|
-
if (error instanceof
|
|
19801
|
+
if (error instanceof AppError10) {
|
|
19781
19802
|
throw error;
|
|
19782
19803
|
} else {
|
|
19783
19804
|
throw new Error("Failed to create ANPR.");
|
|
@@ -20102,7 +20123,7 @@ function useSiteCameraRepo() {
|
|
|
20102
20123
|
if (isDuplicated) {
|
|
20103
20124
|
throw new BadRequestError43("ANPR already exist.");
|
|
20104
20125
|
}
|
|
20105
|
-
if (error2 instanceof
|
|
20126
|
+
if (error2 instanceof AppError10) {
|
|
20106
20127
|
throw error2;
|
|
20107
20128
|
}
|
|
20108
20129
|
throw new Error("Failed to update ANPR.");
|
|
@@ -20125,7 +20146,7 @@ function useSiteCameraRepo() {
|
|
|
20125
20146
|
level: "error",
|
|
20126
20147
|
message: error.message
|
|
20127
20148
|
});
|
|
20128
|
-
if (error instanceof
|
|
20149
|
+
if (error instanceof AppError10) {
|
|
20129
20150
|
throw error;
|
|
20130
20151
|
}
|
|
20131
20152
|
throw new Error("Failed to delete site camera.");
|
|
@@ -22054,7 +22075,7 @@ function useCameraViewService() {
|
|
|
22054
22075
|
}
|
|
22055
22076
|
async function authorizeCamera(params) {
|
|
22056
22077
|
if (!params.userId || !ObjectId52.isValid(params.userId)) {
|
|
22057
|
-
throw new
|
|
22078
|
+
throw new UnauthorizedError("Not signed in.");
|
|
22058
22079
|
}
|
|
22059
22080
|
if (!ObjectId52.isValid(params.cameraId)) {
|
|
22060
22081
|
throw new BadRequestError44("Invalid camera id.");
|
|
@@ -22083,7 +22104,7 @@ function useCameraViewService() {
|
|
|
22083
22104
|
memberships
|
|
22084
22105
|
);
|
|
22085
22106
|
if (!hasAnyPermission(permissions, params.permissions)) {
|
|
22086
|
-
throw new
|
|
22107
|
+
throw new UnauthorizedError(
|
|
22087
22108
|
"You do not have permission to use this camera."
|
|
22088
22109
|
);
|
|
22089
22110
|
}
|
|
@@ -22191,7 +22212,7 @@ function useCameraViewService() {
|
|
|
22191
22212
|
}
|
|
22192
22213
|
async function entitleSite(params) {
|
|
22193
22214
|
if (!params.userId || !ObjectId52.isValid(params.userId)) {
|
|
22194
|
-
throw new
|
|
22215
|
+
throw new UnauthorizedError("Not signed in.");
|
|
22195
22216
|
}
|
|
22196
22217
|
if (!ObjectId52.isValid(params.siteId)) {
|
|
22197
22218
|
throw new BadRequestError44("Invalid site id.");
|
|
@@ -22224,7 +22245,7 @@ function useCameraViewService() {
|
|
|
22224
22245
|
);
|
|
22225
22246
|
const required = params.permissions ?? CAMERA_VIEW_PERMISSIONS;
|
|
22226
22247
|
if (!hasAnyPermission(permissions, required)) {
|
|
22227
|
-
throw new
|
|
22248
|
+
throw new UnauthorizedError(
|
|
22228
22249
|
params.message ?? (required === CAMERA_VIEW_PERMISSIONS ? "You do not have permission to view these cameras." : "You do not have permission to set up cameras on this site.")
|
|
22229
22250
|
);
|
|
22230
22251
|
}
|
|
@@ -22615,8 +22636,8 @@ function useCameraViewService() {
|
|
|
22615
22636
|
permissions: CAMERA_RECORDINGS_PERMISSIONS
|
|
22616
22637
|
});
|
|
22617
22638
|
} catch (error) {
|
|
22618
|
-
if (error instanceof
|
|
22619
|
-
throw new
|
|
22639
|
+
if (error instanceof UnauthorizedError && params.userId && ObjectId52.isValid(params.userId)) {
|
|
22640
|
+
throw new AppError11("You do not have permission to watch recorded footage.", 403);
|
|
22620
22641
|
}
|
|
22621
22642
|
throw error;
|
|
22622
22643
|
}
|
|
@@ -22628,7 +22649,7 @@ function useCameraViewService() {
|
|
|
22628
22649
|
const key = playbackKeys[authority];
|
|
22629
22650
|
const link = capabilities.playback.state === "supported" && key ? signPlaybackLink({ host: camera.host, key, start: params.start, end: params.end }) : null;
|
|
22630
22651
|
if (!link) {
|
|
22631
|
-
throw new
|
|
22652
|
+
throw new AppError11(
|
|
22632
22653
|
capabilities.playback.detail ?? "Recorded footage is not set up for this camera yet.",
|
|
22633
22654
|
409
|
|
22634
22655
|
);
|
|
@@ -22680,7 +22701,7 @@ function membershipPreferenceOf(req) {
|
|
|
22680
22701
|
async function requireSiteReach(req, site, permission) {
|
|
22681
22702
|
const siteId = site?.toString?.() ?? "";
|
|
22682
22703
|
if (!siteId)
|
|
22683
|
-
throw new
|
|
22704
|
+
throw new UnauthorizedError2("Not authorized.");
|
|
22684
22705
|
const actor = await resolveInviteActor(callerId(req));
|
|
22685
22706
|
if (staffMayBypass(actor))
|
|
22686
22707
|
return;
|
|
@@ -22795,10 +22816,10 @@ async function requirePlatformStaff(req, grant) {
|
|
|
22795
22816
|
const id = callerId(req);
|
|
22796
22817
|
const role = id ? await resolveStaffRole(id) : null;
|
|
22797
22818
|
if (!role) {
|
|
22798
|
-
throw new
|
|
22819
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22799
22820
|
}
|
|
22800
22821
|
if (grant && !consoleRoleAllows(role.permissions, grant.resource, grant.action)) {
|
|
22801
|
-
throw new
|
|
22822
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22802
22823
|
}
|
|
22803
22824
|
return id;
|
|
22804
22825
|
}
|
|
@@ -22818,7 +22839,7 @@ async function requireOrgAccess(req, orgId) {
|
|
|
22818
22839
|
async function requirePlatformOwner(req, grant) {
|
|
22819
22840
|
const id = callerId(req);
|
|
22820
22841
|
if (!id || !await isPlatformOwner(id)) {
|
|
22821
|
-
throw new
|
|
22842
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22822
22843
|
}
|
|
22823
22844
|
if (grant)
|
|
22824
22845
|
await requirePlatformStaff(req, grant);
|
|
@@ -22827,7 +22848,7 @@ async function requirePlatformOwner(req, grant) {
|
|
|
22827
22848
|
async function requireOrgReach(req, orgId) {
|
|
22828
22849
|
const id = callerId(req);
|
|
22829
22850
|
if (!id)
|
|
22830
|
-
throw new
|
|
22851
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22831
22852
|
const org = orgId?.toString() ?? "";
|
|
22832
22853
|
const actor = await resolveInviteActor(id);
|
|
22833
22854
|
if (staffMayBypass(actor))
|
|
@@ -22838,7 +22859,7 @@ async function requireOrgReach(req, orgId) {
|
|
|
22838
22859
|
return id;
|
|
22839
22860
|
if (org && await hasOrgOwnership(id, org))
|
|
22840
22861
|
return id;
|
|
22841
|
-
throw new
|
|
22862
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22842
22863
|
}
|
|
22843
22864
|
async function requireSelfEnrolRole(req, orgId, roleId) {
|
|
22844
22865
|
const id = callerId(req);
|
|
@@ -22852,7 +22873,7 @@ async function requireSelfEnrolRole(req, orgId, roleId) {
|
|
|
22852
22873
|
return;
|
|
22853
22874
|
if (await invitationOffersRole(id, org, role))
|
|
22854
22875
|
return;
|
|
22855
|
-
throw new
|
|
22876
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22856
22877
|
}
|
|
22857
22878
|
async function canReadOrgRecord(req, orgId) {
|
|
22858
22879
|
const id = callerId(req);
|
|
@@ -22919,7 +22940,7 @@ async function requireInviteReach(req, org, app, role, site) {
|
|
|
22919
22940
|
await requireSiteServedByOrg(site, org);
|
|
22920
22941
|
await requireSiteReachInOrg(req, site, org);
|
|
22921
22942
|
} else if (org && await pinnedSitesIn(req, org) !== null) {
|
|
22922
|
-
throw new
|
|
22943
|
+
throw new UnauthorizedError3(
|
|
22923
22944
|
"Your access is limited to your site. Invite people from that site's Invitations page."
|
|
22924
22945
|
);
|
|
22925
22946
|
}
|
|
@@ -22976,13 +22997,13 @@ async function requireRoleAssignable(req, member, role, app) {
|
|
|
22976
22997
|
async function requireSiteAccessEditor(req, orgId) {
|
|
22977
22998
|
const id = callerId(req);
|
|
22978
22999
|
if (!id)
|
|
22979
|
-
throw new
|
|
23000
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
22980
23001
|
if (staffMayBypass(await resolveInviteActor(id)))
|
|
22981
23002
|
return id;
|
|
22982
23003
|
if (await hasOrgOwnership(id, orgId))
|
|
22983
23004
|
return id;
|
|
22984
23005
|
if (await pinnedSitesIn(req, orgId) !== null) {
|
|
22985
|
-
throw new
|
|
23006
|
+
throw new UnauthorizedError3("Only the organisation's owner or an organisation admin can change site access.");
|
|
22986
23007
|
}
|
|
22987
23008
|
return await requireRoleAssigner(req, orgId);
|
|
22988
23009
|
}
|
|
@@ -22994,7 +23015,7 @@ async function requireNotOwnerUnlessOwner(req, orgId, targetUser) {
|
|
|
22994
23015
|
return;
|
|
22995
23016
|
if (staffMayBypass(await resolveInviteActor(id)))
|
|
22996
23017
|
return;
|
|
22997
|
-
throw new
|
|
23018
|
+
throw new UnauthorizedError3("Only the organisation's owner can change the owner's access.");
|
|
22998
23019
|
}
|
|
22999
23020
|
async function requireSiteReachInOrg(req, siteId, orgId) {
|
|
23000
23021
|
if (await hasOrgOwnership(callerId(req), orgId)) {
|
|
@@ -23056,7 +23077,7 @@ async function requireVerificationReach(req, verification) {
|
|
|
23056
23077
|
if (site) {
|
|
23057
23078
|
await requireSiteReachInOrg(req, site, org);
|
|
23058
23079
|
} else if (await pinnedSitesIn(req, org) !== null) {
|
|
23059
|
-
throw new
|
|
23080
|
+
throw new UnauthorizedError3(
|
|
23060
23081
|
"This invitation was sent from the organisation, not your site."
|
|
23061
23082
|
);
|
|
23062
23083
|
}
|
|
@@ -23064,13 +23085,13 @@ async function requireVerificationReach(req, verification) {
|
|
|
23064
23085
|
async function requireRoleAssigner(req, orgId) {
|
|
23065
23086
|
const id = callerId(req);
|
|
23066
23087
|
if (!id)
|
|
23067
|
-
throw new
|
|
23088
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
23068
23089
|
const actor = await resolveInviteActor(id);
|
|
23069
23090
|
if (staffMayBypass(actor))
|
|
23070
23091
|
return id;
|
|
23071
23092
|
const org = orgId?.toString() ?? "";
|
|
23072
23093
|
if (!org || !ObjectId54.isValid(org) || !ObjectId54.isValid(id)) {
|
|
23073
|
-
throw new
|
|
23094
|
+
throw new UnauthorizedError3("Not authorized.");
|
|
23074
23095
|
}
|
|
23075
23096
|
if (await hasOrgOwnership(id, org))
|
|
23076
23097
|
return id;
|
|
@@ -23095,7 +23116,7 @@ async function requireRoleAssigner(req, orgId) {
|
|
|
23095
23116
|
return id;
|
|
23096
23117
|
}
|
|
23097
23118
|
}
|
|
23098
|
-
throw new
|
|
23119
|
+
throw new UnauthorizedError3("You do not have permission to assign roles.");
|
|
23099
23120
|
}
|
|
23100
23121
|
|
|
23101
23122
|
// src/services/service-provider-invite.service.ts
|
|
@@ -23137,7 +23158,7 @@ async function assertServiceProviderInviteScope(actor, orgId, siteId) {
|
|
|
23137
23158
|
)
|
|
23138
23159
|
});
|
|
23139
23160
|
if (!scope.ok)
|
|
23140
|
-
throw new
|
|
23161
|
+
throw new UnauthorizedError4(scope.reason);
|
|
23141
23162
|
return { sender: scope.sender, siteOwnerOrg };
|
|
23142
23163
|
}
|
|
23143
23164
|
function useServiceProviderInviteService() {
|
|
@@ -23235,13 +23256,13 @@ function useServiceProviderInviteService() {
|
|
|
23235
23256
|
const org = inviteOrgId(invite);
|
|
23236
23257
|
if (org && actor.orgIds.includes(org))
|
|
23237
23258
|
return;
|
|
23238
|
-
throw new
|
|
23259
|
+
throw new UnauthorizedError4(
|
|
23239
23260
|
"This invitation belongs to another organisation."
|
|
23240
23261
|
);
|
|
23241
23262
|
}
|
|
23242
23263
|
function assertSuperAdmin(actor) {
|
|
23243
23264
|
if (!staffMayBypass(actor)) {
|
|
23244
|
-
throw new
|
|
23265
|
+
throw new UnauthorizedError4(
|
|
23245
23266
|
"Only a Seven365 administrator can approve or reject invitations."
|
|
23246
23267
|
);
|
|
23247
23268
|
}
|
|
@@ -23254,7 +23275,7 @@ function useServiceProviderInviteService() {
|
|
|
23254
23275
|
async function actorFor(userId) {
|
|
23255
23276
|
const actor = await resolveInviteActor(userId);
|
|
23256
23277
|
if (!actor.id)
|
|
23257
|
-
throw new
|
|
23278
|
+
throw new UnauthorizedError4("Sign in to continue.");
|
|
23258
23279
|
return actor;
|
|
23259
23280
|
}
|
|
23260
23281
|
async function listApprovals({
|
|
@@ -23335,7 +23356,7 @@ function useServiceProviderInviteService() {
|
|
|
23335
23356
|
let scope = actor.orgIds;
|
|
23336
23357
|
if (orgId) {
|
|
23337
23358
|
if (!staffMayBypass(actor) && !actor.orgIds.includes(orgId)) {
|
|
23338
|
-
throw new
|
|
23359
|
+
throw new UnauthorizedError4(
|
|
23339
23360
|
"You are not a member of that organisation."
|
|
23340
23361
|
);
|
|
23341
23362
|
}
|
|
@@ -23563,7 +23584,7 @@ function useServiceProviderInviteService() {
|
|
|
23563
23584
|
);
|
|
23564
23585
|
const invitedUserId = user?._id?.toString();
|
|
23565
23586
|
if (!invitedUserId || invitedUserId !== userId) {
|
|
23566
|
-
throw new
|
|
23587
|
+
throw new UnauthorizedError4("This invitation was sent to someone else.");
|
|
23567
23588
|
}
|
|
23568
23589
|
}
|
|
23569
23590
|
async function decline({ id, userId }) {
|
|
@@ -23667,7 +23688,7 @@ function useServiceProviderInviteService() {
|
|
|
23667
23688
|
(m) => m.org === id && (m.companyWideRole === true || !m.siteId && m.orgLevelRole === true)
|
|
23668
23689
|
);
|
|
23669
23690
|
if (!runs) {
|
|
23670
|
-
throw new
|
|
23691
|
+
throw new UnauthorizedError4(
|
|
23671
23692
|
"Only an administrator of that company can answer this invitation for it."
|
|
23672
23693
|
);
|
|
23673
23694
|
}
|
|
@@ -24107,7 +24128,7 @@ function useVerificationService() {
|
|
|
24107
24128
|
const org = await getOrgById(orgId);
|
|
24108
24129
|
const actor = await resolveInviteActor(invitedBy);
|
|
24109
24130
|
if (!actor.id) {
|
|
24110
|
-
throw new
|
|
24131
|
+
throw new UnauthorizedError5("Sign in to continue.");
|
|
24111
24132
|
}
|
|
24112
24133
|
const { sender } = await assertServiceProviderInviteScope(
|
|
24113
24134
|
actor,
|
|
@@ -25392,7 +25413,7 @@ import {
|
|
|
25392
25413
|
paginate as paginate19,
|
|
25393
25414
|
useAtlas as useAtlas40,
|
|
25394
25415
|
useCache as useCache21,
|
|
25395
|
-
AppError as
|
|
25416
|
+
AppError as AppError12,
|
|
25396
25417
|
toObjectId as toObjectId9
|
|
25397
25418
|
} from "@7365admin1/node-server-utils";
|
|
25398
25419
|
import { ObjectId as ObjectId58 } from "mongodb";
|
|
@@ -25737,7 +25758,7 @@ function usePersonRepo() {
|
|
|
25737
25758
|
});
|
|
25738
25759
|
return result;
|
|
25739
25760
|
} catch (error) {
|
|
25740
|
-
if (error instanceof
|
|
25761
|
+
if (error instanceof AppError12) {
|
|
25741
25762
|
throw error;
|
|
25742
25763
|
} else {
|
|
25743
25764
|
throw new InternalServerError24("Failed to get person by id.");
|
|
@@ -26169,7 +26190,7 @@ function usePersonRepo() {
|
|
|
26169
26190
|
});
|
|
26170
26191
|
return result;
|
|
26171
26192
|
} catch (error) {
|
|
26172
|
-
if (error instanceof
|
|
26193
|
+
if (error instanceof AppError12) {
|
|
26173
26194
|
throw error;
|
|
26174
26195
|
} else {
|
|
26175
26196
|
throw new InternalServerError24("Failed to get person by user.");
|
|
@@ -26780,7 +26801,7 @@ function useRoleService() {
|
|
|
26780
26801
|
}
|
|
26781
26802
|
|
|
26782
26803
|
// src/utils/role-scope.util.ts
|
|
26783
|
-
import {
|
|
26804
|
+
import { AppError as AppError13 } from "@7365admin1/node-server-utils";
|
|
26784
26805
|
function roleScope(role) {
|
|
26785
26806
|
if ((role?.type ?? "") === PLATFORM_STAFF_ROLE_TYPE)
|
|
26786
26807
|
return "platform";
|
|
@@ -26814,8 +26835,9 @@ function requireNoPlatformGrant(role, next) {
|
|
|
26814
26835
|
const added = platformPermissionsAdded(next, role?.permissions);
|
|
26815
26836
|
if (added.length === 0)
|
|
26816
26837
|
return;
|
|
26817
|
-
throw new
|
|
26818
|
-
"These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", ")
|
|
26838
|
+
throw new AppError13(
|
|
26839
|
+
"These are Seven365 console permissions and cannot be granted on a client role: " + added.join(", "),
|
|
26840
|
+
403
|
|
26819
26841
|
);
|
|
26820
26842
|
}
|
|
26821
26843
|
function permissionsMeanEverything(permissions) {
|
|
@@ -26828,15 +26850,17 @@ function refuseSharedClientTemplate(role, next) {
|
|
|
26828
26850
|
return true;
|
|
26829
26851
|
if (Array.isArray(next) && restorableFromHistory(role, next))
|
|
26830
26852
|
return true;
|
|
26831
|
-
throw new
|
|
26832
|
-
"This role is shared by every client that was invited with it and cannot be changed here."
|
|
26853
|
+
throw new AppError13(
|
|
26854
|
+
"This role is shared by every client that was invited with it and cannot be changed here.",
|
|
26855
|
+
403
|
|
26833
26856
|
);
|
|
26834
26857
|
}
|
|
26835
26858
|
function refuseNewSharedClientTemplate(role) {
|
|
26836
26859
|
if (roleScope(role) !== "client-template")
|
|
26837
26860
|
return;
|
|
26838
|
-
throw new
|
|
26839
|
-
"A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to."
|
|
26861
|
+
throw new AppError13(
|
|
26862
|
+
"A role with no organisation would be shared by every client and cannot be created. Choose the organisation this role belongs to.",
|
|
26863
|
+
403
|
|
26840
26864
|
);
|
|
26841
26865
|
}
|
|
26842
26866
|
function samePermissionSet(a, b) {
|
|
@@ -26980,7 +27004,7 @@ function clientInviteOwnerPermissionsOn(env2 = process.env) {
|
|
|
26980
27004
|
}
|
|
26981
27005
|
|
|
26982
27006
|
// src/utils/module-ceiling.util.ts
|
|
26983
|
-
import {
|
|
27007
|
+
import { AppError as AppError14 } from "@7365admin1/node-server-utils";
|
|
26984
27008
|
async function moduleCeiling(org, site) {
|
|
26985
27009
|
const orgId = org?.toString() ?? "";
|
|
26986
27010
|
const siteId = site?.toString() ?? "";
|
|
@@ -27031,8 +27055,9 @@ async function boundRoleToOwnerGrant(req, role, next, previous) {
|
|
|
27031
27055
|
return list;
|
|
27032
27056
|
const { permissions, refused } = boundToOwnerGrant(ceiling, list, previous);
|
|
27033
27057
|
if (refused.length) {
|
|
27034
|
-
throw new
|
|
27035
|
-
"Seven365 has not given this organisation " + refused.join(", ") + "."
|
|
27058
|
+
throw new AppError14(
|
|
27059
|
+
"Seven365 has not given this organisation " + refused.join(", ") + ".",
|
|
27060
|
+
403
|
|
27036
27061
|
);
|
|
27037
27062
|
}
|
|
27038
27063
|
return permissions;
|
|
@@ -27436,18 +27461,18 @@ function useRoleController() {
|
|
|
27436
27461
|
|
|
27437
27462
|
// src/controllers/member.controller.ts
|
|
27438
27463
|
import Joi29 from "joi";
|
|
27439
|
-
import { BadRequestError as BadRequestError57, logger as logger43, UnauthorizedError as
|
|
27464
|
+
import { BadRequestError as BadRequestError57, logger as logger43, UnauthorizedError as UnauthorizedError8 } from "@7365admin1/node-server-utils";
|
|
27440
27465
|
|
|
27441
27466
|
// src/services/member.service.ts
|
|
27442
27467
|
import {
|
|
27443
27468
|
BadRequestError as BadRequestError55,
|
|
27444
|
-
UnauthorizedError as
|
|
27469
|
+
UnauthorizedError as UnauthorizedError6,
|
|
27445
27470
|
useAtlas as useAtlas43
|
|
27446
27471
|
} from "@7365admin1/node-server-utils";
|
|
27447
27472
|
import { ObjectId as ObjectId60 } from "mongodb";
|
|
27448
27473
|
async function requireStaffCaller(callerId5, what) {
|
|
27449
27474
|
if (!await isSuperAdmin(callerId5)) {
|
|
27450
|
-
throw new
|
|
27475
|
+
throw new UnauthorizedError6(
|
|
27451
27476
|
`Only Seven365 staff can ${what}.`
|
|
27452
27477
|
);
|
|
27453
27478
|
}
|
|
@@ -27683,7 +27708,7 @@ function useMemberService() {
|
|
|
27683
27708
|
}
|
|
27684
27709
|
|
|
27685
27710
|
// src/services/member-site-access.service.ts
|
|
27686
|
-
import { BadRequestError as BadRequestError56, UnauthorizedError as
|
|
27711
|
+
import { BadRequestError as BadRequestError56, UnauthorizedError as UnauthorizedError7, useAtlas as useAtlas44 } from "@7365admin1/node-server-utils";
|
|
27687
27712
|
import { ObjectId as ObjectId61 } from "mongodb";
|
|
27688
27713
|
var EXCLUDED_TYPES = ["resident", PLATFORM_STAFF_MEMBER_TYPE];
|
|
27689
27714
|
var both = (id) => [id, new ObjectId61(id)];
|
|
@@ -27756,7 +27781,7 @@ function useMemberSiteAccessService() {
|
|
|
27756
27781
|
actor
|
|
27757
27782
|
}) {
|
|
27758
27783
|
if (user === actor)
|
|
27759
|
-
throw new
|
|
27784
|
+
throw new UnauthorizedError7("You cannot change your own site access.");
|
|
27760
27785
|
const current = await get({ org, user });
|
|
27761
27786
|
const known = new Map(current.sites.map((s) => [s.site, s]));
|
|
27762
27787
|
const seen2 = /* @__PURE__ */ new Set();
|
|
@@ -28097,7 +28122,7 @@ function useMemberController() {
|
|
|
28097
28122
|
const scope = staffMayBypass(actor) ? null : memberListSiteScope(actor.memberships, org);
|
|
28098
28123
|
if (scope) {
|
|
28099
28124
|
if (siteId && !scope.includes(siteId.toLowerCase())) {
|
|
28100
|
-
throw new
|
|
28125
|
+
throw new UnauthorizedError8("Not authorized.");
|
|
28101
28126
|
}
|
|
28102
28127
|
if (!siteId)
|
|
28103
28128
|
siteIds = scope;
|
|
@@ -29006,7 +29031,7 @@ function useVerificationController() {
|
|
|
29006
29031
|
// src/controllers/file.controller.ts
|
|
29007
29032
|
import {
|
|
29008
29033
|
BadRequestError as BadRequestError59,
|
|
29009
|
-
UnauthorizedError as
|
|
29034
|
+
UnauthorizedError as UnauthorizedError9,
|
|
29010
29035
|
logger as logger45
|
|
29011
29036
|
} from "@7365admin1/node-server-utils";
|
|
29012
29037
|
import Joi31 from "joi";
|
|
@@ -29035,7 +29060,7 @@ async function requireFileDelete(req, file) {
|
|
|
29035
29060
|
return;
|
|
29036
29061
|
const caller = callerId(req);
|
|
29037
29062
|
if (!caller)
|
|
29038
|
-
throw new
|
|
29063
|
+
throw new UnauthorizedError9("Not authorized.");
|
|
29039
29064
|
if (caller === ownerId)
|
|
29040
29065
|
return;
|
|
29041
29066
|
const [me, owner] = await Promise.all([
|
|
@@ -29051,7 +29076,7 @@ async function requireFileDelete(req, file) {
|
|
|
29051
29076
|
})) {
|
|
29052
29077
|
return;
|
|
29053
29078
|
}
|
|
29054
|
-
throw new
|
|
29079
|
+
throw new UnauthorizedError9("Not authorized.");
|
|
29055
29080
|
}
|
|
29056
29081
|
function useFileController() {
|
|
29057
29082
|
const { createFile, deleteFile: _deleteFile } = useFileService();
|
|
@@ -29121,11 +29146,11 @@ function useFileController() {
|
|
|
29121
29146
|
|
|
29122
29147
|
// src/controllers/organization.controller.ts
|
|
29123
29148
|
import {
|
|
29124
|
-
AppError as
|
|
29149
|
+
AppError as AppError15,
|
|
29125
29150
|
BadRequestError as BadRequestError62,
|
|
29126
29151
|
logger as logger47,
|
|
29127
29152
|
NotFoundError as NotFoundError20,
|
|
29128
|
-
UnauthorizedError as
|
|
29153
|
+
UnauthorizedError as UnauthorizedError10
|
|
29129
29154
|
} from "@7365admin1/node-server-utils";
|
|
29130
29155
|
import Joi34 from "joi";
|
|
29131
29156
|
import { ObjectId as ObjectId65 } from "mongodb";
|
|
@@ -30148,7 +30173,7 @@ function orgModulesHandlers({
|
|
|
30148
30173
|
const residentAppModules = req.body.residentAppModules;
|
|
30149
30174
|
const preview = await orgModulePreview(await _getById(orgId), modules, gateData);
|
|
30150
30175
|
if (mustAcknowledge(preview, req.body.acknowledgeImpact)) {
|
|
30151
|
-
next(new
|
|
30176
|
+
next(new AppError15(impactUnacknowledgedMessage(preview), 409));
|
|
30152
30177
|
return;
|
|
30153
30178
|
}
|
|
30154
30179
|
await _update(orgId, {
|
|
@@ -30437,7 +30462,7 @@ function useOrgController() {
|
|
|
30437
30462
|
try {
|
|
30438
30463
|
const createdBy = callerId(req);
|
|
30439
30464
|
if (!createdBy)
|
|
30440
|
-
throw new
|
|
30465
|
+
throw new UnauthorizedError10("Not authorized.");
|
|
30441
30466
|
const { inviteId, ...body } = req.body ?? {};
|
|
30442
30467
|
let invitedFrom = null;
|
|
30443
30468
|
let invitedRole = null;
|
|
@@ -30941,7 +30966,7 @@ function useOrgControllerV2() {
|
|
|
30941
30966
|
|
|
30942
30967
|
// src/services/subscription.service.ts
|
|
30943
30968
|
import {
|
|
30944
|
-
AppError as
|
|
30969
|
+
AppError as AppError17,
|
|
30945
30970
|
BadRequestError as BadRequestError75,
|
|
30946
30971
|
logger as logger55,
|
|
30947
30972
|
useAtlas as useAtlas53
|
|
@@ -32233,7 +32258,7 @@ function usePaymentRepo() {
|
|
|
32233
32258
|
|
|
32234
32259
|
// src/repositories/price.repo.ts
|
|
32235
32260
|
import {
|
|
32236
|
-
AppError as
|
|
32261
|
+
AppError as AppError16,
|
|
32237
32262
|
BadRequestError as BadRequestError74,
|
|
32238
32263
|
InternalServerError as InternalServerError33,
|
|
32239
32264
|
logger as logger54,
|
|
@@ -32373,7 +32398,7 @@ function usePriceRepo() {
|
|
|
32373
32398
|
});
|
|
32374
32399
|
return data;
|
|
32375
32400
|
} catch (error) {
|
|
32376
|
-
if (error instanceof
|
|
32401
|
+
if (error instanceof AppError16) {
|
|
32377
32402
|
throw error;
|
|
32378
32403
|
} else {
|
|
32379
32404
|
throw new InternalServerError33("Failed to get price.");
|
|
@@ -33025,7 +33050,7 @@ function useSubscriptionService() {
|
|
|
33025
33050
|
level: "error",
|
|
33026
33051
|
message: `Failed to update subscription seats: ${error}`
|
|
33027
33052
|
});
|
|
33028
|
-
if (error instanceof
|
|
33053
|
+
if (error instanceof AppError17) {
|
|
33029
33054
|
throw error;
|
|
33030
33055
|
}
|
|
33031
33056
|
throw new BadRequestError75("Failed to update subscription seats.");
|
|
@@ -33110,13 +33135,13 @@ function useSubscriptionService() {
|
|
|
33110
33135
|
import Joi39 from "joi";
|
|
33111
33136
|
import {
|
|
33112
33137
|
BadRequestError as BadRequestError78,
|
|
33113
|
-
UnauthorizedError as
|
|
33138
|
+
UnauthorizedError as UnauthorizedError11,
|
|
33114
33139
|
logger as logger57
|
|
33115
33140
|
} from "@7365admin1/node-server-utils";
|
|
33116
33141
|
|
|
33117
33142
|
// src/repositories/subscription-plan.repo.ts
|
|
33118
33143
|
import {
|
|
33119
|
-
AppError as
|
|
33144
|
+
AppError as AppError18,
|
|
33120
33145
|
BadRequestError as BadRequestError77,
|
|
33121
33146
|
InternalServerError as InternalServerError34,
|
|
33122
33147
|
logger as logger56,
|
|
@@ -33227,7 +33252,7 @@ function useSubscriptionPlanRepo() {
|
|
|
33227
33252
|
return res.insertedId;
|
|
33228
33253
|
} catch (error) {
|
|
33229
33254
|
logger56.log({ level: "error", message: error.message });
|
|
33230
|
-
if (error instanceof
|
|
33255
|
+
if (error instanceof AppError18) {
|
|
33231
33256
|
throw error;
|
|
33232
33257
|
} else {
|
|
33233
33258
|
throw new InternalServerError34("Failed to create subscription plan.");
|
|
@@ -33335,7 +33360,7 @@ function useSubscriptionPlanRepo() {
|
|
|
33335
33360
|
});
|
|
33336
33361
|
return data;
|
|
33337
33362
|
} catch (error) {
|
|
33338
|
-
if (error instanceof
|
|
33363
|
+
if (error instanceof AppError18) {
|
|
33339
33364
|
throw error;
|
|
33340
33365
|
} else {
|
|
33341
33366
|
throw new InternalServerError34("Failed to get subscription plan.");
|
|
@@ -33390,7 +33415,7 @@ function useSubscriptionPlanRepo() {
|
|
|
33390
33415
|
});
|
|
33391
33416
|
return "Successfully updated subscription plan status.";
|
|
33392
33417
|
} catch (error) {
|
|
33393
|
-
if (error instanceof
|
|
33418
|
+
if (error instanceof AppError18) {
|
|
33394
33419
|
throw error;
|
|
33395
33420
|
}
|
|
33396
33421
|
throw new InternalServerError34(
|
|
@@ -33531,7 +33556,7 @@ function useSubscriptionController() {
|
|
|
33531
33556
|
try {
|
|
33532
33557
|
const subscription = await _getSubscriptionById(subscriptionId);
|
|
33533
33558
|
if (!subscription) {
|
|
33534
|
-
throw new
|
|
33559
|
+
throw new UnauthorizedError11("Not authorized.");
|
|
33535
33560
|
}
|
|
33536
33561
|
await requireOrgAccess(req, subscription.org?.toString());
|
|
33537
33562
|
const _res = await _updateSubscriptionSeats({
|
|
@@ -34962,7 +34987,7 @@ function useWorkOrderController() {
|
|
|
34962
34987
|
import Joi46 from "joi";
|
|
34963
34988
|
import {
|
|
34964
34989
|
BadRequestError as BadRequestError88,
|
|
34965
|
-
UnauthorizedError as
|
|
34990
|
+
UnauthorizedError as UnauthorizedError12,
|
|
34966
34991
|
logger as logger64
|
|
34967
34992
|
} from "@7365admin1/node-server-utils";
|
|
34968
34993
|
|
|
@@ -35264,7 +35289,7 @@ function useServiceProviderController() {
|
|
|
35264
35289
|
throw new BadRequestError88(`Invalid input: ${error.message}`);
|
|
35265
35290
|
await requireSiteReach(req, value.siteId);
|
|
35266
35291
|
if (!await isSiteClient(req, value.siteId)) {
|
|
35267
|
-
throw new
|
|
35292
|
+
throw new UnauthorizedError12(
|
|
35268
35293
|
"Only the site's own organisation can see its service providers' people."
|
|
35269
35294
|
);
|
|
35270
35295
|
}
|
|
@@ -36099,7 +36124,7 @@ function useCustomerController() {
|
|
|
36099
36124
|
|
|
36100
36125
|
// src/services/site.service.ts
|
|
36101
36126
|
import {
|
|
36102
|
-
AppError as
|
|
36127
|
+
AppError as AppError20,
|
|
36103
36128
|
BadRequestError as BadRequestError96,
|
|
36104
36129
|
logger as logger71,
|
|
36105
36130
|
useAtlas as useAtlas61
|
|
@@ -36117,7 +36142,7 @@ import { ObjectId as ObjectId81 } from "mongodb";
|
|
|
36117
36142
|
|
|
36118
36143
|
// src/repositories/building-unit.repository.ts
|
|
36119
36144
|
import {
|
|
36120
|
-
AppError as
|
|
36145
|
+
AppError as AppError19,
|
|
36121
36146
|
BadRequestError as BadRequestError94,
|
|
36122
36147
|
InternalServerError as InternalServerError36,
|
|
36123
36148
|
logger as logger69,
|
|
@@ -36421,7 +36446,7 @@ function useBuildingUnitRepo() {
|
|
|
36421
36446
|
if (isDuplicated) {
|
|
36422
36447
|
throw new BadRequestError94("Building unit already exists.");
|
|
36423
36448
|
}
|
|
36424
|
-
if (error instanceof
|
|
36449
|
+
if (error instanceof AppError19) {
|
|
36425
36450
|
throw error;
|
|
36426
36451
|
} else {
|
|
36427
36452
|
throw new Error("Failed to create building unit.");
|
|
@@ -36480,7 +36505,7 @@ function useBuildingUnitRepo() {
|
|
|
36480
36505
|
if (isDuplicated) {
|
|
36481
36506
|
throw new BadRequestError94("Building unit already exists.");
|
|
36482
36507
|
}
|
|
36483
|
-
if (error2 instanceof
|
|
36508
|
+
if (error2 instanceof AppError19) {
|
|
36484
36509
|
throw error2;
|
|
36485
36510
|
} else {
|
|
36486
36511
|
throw new Error("Failed to create building unit.");
|
|
@@ -36514,7 +36539,7 @@ function useBuildingUnitRepo() {
|
|
|
36514
36539
|
if (isDuplicated) {
|
|
36515
36540
|
throw new BadRequestError94("Building unit already exists.");
|
|
36516
36541
|
}
|
|
36517
|
-
if (error2 instanceof
|
|
36542
|
+
if (error2 instanceof AppError19) {
|
|
36518
36543
|
throw error2;
|
|
36519
36544
|
} else {
|
|
36520
36545
|
throw new Error("Failed to create building unit.");
|
|
@@ -36791,7 +36816,7 @@ function useBuildingUnitRepo() {
|
|
|
36791
36816
|
}
|
|
36792
36817
|
return result;
|
|
36793
36818
|
} catch (error) {
|
|
36794
|
-
if (error instanceof
|
|
36819
|
+
if (error instanceof AppError19) {
|
|
36795
36820
|
throw error;
|
|
36796
36821
|
} else {
|
|
36797
36822
|
throw new InternalServerError36("Failed to get building unit.");
|
|
@@ -36835,7 +36860,7 @@ function useBuildingUnitRepo() {
|
|
|
36835
36860
|
});
|
|
36836
36861
|
return result;
|
|
36837
36862
|
} catch (error) {
|
|
36838
|
-
if (error instanceof
|
|
36863
|
+
if (error instanceof AppError19) {
|
|
36839
36864
|
throw error;
|
|
36840
36865
|
} else {
|
|
36841
36866
|
throw new InternalServerError36("Failed to get building unit.");
|
|
@@ -36865,7 +36890,7 @@ function useBuildingUnitRepo() {
|
|
|
36865
36890
|
delCachedData();
|
|
36866
36891
|
return result;
|
|
36867
36892
|
} catch (error) {
|
|
36868
|
-
if (error instanceof
|
|
36893
|
+
if (error instanceof AppError19) {
|
|
36869
36894
|
throw error;
|
|
36870
36895
|
} else {
|
|
36871
36896
|
throw new InternalServerError36("Failed to update building unit level.");
|
|
@@ -36907,7 +36932,7 @@ function useBuildingUnitRepo() {
|
|
|
36907
36932
|
});
|
|
36908
36933
|
return result;
|
|
36909
36934
|
} catch (error) {
|
|
36910
|
-
if (error instanceof
|
|
36935
|
+
if (error instanceof AppError19) {
|
|
36911
36936
|
throw error;
|
|
36912
36937
|
} else {
|
|
36913
36938
|
throw new InternalServerError36("Failed to get building unit.");
|
|
@@ -36939,7 +36964,7 @@ function useBuildingUnitRepo() {
|
|
|
36939
36964
|
level: "error",
|
|
36940
36965
|
message: error.message
|
|
36941
36966
|
});
|
|
36942
|
-
if (error instanceof
|
|
36967
|
+
if (error instanceof AppError19) {
|
|
36943
36968
|
throw error;
|
|
36944
36969
|
} else {
|
|
36945
36970
|
throw new Error("Failed to deleted room/facility.");
|
|
@@ -36976,7 +37001,7 @@ function useBuildingUnitRepo() {
|
|
|
36976
37001
|
});
|
|
36977
37002
|
return data;
|
|
36978
37003
|
} catch (error) {
|
|
36979
|
-
if (error instanceof
|
|
37004
|
+
if (error instanceof AppError19) {
|
|
36980
37005
|
throw error;
|
|
36981
37006
|
} else {
|
|
36982
37007
|
throw new InternalServerError36("Failed to get building units.");
|
|
@@ -36999,7 +37024,7 @@ function useBuildingUnitRepo() {
|
|
|
36999
37024
|
const data = await collection.aggregate([{ $match: query2 }, { $project: { name: 1 } }]).toArray();
|
|
37000
37025
|
return data;
|
|
37001
37026
|
} catch (error) {
|
|
37002
|
-
if (error instanceof
|
|
37027
|
+
if (error instanceof AppError19) {
|
|
37003
37028
|
throw error;
|
|
37004
37029
|
} else {
|
|
37005
37030
|
throw new InternalServerError36("Failed to get building units.");
|
|
@@ -37054,7 +37079,7 @@ function useBuildingUnitRepo() {
|
|
|
37054
37079
|
]).toArray();
|
|
37055
37080
|
return data;
|
|
37056
37081
|
} catch (error) {
|
|
37057
|
-
if (error instanceof
|
|
37082
|
+
if (error instanceof AppError19) {
|
|
37058
37083
|
throw error;
|
|
37059
37084
|
} else {
|
|
37060
37085
|
throw new InternalServerError36(
|
|
@@ -37121,7 +37146,7 @@ function useBuildingUnitRepo() {
|
|
|
37121
37146
|
});
|
|
37122
37147
|
return result;
|
|
37123
37148
|
} catch (error) {
|
|
37124
|
-
if (error instanceof
|
|
37149
|
+
if (error instanceof AppError19) {
|
|
37125
37150
|
throw error;
|
|
37126
37151
|
} else {
|
|
37127
37152
|
throw new InternalServerError36("Failed to get building unit.");
|
|
@@ -37168,7 +37193,7 @@ function useBuildingUnitRepo() {
|
|
|
37168
37193
|
});
|
|
37169
37194
|
return result;
|
|
37170
37195
|
} catch (error) {
|
|
37171
|
-
if (error instanceof
|
|
37196
|
+
if (error instanceof AppError19) {
|
|
37172
37197
|
throw error;
|
|
37173
37198
|
} else {
|
|
37174
37199
|
throw new InternalServerError36("Failed to get building unit.");
|
|
@@ -37194,7 +37219,7 @@ function useBuildingUnitRepo() {
|
|
|
37194
37219
|
if (isDuplicated) {
|
|
37195
37220
|
throw new BadRequestError94("Some building units already exist.");
|
|
37196
37221
|
}
|
|
37197
|
-
if (error instanceof
|
|
37222
|
+
if (error instanceof AppError19) {
|
|
37198
37223
|
throw error;
|
|
37199
37224
|
} else {
|
|
37200
37225
|
throw new Error("Failed to bulk insert building units.");
|
|
@@ -39387,7 +39412,7 @@ function useSiteService() {
|
|
|
39387
39412
|
});
|
|
39388
39413
|
await deleteSiteCameraCache();
|
|
39389
39414
|
} catch (error2) {
|
|
39390
|
-
if (error2 instanceof
|
|
39415
|
+
if (error2 instanceof AppError20) {
|
|
39391
39416
|
throw error2;
|
|
39392
39417
|
}
|
|
39393
39418
|
throw new BadRequestError96("Failed to update guard post.");
|
|
@@ -39475,18 +39500,18 @@ function useSiteService() {
|
|
|
39475
39500
|
|
|
39476
39501
|
// src/controllers/site.controller.ts
|
|
39477
39502
|
import {
|
|
39478
|
-
AppError as
|
|
39503
|
+
AppError as AppError22,
|
|
39479
39504
|
BadRequestError as BadRequestError97,
|
|
39480
39505
|
logger as logger72,
|
|
39481
39506
|
NotFoundError as NotFoundError28,
|
|
39482
|
-
UnauthorizedError as
|
|
39507
|
+
UnauthorizedError as UnauthorizedError13,
|
|
39483
39508
|
useAtlas as useAtlas63
|
|
39484
39509
|
} from "@7365admin1/node-server-utils";
|
|
39485
39510
|
import Joi52 from "joi";
|
|
39486
39511
|
import { ObjectId as ObjectId83 } from "mongodb";
|
|
39487
39512
|
|
|
39488
39513
|
// src/utils/site-owner-edit.util.ts
|
|
39489
|
-
import { AppError as
|
|
39514
|
+
import { AppError as AppError21, useAtlas as useAtlas62 } from "@7365admin1/node-server-utils";
|
|
39490
39515
|
import { ObjectId as ObjectId82 } from "mongodb";
|
|
39491
39516
|
var SITE_OWNER_FIELDS = ["address", "timezone"];
|
|
39492
39517
|
function touchesSiteOwnerFields(body) {
|
|
@@ -39514,7 +39539,7 @@ async function requireSiteOwnerEdit(actor, staff, siteId) {
|
|
|
39514
39539
|
const ownerOrg = await ownerOfSite(siteId);
|
|
39515
39540
|
if (mayEditSiteDetails({ staff, actorOrgIds: actor.orgIds, ownerOrg }))
|
|
39516
39541
|
return;
|
|
39517
|
-
throw new
|
|
39542
|
+
throw new AppError21(siteOwnerOnlyMessage(await ownerOrgName(ownerOrg)), 403);
|
|
39518
39543
|
}
|
|
39519
39544
|
async function ownerOfSite(siteId) {
|
|
39520
39545
|
const id = String(siteId?.toString?.() ?? "");
|
|
@@ -39550,10 +39575,10 @@ async function requireSiteOwnerDelete(actor, staff, siteId) {
|
|
|
39550
39575
|
const permissions = member.role ? await getUserPermissions({ user: actor.id, org: owner, role: member.role, memberSite: member.siteId }) : [];
|
|
39551
39576
|
if (mayDeleteSite(permissions))
|
|
39552
39577
|
return;
|
|
39553
|
-
throw new
|
|
39578
|
+
throw new AppError21(NO_SITE_DELETE_PERMISSION, 403);
|
|
39554
39579
|
}
|
|
39555
39580
|
}
|
|
39556
|
-
throw new
|
|
39581
|
+
throw new AppError21(siteDeleteOwnerOnlyMessage(await ownerOrgName(owner)), 403);
|
|
39557
39582
|
}
|
|
39558
39583
|
|
|
39559
39584
|
// src/controllers/site.controller.ts
|
|
@@ -39625,7 +39650,7 @@ function siteModulesHandlers({
|
|
|
39625
39650
|
return;
|
|
39626
39651
|
}
|
|
39627
39652
|
if (!await mayManage(actor, site)) {
|
|
39628
|
-
throw new
|
|
39653
|
+
throw new UnauthorizedError13("Not authorized.");
|
|
39629
39654
|
}
|
|
39630
39655
|
const org = site.orgId ? await _getOrgById(site.orgId.toString()) : null;
|
|
39631
39656
|
const rejected = rejectedSiteModules(
|
|
@@ -39639,7 +39664,7 @@ function siteModulesHandlers({
|
|
|
39639
39664
|
const modules = normaliseModules(req.body.modules);
|
|
39640
39665
|
const preview = await siteModulePreview(site, org, modules, gateData);
|
|
39641
39666
|
if (mustAcknowledge(preview, req.body.acknowledgeImpact)) {
|
|
39642
|
-
next(new
|
|
39667
|
+
next(new AppError22(impactUnacknowledgedMessage(preview), 409));
|
|
39643
39668
|
return;
|
|
39644
39669
|
}
|
|
39645
39670
|
await _updateById(siteId, {
|
|
@@ -39687,7 +39712,7 @@ function siteModulesHandlers({
|
|
|
39687
39712
|
if (!site)
|
|
39688
39713
|
throw new NotFoundError28("Site not found.");
|
|
39689
39714
|
if (!await mayManage(actor, site))
|
|
39690
|
-
throw new
|
|
39715
|
+
throw new UnauthorizedError13("Not authorized.");
|
|
39691
39716
|
const org = site?.orgId ? await _getOrgById(site.orgId.toString()) : null;
|
|
39692
39717
|
res.json(
|
|
39693
39718
|
await siteModulePreview(site, org, normaliseModules(req.body.modules), gateData)
|
|
@@ -40159,7 +40184,7 @@ function useChatController() {
|
|
|
40159
40184
|
|
|
40160
40185
|
// src/repositories/building.repository.ts
|
|
40161
40186
|
import {
|
|
40162
|
-
AppError as
|
|
40187
|
+
AppError as AppError23,
|
|
40163
40188
|
BadRequestError as BadRequestError100,
|
|
40164
40189
|
InternalServerError as InternalServerError38,
|
|
40165
40190
|
logger as logger76,
|
|
@@ -40278,7 +40303,7 @@ function useBuildingRepo() {
|
|
|
40278
40303
|
if (isDuplicated) {
|
|
40279
40304
|
throw new BadRequestError100("Building already exists.");
|
|
40280
40305
|
}
|
|
40281
|
-
if (error instanceof
|
|
40306
|
+
if (error instanceof AppError23) {
|
|
40282
40307
|
throw error;
|
|
40283
40308
|
} else {
|
|
40284
40309
|
throw new Error("Failed to create building.");
|
|
@@ -40341,7 +40366,7 @@ function useBuildingRepo() {
|
|
|
40341
40366
|
if (isDuplicated) {
|
|
40342
40367
|
throw new BadRequestError100("Building already exists.");
|
|
40343
40368
|
}
|
|
40344
|
-
if (error instanceof
|
|
40369
|
+
if (error instanceof AppError23) {
|
|
40345
40370
|
throw error;
|
|
40346
40371
|
} else {
|
|
40347
40372
|
throw new Error("Failed to update building.");
|
|
@@ -40567,7 +40592,7 @@ function useBuildingRepo() {
|
|
|
40567
40592
|
});
|
|
40568
40593
|
return result;
|
|
40569
40594
|
} catch (error) {
|
|
40570
|
-
if (error instanceof
|
|
40595
|
+
if (error instanceof AppError23) {
|
|
40571
40596
|
throw error;
|
|
40572
40597
|
} else {
|
|
40573
40598
|
throw new InternalServerError38("Failed to get building.");
|
|
@@ -40593,7 +40618,7 @@ function useBuildingRepo() {
|
|
|
40593
40618
|
level: "error",
|
|
40594
40619
|
message: error.message
|
|
40595
40620
|
});
|
|
40596
|
-
if (error instanceof
|
|
40621
|
+
if (error instanceof AppError23) {
|
|
40597
40622
|
throw error;
|
|
40598
40623
|
} else {
|
|
40599
40624
|
throw new InternalServerError38("Failed to delete building.");
|
|
@@ -40635,7 +40660,7 @@ function useBuildingRepo() {
|
|
|
40635
40660
|
});
|
|
40636
40661
|
return result;
|
|
40637
40662
|
} catch (error) {
|
|
40638
|
-
if (error instanceof
|
|
40663
|
+
if (error instanceof AppError23) {
|
|
40639
40664
|
throw error;
|
|
40640
40665
|
} else {
|
|
40641
40666
|
throw new InternalServerError38("Failed to get building.");
|
|
@@ -40682,7 +40707,7 @@ function useBuildingRepo() {
|
|
|
40682
40707
|
]).toArray();
|
|
40683
40708
|
return result[0] ?? null;
|
|
40684
40709
|
} catch (error) {
|
|
40685
|
-
if (error instanceof
|
|
40710
|
+
if (error instanceof AppError23) {
|
|
40686
40711
|
throw error;
|
|
40687
40712
|
} else {
|
|
40688
40713
|
throw new InternalServerError38("Failed to get building.");
|
|
@@ -40769,7 +40794,7 @@ function useBuildingRepo() {
|
|
|
40769
40794
|
}
|
|
40770
40795
|
return result;
|
|
40771
40796
|
} catch (error) {
|
|
40772
|
-
if (error instanceof
|
|
40797
|
+
if (error instanceof AppError23) {
|
|
40773
40798
|
throw error;
|
|
40774
40799
|
} else {
|
|
40775
40800
|
throw new InternalServerError38("Failed to get building.");
|
|
@@ -40827,7 +40852,7 @@ function useBuildingRepo() {
|
|
|
40827
40852
|
data: result
|
|
40828
40853
|
};
|
|
40829
40854
|
} catch (error) {
|
|
40830
|
-
if (error instanceof
|
|
40855
|
+
if (error instanceof AppError23) {
|
|
40831
40856
|
throw error;
|
|
40832
40857
|
} else {
|
|
40833
40858
|
throw new InternalServerError38("Failed to get building.");
|
|
@@ -40870,7 +40895,7 @@ function useBuildingRepo() {
|
|
|
40870
40895
|
data: result
|
|
40871
40896
|
};
|
|
40872
40897
|
} catch (error) {
|
|
40873
|
-
if (error instanceof
|
|
40898
|
+
if (error instanceof AppError23) {
|
|
40874
40899
|
throw error;
|
|
40875
40900
|
} else {
|
|
40876
40901
|
throw new InternalServerError38("Failed to get buildings.");
|
|
@@ -40904,7 +40929,7 @@ import { ObjectId as ObjectId88 } from "mongodb";
|
|
|
40904
40929
|
|
|
40905
40930
|
// src/repositories/building-level.repository.ts
|
|
40906
40931
|
import {
|
|
40907
|
-
AppError as
|
|
40932
|
+
AppError as AppError24,
|
|
40908
40933
|
BadRequestError as BadRequestError102,
|
|
40909
40934
|
InternalServerError as InternalServerError39,
|
|
40910
40935
|
logger as logger78,
|
|
@@ -41064,7 +41089,7 @@ function useBuildingLevelRepo() {
|
|
|
41064
41089
|
if (isDuplicated) {
|
|
41065
41090
|
throw new BadRequestError102("Building level already exists.");
|
|
41066
41091
|
}
|
|
41067
|
-
if (error instanceof
|
|
41092
|
+
if (error instanceof AppError24) {
|
|
41068
41093
|
throw error;
|
|
41069
41094
|
} else {
|
|
41070
41095
|
throw new Error("Failed to create building level.");
|
|
@@ -41203,7 +41228,7 @@ function useBuildingLevelRepo() {
|
|
|
41203
41228
|
});
|
|
41204
41229
|
return result;
|
|
41205
41230
|
} catch (error) {
|
|
41206
|
-
if (error instanceof
|
|
41231
|
+
if (error instanceof AppError24) {
|
|
41207
41232
|
throw error;
|
|
41208
41233
|
} else {
|
|
41209
41234
|
throw new InternalServerError39("Failed to get building level.");
|
|
@@ -41249,7 +41274,7 @@ function useBuildingLevelRepo() {
|
|
|
41249
41274
|
delCachedData();
|
|
41250
41275
|
return result;
|
|
41251
41276
|
} catch (error) {
|
|
41252
|
-
if (error instanceof
|
|
41277
|
+
if (error instanceof AppError24) {
|
|
41253
41278
|
throw error;
|
|
41254
41279
|
} else {
|
|
41255
41280
|
throw new InternalServerError39("Failed to update building level.");
|
|
@@ -41288,7 +41313,7 @@ function useBuildingLevelRepo() {
|
|
|
41288
41313
|
level: "error",
|
|
41289
41314
|
message: error.message
|
|
41290
41315
|
});
|
|
41291
|
-
if (error instanceof
|
|
41316
|
+
if (error instanceof AppError24) {
|
|
41292
41317
|
throw error;
|
|
41293
41318
|
} else {
|
|
41294
41319
|
throw new Error("Failed to deleted building level.");
|
|
@@ -41351,7 +41376,7 @@ function useBuildingLevelRepo() {
|
|
|
41351
41376
|
if (isDuplicated) {
|
|
41352
41377
|
throw new BadRequestError102("Some levels already exist.");
|
|
41353
41378
|
}
|
|
41354
|
-
if (error instanceof
|
|
41379
|
+
if (error instanceof AppError24) {
|
|
41355
41380
|
throw error;
|
|
41356
41381
|
} else {
|
|
41357
41382
|
throw new Error("Failed to bulk insert levels.");
|
|
@@ -41386,7 +41411,7 @@ function useBuildingLevelRepo() {
|
|
|
41386
41411
|
if (isDuplicated) {
|
|
41387
41412
|
throw new BadRequestError102("Some building levels already exist.");
|
|
41388
41413
|
}
|
|
41389
|
-
if (error instanceof
|
|
41414
|
+
if (error instanceof AppError24) {
|
|
41390
41415
|
throw error;
|
|
41391
41416
|
} else {
|
|
41392
41417
|
throw new Error("Failed to batch update building levels.");
|
|
@@ -41438,7 +41463,7 @@ function useBuildingLevelRepo() {
|
|
|
41438
41463
|
data: result
|
|
41439
41464
|
};
|
|
41440
41465
|
} catch (error) {
|
|
41441
|
-
if (error instanceof
|
|
41466
|
+
if (error instanceof AppError24) {
|
|
41442
41467
|
throw error;
|
|
41443
41468
|
} else {
|
|
41444
41469
|
throw new InternalServerError39("Failed to get building level.");
|
|
@@ -45012,7 +45037,7 @@ function useCameraViewController() {
|
|
|
45012
45037
|
import Joi61 from "joi";
|
|
45013
45038
|
import {
|
|
45014
45039
|
BadRequestError as BadRequestError111,
|
|
45015
|
-
UnauthorizedError as
|
|
45040
|
+
UnauthorizedError as UnauthorizedError14,
|
|
45016
45041
|
logger as logger85
|
|
45017
45042
|
} from "@7365admin1/node-server-utils";
|
|
45018
45043
|
async function requireEitherOrg(req, ...orgs) {
|
|
@@ -45021,7 +45046,7 @@ async function requireEitherOrg(req, ...orgs) {
|
|
|
45021
45046
|
if (staffMayBypass(actor))
|
|
45022
45047
|
return actor;
|
|
45023
45048
|
if (wanted.length === 0 || !wanted.some((org) => actor.orgIds.includes(org))) {
|
|
45024
|
-
throw new
|
|
45049
|
+
throw new UnauthorizedError14("Not authorized.");
|
|
45025
45050
|
}
|
|
45026
45051
|
return actor;
|
|
45027
45052
|
}
|
|
@@ -48250,7 +48275,7 @@ import {
|
|
|
48250
48275
|
BadRequestError as BadRequestError125,
|
|
48251
48276
|
InternalServerError as InternalServerError45,
|
|
48252
48277
|
NotFoundError as NotFoundError38,
|
|
48253
|
-
UnauthorizedError as
|
|
48278
|
+
UnauthorizedError as UnauthorizedError15,
|
|
48254
48279
|
logger as logger97
|
|
48255
48280
|
} from "@7365admin1/node-server-utils";
|
|
48256
48281
|
|
|
@@ -51784,8 +51809,8 @@ function useHidAmicoService() {
|
|
|
51784
51809
|
await siteAccess.authorizeSite({ siteId, userId: value.userId, permissions });
|
|
51785
51810
|
}
|
|
51786
51811
|
} catch (error) {
|
|
51787
|
-
if (error instanceof
|
|
51788
|
-
throw new
|
|
51812
|
+
if (error instanceof UnauthorizedError15) {
|
|
51813
|
+
throw new UnauthorizedError15("You do not have permission to manage HID access at this site.");
|
|
51789
51814
|
}
|
|
51790
51815
|
throw error;
|
|
51791
51816
|
}
|
|
@@ -51809,7 +51834,7 @@ function useHidAmicoService() {
|
|
|
51809
51834
|
try {
|
|
51810
51835
|
await authorizeSiteForCaller(String(reader.site || ""), userId);
|
|
51811
51836
|
} catch (error) {
|
|
51812
|
-
if (error instanceof
|
|
51837
|
+
if (error instanceof UnauthorizedError15)
|
|
51813
51838
|
throw error;
|
|
51814
51839
|
throw new NotFoundError38(HID_READER_NOT_FOUND);
|
|
51815
51840
|
}
|
|
@@ -51861,10 +51886,10 @@ function useHidAmicoService() {
|
|
|
51861
51886
|
async function assertUserReaderPermission(reader, userId, options = {}) {
|
|
51862
51887
|
const permission = await getReaderPermissionForUser(reader, userId);
|
|
51863
51888
|
if (!permission.granted) {
|
|
51864
|
-
throw new
|
|
51889
|
+
throw new UnauthorizedError15("You do not have HID access permission for this reader.");
|
|
51865
51890
|
}
|
|
51866
51891
|
if (options.intercom && !permission.intercom) {
|
|
51867
|
-
throw new
|
|
51892
|
+
throw new UnauthorizedError15("You do not have HID intercom permission for this reader.");
|
|
51868
51893
|
}
|
|
51869
51894
|
return permission;
|
|
51870
51895
|
}
|
|
@@ -53202,10 +53227,10 @@ function useHidAmicoService() {
|
|
|
53202
53227
|
const hasActiveMembership = memberships.some((membership) => membership.status !== "deleted" && membership.status !== "inactive");
|
|
53203
53228
|
const resolvedIssuer = issuer || (hasResidentMembership ? "resident" : "property_management");
|
|
53204
53229
|
if (resolvedIssuer === "resident" && !hasResidentMembership) {
|
|
53205
|
-
throw new
|
|
53230
|
+
throw new UnauthorizedError15("Only a Resident account can issue a Resident visitor QR code.");
|
|
53206
53231
|
}
|
|
53207
53232
|
if (resolvedIssuer === "property_management" && !hasActiveMembership) {
|
|
53208
|
-
throw new
|
|
53233
|
+
throw new UnauthorizedError15("Only a site Property Management account can issue this visitor QR code.");
|
|
53209
53234
|
}
|
|
53210
53235
|
const configuredGateIds = site?.metadata?.hidQrCodePass?.qrGatePermissions?.[resolvedIssuer === "resident" ? "resident" : "propertyManagement"] || [];
|
|
53211
53236
|
const gateReaderIds = configuredGateIds.filter((readerId) => typeof readerId === "string" && /^[a-f0-9]{24}$/i.test(readerId)).map(String);
|
|
@@ -55798,7 +55823,7 @@ function useVisitorTransactionService() {
|
|
|
55798
55823
|
import Joi70 from "joi";
|
|
55799
55824
|
import moment5 from "moment-timezone";
|
|
55800
55825
|
import { ObjectId as ObjectId104 } from "mongodb";
|
|
55801
|
-
import { BadRequestError as BadRequestError128, NotFoundError as NotFoundError40, InternalServerError as InternalServerError47, UnauthorizedError as
|
|
55826
|
+
import { BadRequestError as BadRequestError128, NotFoundError as NotFoundError40, InternalServerError as InternalServerError47, UnauthorizedError as UnauthorizedError16, logger as logger101 } from "@7365admin1/node-server-utils";
|
|
55802
55827
|
|
|
55803
55828
|
// src/models/visitor-invite.model.ts
|
|
55804
55829
|
import Joi68 from "joi";
|
|
@@ -60671,7 +60696,7 @@ function useVisitorTransactionController() {
|
|
|
60671
60696
|
}
|
|
60672
60697
|
const inviterUserId = callerId(req);
|
|
60673
60698
|
if (!inviterUserId) {
|
|
60674
|
-
next(new
|
|
60699
|
+
next(new UnauthorizedError16("Not authorized."));
|
|
60675
60700
|
return;
|
|
60676
60701
|
}
|
|
60677
60702
|
try {
|
|
@@ -61235,7 +61260,7 @@ function useGuestManagementController() {
|
|
|
61235
61260
|
// src/controllers/person.controller.ts
|
|
61236
61261
|
import Joi73 from "joi";
|
|
61237
61262
|
import { BadRequestError as BadRequestError131, logger as logger104 } from "@7365admin1/node-server-utils";
|
|
61238
|
-
import { NotFoundError as NotFoundError41, UnauthorizedError as
|
|
61263
|
+
import { NotFoundError as NotFoundError41, UnauthorizedError as UnauthorizedError17 } from "@7365admin1/node-server-utils";
|
|
61239
61264
|
|
|
61240
61265
|
// src/utils/people-create-gate.util.ts
|
|
61241
61266
|
var PEOPLE_CREATE_REACH_MODE_DEFAULT = "enforce";
|
|
@@ -61302,7 +61327,7 @@ function usePersonController() {
|
|
|
61302
61327
|
}
|
|
61303
61328
|
const org = person.org?.toString() ?? "";
|
|
61304
61329
|
if (!org || !actor.orgIds.includes(org)) {
|
|
61305
|
-
throw new
|
|
61330
|
+
throw new UnauthorizedError17("Not authorized.");
|
|
61306
61331
|
}
|
|
61307
61332
|
return actor;
|
|
61308
61333
|
}
|
|
@@ -61385,7 +61410,7 @@ function usePersonController() {
|
|
|
61385
61410
|
});
|
|
61386
61411
|
}
|
|
61387
61412
|
if (verdict.refuse) {
|
|
61388
|
-
next(new
|
|
61413
|
+
next(new UnauthorizedError17("Not authorized."));
|
|
61389
61414
|
return;
|
|
61390
61415
|
}
|
|
61391
61416
|
}
|
|
@@ -61468,7 +61493,7 @@ function usePersonController() {
|
|
|
61468
61493
|
});
|
|
61469
61494
|
} else if (org) {
|
|
61470
61495
|
if (!actor.orgIds.includes(org)) {
|
|
61471
|
-
throw new
|
|
61496
|
+
throw new UnauthorizedError17("Not authorized.");
|
|
61472
61497
|
}
|
|
61473
61498
|
} else {
|
|
61474
61499
|
orgs = actor.orgIds;
|
|
@@ -62249,10 +62274,10 @@ function networkFaultsPipeline(q) {
|
|
|
62249
62274
|
|
|
62250
62275
|
// src/utils/robot-credentials.util.ts
|
|
62251
62276
|
import crypto9 from "crypto";
|
|
62252
|
-
import { AppError as
|
|
62277
|
+
import { AppError as AppError25 } from "@7365admin1/node-server-utils";
|
|
62253
62278
|
var ROBOT_CREDENTIALS_ENV = "ROBOT_CREDENTIALS_KEY";
|
|
62254
62279
|
var PREFIX = "rc1:";
|
|
62255
|
-
var RobotCredentialsError = class extends
|
|
62280
|
+
var RobotCredentialsError = class extends AppError25 {
|
|
62256
62281
|
constructor(message) {
|
|
62257
62282
|
super(message, 503);
|
|
62258
62283
|
}
|
|
@@ -63078,11 +63103,11 @@ function clearRobotBrands() {
|
|
|
63078
63103
|
}
|
|
63079
63104
|
|
|
63080
63105
|
// src/services/robot-fleet.service.ts
|
|
63081
|
-
import { AppError as
|
|
63106
|
+
import { AppError as AppError28, BadRequestError as BadRequestError137, NotFoundError as NotFoundError43 } from "@7365admin1/node-server-utils";
|
|
63082
63107
|
|
|
63083
63108
|
// src/services/robot-cloud.service.ts
|
|
63084
63109
|
import axios3 from "axios";
|
|
63085
|
-
import { AppError as
|
|
63110
|
+
import { AppError as AppError26, logger as logger107 } from "@7365admin1/node-server-utils";
|
|
63086
63111
|
|
|
63087
63112
|
// src/utils/robot-cloud.util.ts
|
|
63088
63113
|
import * as crypto10 from "crypto";
|
|
@@ -63455,7 +63480,7 @@ var STEP_NAMES = {
|
|
|
63455
63480
|
};
|
|
63456
63481
|
var robotCloudStepName = (path5) => STEP_NAMES[path5] ?? path5;
|
|
63457
63482
|
var SUCCESS_CODES = /* @__PURE__ */ new Set(["0", "200"]);
|
|
63458
|
-
var RobotCloudError = class extends
|
|
63483
|
+
var RobotCloudError = class extends AppError26 {
|
|
63459
63484
|
constructor(path5, message, opts = {}) {
|
|
63460
63485
|
const kind = opts.kind ?? (opts.refused ? "refused" : "input");
|
|
63461
63486
|
super(message, kind === "timeout" ? 504 : kind === "input" ? 400 : 502);
|
|
@@ -65077,7 +65102,7 @@ registerOpenRmfBrand();
|
|
|
65077
65102
|
|
|
65078
65103
|
// src/services/padbot.adapter.ts
|
|
65079
65104
|
import { createHash as createHash6 } from "crypto";
|
|
65080
|
-
import { AppError as
|
|
65105
|
+
import { AppError as AppError27, BadRequestError as BadRequestError136 } from "@7365admin1/node-server-utils";
|
|
65081
65106
|
|
|
65082
65107
|
// src/utils/padbot-sign.util.ts
|
|
65083
65108
|
import { createHash as createHash5, createHmac as createHmac2, randomUUID } from "crypto";
|
|
@@ -65986,19 +66011,19 @@ function createPadbotClient(credentials, options = {}) {
|
|
|
65986
66011
|
try {
|
|
65987
66012
|
res = await doFetch(`${baseUrl}${path5}`, { method: "POST", headers: req.headers, body: req.body, signal: AbortSignal.timeout(timeoutMs) });
|
|
65988
66013
|
} catch (error) {
|
|
65989
|
-
throw new
|
|
66014
|
+
throw new AppError27(`PadBot's cloud did not answer (${error?.name === "TimeoutError" ? "timed out" : "unreachable"}).`, 502);
|
|
65990
66015
|
}
|
|
65991
66016
|
if (res.status === 401)
|
|
65992
66017
|
throw new BadRequestError136("PadBot refused the AccessKey. Check the AccessKey ID and Secret (and the server clock).");
|
|
65993
66018
|
if (res.status === 403)
|
|
65994
66019
|
throw new BadRequestError136("This PadBot AccessKey is not allowed to do that.");
|
|
65995
66020
|
if (res.status !== 200)
|
|
65996
|
-
throw new
|
|
66021
|
+
throw new AppError27(`PadBot's cloud answered HTTP ${res.status}. Try again shortly.`, 502);
|
|
65997
66022
|
let json;
|
|
65998
66023
|
try {
|
|
65999
66024
|
json = JSON.parse(await res.text());
|
|
66000
66025
|
} catch {
|
|
66001
|
-
throw new
|
|
66026
|
+
throw new AppError27("PadBot's cloud sent an answer that is not JSON.", 502);
|
|
66002
66027
|
}
|
|
66003
66028
|
if (meta) {
|
|
66004
66029
|
meta.message = typeof json?.message === "string" ? json.message.slice(0, 200) : "";
|
|
@@ -66953,7 +66978,7 @@ function useRobotFleetService(deps) {
|
|
|
66953
66978
|
const last = lastTimestampProbe.get(key);
|
|
66954
66979
|
if (last && Date.now() - last < TIMESTAMP_PROBE_INTERVAL_MS) {
|
|
66955
66980
|
const wait = Math.ceil((TIMESTAMP_PROBE_INTERVAL_MS - (Date.now() - last)) / 1e3);
|
|
66956
|
-
throw new
|
|
66981
|
+
throw new AppError28(`The timestamp probe ran for this robot less than a minute ago - try again in ${wait} s.`, 429);
|
|
66957
66982
|
}
|
|
66958
66983
|
const pair = robotCloudCredentials(robot);
|
|
66959
66984
|
if (!pair.appid || !pair.secret) {
|
|
@@ -68447,7 +68472,7 @@ function startPadbotLiveFeed(deps = {}) {
|
|
|
68447
68472
|
|
|
68448
68473
|
// src/services/padbot-drive.service.ts
|
|
68449
68474
|
import { randomBytes as randomBytes3, randomUUID as randomUUID2 } from "crypto";
|
|
68450
|
-
import { AppError as
|
|
68475
|
+
import { AppError as AppError29, BadRequestError as BadRequestError139, logger as logger111 } from "@7365admin1/node-server-utils";
|
|
68451
68476
|
var sessions = /* @__PURE__ */ new Map();
|
|
68452
68477
|
var byRobot = /* @__PURE__ */ new Map();
|
|
68453
68478
|
var endedWhy = /* @__PURE__ */ new Map();
|
|
@@ -68488,7 +68513,7 @@ async function startPadbotDrive(robot, userId, deps = {}) {
|
|
|
68488
68513
|
if (current) {
|
|
68489
68514
|
const s = sessions.get(current);
|
|
68490
68515
|
if (s && s.userId !== userId)
|
|
68491
|
-
throw new
|
|
68516
|
+
throw new AppError29("Someone else is controlling this robot right now.", 409);
|
|
68492
68517
|
s?.watchdog.end("replaced");
|
|
68493
68518
|
}
|
|
68494
68519
|
if (!(deps.linkUp ?? padbotLinkUp)(robotId)) {
|
|
@@ -68565,7 +68590,7 @@ function padbotDriveSignal(robotId, sessionId, userId, signal) {
|
|
|
68565
68590
|
const s = sessions.get(sessionId);
|
|
68566
68591
|
if (!s || s.robotId !== robotId || s.userId !== userId) {
|
|
68567
68592
|
const why = endedWhy.get(sessionId);
|
|
68568
|
-
throw new
|
|
68593
|
+
throw new AppError29(DRIVE_END_TEXT[why?.reason ?? ""] ?? "Manual control has ended.", 410);
|
|
68569
68594
|
}
|
|
68570
68595
|
if (signal.seq <= s.seq)
|
|
68571
68596
|
return { ok: true, moving: s.watchdog.moving };
|
|
@@ -68589,7 +68614,7 @@ function padbotDriveSignal(robotId, sessionId, userId, signal) {
|
|
|
68589
68614
|
}
|
|
68590
68615
|
if (s.watchdog.ended) {
|
|
68591
68616
|
const why = endedWhy.get(sessionId);
|
|
68592
|
-
throw new
|
|
68617
|
+
throw new AppError29(DRIVE_END_TEXT[why?.reason ?? ""] ?? "Manual control has ended.", 410);
|
|
68593
68618
|
}
|
|
68594
68619
|
return { ok: true, moving: s.watchdog.moving };
|
|
68595
68620
|
}
|
|
@@ -69813,7 +69838,7 @@ function startRobotTracking(options) {
|
|
|
69813
69838
|
|
|
69814
69839
|
// src/controllers/robot-fleet.controller.ts
|
|
69815
69840
|
import Joi76 from "joi";
|
|
69816
|
-
import { AppError as
|
|
69841
|
+
import { AppError as AppError30, BadRequestError as BadRequestError140, logger as logger112 } from "@7365admin1/node-server-utils";
|
|
69817
69842
|
function useRobotFleetController(deps) {
|
|
69818
69843
|
let repo = null;
|
|
69819
69844
|
const getRepo = () => repo ?? (repo = useRobotRepo());
|
|
@@ -69843,7 +69868,7 @@ function useRobotFleetController(deps) {
|
|
|
69843
69868
|
if (error?.isOperational)
|
|
69844
69869
|
return next(error);
|
|
69845
69870
|
next(
|
|
69846
|
-
new
|
|
69871
|
+
new AppError30(
|
|
69847
69872
|
"Couldn't read this robot from its cloud (unexpected error). Seven365 staff can run Diagnose on the robot to see the failing step.",
|
|
69848
69873
|
502
|
|
69849
69874
|
)
|
|
@@ -70413,7 +70438,7 @@ import {
|
|
|
70413
70438
|
paginate as paginate35,
|
|
70414
70439
|
BadRequestError as BadRequestError141,
|
|
70415
70440
|
NotFoundError as NotFoundError44,
|
|
70416
|
-
AppError as
|
|
70441
|
+
AppError as AppError31
|
|
70417
70442
|
} from "@7365admin1/node-server-utils";
|
|
70418
70443
|
var NOT_DELETED2 = { deletedAt: { $in: ["", null] } };
|
|
70419
70444
|
function toObjectId16(id, what) {
|
|
@@ -70554,7 +70579,7 @@ function useRobotBuildingMapRepo() {
|
|
|
70554
70579
|
}
|
|
70555
70580
|
);
|
|
70556
70581
|
if (!res.matchedCount) {
|
|
70557
|
-
throw new
|
|
70582
|
+
throw new AppError31(
|
|
70558
70583
|
"This map was changed by someone else since you opened it. Reload it and make your change again.",
|
|
70559
70584
|
409
|
|
70560
70585
|
);
|
|
@@ -70582,7 +70607,7 @@ function useRobotBuildingMapRepo() {
|
|
|
70582
70607
|
const exists = await collection.countDocuments({ _id: id, ...NOT_DELETED2, "floorPlans.floorNo": floorNo2 });
|
|
70583
70608
|
if (!exists)
|
|
70584
70609
|
throw new NotFoundError44("This floor has no plan.");
|
|
70585
|
-
throw new
|
|
70610
|
+
throw new AppError31("This map was changed by someone else since you opened it. Reload it and make your change again.", 409);
|
|
70586
70611
|
}
|
|
70587
70612
|
return version + 1;
|
|
70588
70613
|
}
|
|
@@ -70603,7 +70628,7 @@ function useRobotBuildingMapRepo() {
|
|
|
70603
70628
|
}
|
|
70604
70629
|
);
|
|
70605
70630
|
if (!res.matchedCount) {
|
|
70606
|
-
throw new
|
|
70631
|
+
throw new AppError31(
|
|
70607
70632
|
"This map was changed by someone else since you opened it. Reload it and make your change again.",
|
|
70608
70633
|
409
|
|
70609
70634
|
);
|
|
@@ -70724,7 +70749,7 @@ function useRobotLiftSessionRepo() {
|
|
|
70724
70749
|
insertedId = res.insertedId;
|
|
70725
70750
|
} catch (error) {
|
|
70726
70751
|
if (isDuplicateKey(error)) {
|
|
70727
|
-
throw new
|
|
70752
|
+
throw new AppError31("This robot already has a lift request open. Release it first.", 409);
|
|
70728
70753
|
}
|
|
70729
70754
|
throw error;
|
|
70730
70755
|
}
|
|
@@ -70762,7 +70787,7 @@ function useRobotLiftSessionRepo() {
|
|
|
70762
70787
|
{ $set: { expiresAt: new Date(now.getTime() + LIFT_LEASE_MS), updatedAt: now } }
|
|
70763
70788
|
);
|
|
70764
70789
|
if (!res.matchedCount) {
|
|
70765
|
-
throw new
|
|
70790
|
+
throw new AppError31("This lift session is no longer active.", 409);
|
|
70766
70791
|
}
|
|
70767
70792
|
}
|
|
70768
70793
|
async function release(session, reason = "released") {
|
|
@@ -70820,7 +70845,7 @@ function useRobotLiftSessionRepo() {
|
|
|
70820
70845
|
|
|
70821
70846
|
// src/controllers/robot-map.controller.ts
|
|
70822
70847
|
import Joi78 from "joi";
|
|
70823
|
-
import { AppError as
|
|
70848
|
+
import { AppError as AppError32, BadRequestError as BadRequestError142, NotFoundError as NotFoundError45, logger as logger113 } from "@7365admin1/node-server-utils";
|
|
70824
70849
|
import { load as loadYaml, CORE_SCHEMA as YAML_CORE_SCHEMA } from "js-yaml";
|
|
70825
70850
|
function useRobotMapController(deps) {
|
|
70826
70851
|
const now = () => deps?.now?.() ?? Date.now();
|
|
@@ -71268,7 +71293,7 @@ function useRobotMapController(deps) {
|
|
|
71268
71293
|
try {
|
|
71269
71294
|
const session = await entitleSession(req);
|
|
71270
71295
|
if (!session.open)
|
|
71271
|
-
throw new
|
|
71296
|
+
throw new AppError32("This lift session is already closed.", 409);
|
|
71272
71297
|
await lifts().release(session);
|
|
71273
71298
|
await audit2(
|
|
71274
71299
|
req,
|
|
@@ -71334,7 +71359,7 @@ function useRobotMapController(deps) {
|
|
|
71334
71359
|
liftStates: liftStates.filter(Boolean)
|
|
71335
71360
|
});
|
|
71336
71361
|
} catch (e) {
|
|
71337
|
-
fail(next, e instanceof OpenRmfError ? new
|
|
71362
|
+
fail(next, e instanceof OpenRmfError ? new AppError32(e.message, 502) : e);
|
|
71338
71363
|
}
|
|
71339
71364
|
}
|
|
71340
71365
|
return {
|
|
@@ -71811,7 +71836,7 @@ function MPatrolQuestion(value) {
|
|
|
71811
71836
|
|
|
71812
71837
|
// src/repositories/patrol-question.repo.ts
|
|
71813
71838
|
import {
|
|
71814
|
-
AppError as
|
|
71839
|
+
AppError as AppError33,
|
|
71815
71840
|
BadRequestError as BadRequestError146,
|
|
71816
71841
|
InternalServerError as InternalServerError52,
|
|
71817
71842
|
logger as logger117,
|
|
@@ -71875,7 +71900,7 @@ function usePatrolQuestionRepo() {
|
|
|
71875
71900
|
if (isDuplicated) {
|
|
71876
71901
|
throw new BadRequestError146("Question already exist.");
|
|
71877
71902
|
}
|
|
71878
|
-
if (error instanceof
|
|
71903
|
+
if (error instanceof AppError33) {
|
|
71879
71904
|
throw error;
|
|
71880
71905
|
} else {
|
|
71881
71906
|
throw new Error("Failed to create Patrol Question.");
|
|
@@ -72276,7 +72301,7 @@ function MPatrolRoute(value) {
|
|
|
72276
72301
|
|
|
72277
72302
|
// src/repositories/patrol-route.repo.ts
|
|
72278
72303
|
import {
|
|
72279
|
-
AppError as
|
|
72304
|
+
AppError as AppError34,
|
|
72280
72305
|
BadRequestError as BadRequestError149,
|
|
72281
72306
|
InternalServerError as InternalServerError53,
|
|
72282
72307
|
logger as logger120,
|
|
@@ -72354,7 +72379,7 @@ function usePatrolRouteRepo() {
|
|
|
72354
72379
|
if (isDuplicated) {
|
|
72355
72380
|
throw new BadRequestError149("Route already exist.");
|
|
72356
72381
|
}
|
|
72357
|
-
if (error instanceof
|
|
72382
|
+
if (error instanceof AppError34) {
|
|
72358
72383
|
throw error;
|
|
72359
72384
|
} else {
|
|
72360
72385
|
throw new Error("Failed to create Patrol Route.");
|
|
@@ -73056,7 +73081,7 @@ function MPatrolLog(value) {
|
|
|
73056
73081
|
|
|
73057
73082
|
// src/repositories/patrol-log.repo.ts
|
|
73058
73083
|
import {
|
|
73059
|
-
AppError as
|
|
73084
|
+
AppError as AppError35,
|
|
73060
73085
|
BadRequestError as BadRequestError152,
|
|
73061
73086
|
InternalServerError as InternalServerError54,
|
|
73062
73087
|
logger as logger123,
|
|
@@ -73122,7 +73147,7 @@ function usePatrolLogRepo() {
|
|
|
73122
73147
|
if (isDuplicated) {
|
|
73123
73148
|
throw new BadRequestError152("Log already exist.");
|
|
73124
73149
|
}
|
|
73125
|
-
if (error instanceof
|
|
73150
|
+
if (error instanceof AppError35) {
|
|
73126
73151
|
throw error;
|
|
73127
73152
|
} else {
|
|
73128
73153
|
throw new Error("Failed to create Patrol Log.");
|
|
@@ -73854,7 +73879,7 @@ function MPatrolEmail(value) {
|
|
|
73854
73879
|
|
|
73855
73880
|
// src/repositories/patrol-email.repo.ts
|
|
73856
73881
|
import {
|
|
73857
|
-
AppError as
|
|
73882
|
+
AppError as AppError36,
|
|
73858
73883
|
BadRequestError as BadRequestError156,
|
|
73859
73884
|
InternalServerError as InternalServerError55,
|
|
73860
73885
|
logger as logger126,
|
|
@@ -73907,7 +73932,7 @@ function usePatrolEmailRepo() {
|
|
|
73907
73932
|
return { ...document2, _id: res.insertedId };
|
|
73908
73933
|
} catch (error) {
|
|
73909
73934
|
logger126.log({ level: "error", message: error.message });
|
|
73910
|
-
if (error instanceof
|
|
73935
|
+
if (error instanceof AppError36) {
|
|
73911
73936
|
throw error;
|
|
73912
73937
|
}
|
|
73913
73938
|
throw new InternalServerError55("Failed to record the patrol email.");
|
|
@@ -74067,7 +74092,7 @@ function usePatrolEmailRepo() {
|
|
|
74067
74092
|
}
|
|
74068
74093
|
return result;
|
|
74069
74094
|
} catch (error) {
|
|
74070
|
-
if (error instanceof
|
|
74095
|
+
if (error instanceof AppError36) {
|
|
74071
74096
|
throw error;
|
|
74072
74097
|
}
|
|
74073
74098
|
logger126.log({ level: "error", message: error.message });
|
|
@@ -75354,7 +75379,7 @@ function useSiteFacilityService() {
|
|
|
75354
75379
|
import {
|
|
75355
75380
|
BadRequestError as BadRequestError162,
|
|
75356
75381
|
NotFoundError as NotFoundError52,
|
|
75357
|
-
UnauthorizedError as
|
|
75382
|
+
UnauthorizedError as UnauthorizedError18,
|
|
75358
75383
|
logger as logger131
|
|
75359
75384
|
} from "@7365admin1/node-server-utils";
|
|
75360
75385
|
import Joi90 from "joi";
|
|
@@ -75441,7 +75466,7 @@ function useSiteFacilityController() {
|
|
|
75441
75466
|
} else {
|
|
75442
75467
|
const { actor } = await siteReachOf(req);
|
|
75443
75468
|
if (!actor.isSuperAdmin)
|
|
75444
|
-
throw new
|
|
75469
|
+
throw new UnauthorizedError18("Not authorized.");
|
|
75445
75470
|
}
|
|
75446
75471
|
const data = await _getAll({
|
|
75447
75472
|
search,
|
|
@@ -78476,7 +78501,7 @@ function useBulletinBoardService() {
|
|
|
78476
78501
|
import {
|
|
78477
78502
|
BadRequestError as BadRequestError171,
|
|
78478
78503
|
NotFoundError as NotFoundError60,
|
|
78479
|
-
UnauthorizedError as
|
|
78504
|
+
UnauthorizedError as UnauthorizedError19,
|
|
78480
78505
|
logger as logger140
|
|
78481
78506
|
} from "@7365admin1/node-server-utils";
|
|
78482
78507
|
import Joi98 from "joi";
|
|
@@ -78512,7 +78537,7 @@ function useBulletinBoardController() {
|
|
|
78512
78537
|
} else {
|
|
78513
78538
|
const { canReach } = await siteReachOf(req);
|
|
78514
78539
|
if (!await canReach(scopeOf(value))) {
|
|
78515
|
-
throw new
|
|
78540
|
+
throw new UnauthorizedError19("Not authorized.");
|
|
78516
78541
|
}
|
|
78517
78542
|
}
|
|
78518
78543
|
const data = await _add(value);
|
|
@@ -78814,7 +78839,7 @@ function MBillingItem(value) {
|
|
|
78814
78839
|
|
|
78815
78840
|
// src/repositories/site-billing-item.repo.ts
|
|
78816
78841
|
import {
|
|
78817
|
-
AppError as
|
|
78842
|
+
AppError as AppError37,
|
|
78818
78843
|
BadRequestError as BadRequestError173,
|
|
78819
78844
|
InternalServerError as InternalServerError61,
|
|
78820
78845
|
logger as logger142,
|
|
@@ -78870,7 +78895,7 @@ function useSiteBillingItemRepo() {
|
|
|
78870
78895
|
if (isDuplicated) {
|
|
78871
78896
|
throw new BadRequestError173("Site Billing Item already exist.");
|
|
78872
78897
|
}
|
|
78873
|
-
if (error instanceof
|
|
78898
|
+
if (error instanceof AppError37) {
|
|
78874
78899
|
throw error;
|
|
78875
78900
|
} else {
|
|
78876
78901
|
throw new Error("Failed to create Site Site Billing Item.");
|
|
@@ -78973,7 +78998,7 @@ function useSiteBillingItemRepo() {
|
|
|
78973
78998
|
});
|
|
78974
78999
|
return result;
|
|
78975
79000
|
} catch (error) {
|
|
78976
|
-
if (error instanceof
|
|
79001
|
+
if (error instanceof AppError37) {
|
|
78977
79002
|
throw error;
|
|
78978
79003
|
} else {
|
|
78979
79004
|
throw new InternalServerError61("Failed to get site billing item by id.");
|
|
@@ -79069,13 +79094,13 @@ import { BadRequestError as BadRequestError177, logger as logger146 } from "@736
|
|
|
79069
79094
|
import {
|
|
79070
79095
|
BadRequestError as BadRequestError176,
|
|
79071
79096
|
logger as logger145,
|
|
79072
|
-
UnauthorizedError as
|
|
79097
|
+
UnauthorizedError as UnauthorizedError20,
|
|
79073
79098
|
useAtlas as useAtlas101
|
|
79074
79099
|
} from "@7365admin1/node-server-utils";
|
|
79075
79100
|
|
|
79076
79101
|
// src/repositories/site-billing-configuration.repo.ts
|
|
79077
79102
|
import {
|
|
79078
|
-
AppError as
|
|
79103
|
+
AppError as AppError38,
|
|
79079
79104
|
BadRequestError as BadRequestError175,
|
|
79080
79105
|
InternalServerError as InternalServerError62,
|
|
79081
79106
|
logger as logger144,
|
|
@@ -79258,7 +79283,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
79258
79283
|
if (isDuplicated) {
|
|
79259
79284
|
throw new BadRequestError175("Site Billing Configuration already exist.");
|
|
79260
79285
|
}
|
|
79261
|
-
if (error instanceof
|
|
79286
|
+
if (error instanceof AppError38) {
|
|
79262
79287
|
throw error;
|
|
79263
79288
|
} else {
|
|
79264
79289
|
throw new Error("Failed to create Site Site Billing Configuration.");
|
|
@@ -79347,7 +79372,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
79347
79372
|
});
|
|
79348
79373
|
return result;
|
|
79349
79374
|
} catch (error) {
|
|
79350
|
-
if (error instanceof
|
|
79375
|
+
if (error instanceof AppError38) {
|
|
79351
79376
|
throw error;
|
|
79352
79377
|
} else {
|
|
79353
79378
|
throw new InternalServerError62(
|
|
@@ -79453,7 +79478,7 @@ function useSiteBillingItemService() {
|
|
|
79453
79478
|
function assertUnitAtSite(buildingUnit, site) {
|
|
79454
79479
|
const siteId = site?.toString?.() ?? "";
|
|
79455
79480
|
if (!siteId || (buildingUnit?.site?.toString() ?? "") !== siteId) {
|
|
79456
|
-
throw new
|
|
79481
|
+
throw new UnauthorizedError20("Not authorized.");
|
|
79457
79482
|
}
|
|
79458
79483
|
}
|
|
79459
79484
|
async function add(value) {
|
|
@@ -79624,7 +79649,7 @@ function useSiteBillingItemService() {
|
|
|
79624
79649
|
message: error.message
|
|
79625
79650
|
});
|
|
79626
79651
|
await session.abortTransaction();
|
|
79627
|
-
if (error instanceof BadRequestError176 || error instanceof
|
|
79652
|
+
if (error instanceof BadRequestError176 || error instanceof UnauthorizedError20) {
|
|
79628
79653
|
throw error;
|
|
79629
79654
|
}
|
|
79630
79655
|
throw new BadRequestError176("Failed to update Site Billing Item.");
|
|
@@ -80791,7 +80816,7 @@ function MUnitBilling(value) {
|
|
|
80791
80816
|
|
|
80792
80817
|
// src/repositories/site-unit-billing.repo.ts
|
|
80793
80818
|
import {
|
|
80794
|
-
AppError as
|
|
80819
|
+
AppError as AppError39,
|
|
80795
80820
|
BadRequestError as BadRequestError183,
|
|
80796
80821
|
InternalServerError as InternalServerError64,
|
|
80797
80822
|
logger as logger152,
|
|
@@ -80868,7 +80893,7 @@ function useSiteUnitBillingRepo() {
|
|
|
80868
80893
|
if (isDuplicated) {
|
|
80869
80894
|
throw new BadRequestError183("Site Unit Billing already exist.");
|
|
80870
80895
|
}
|
|
80871
|
-
if (error instanceof
|
|
80896
|
+
if (error instanceof AppError39) {
|
|
80872
80897
|
throw error;
|
|
80873
80898
|
} else {
|
|
80874
80899
|
throw new Error("Failed to create Site Unit Billing");
|
|
@@ -81024,7 +81049,7 @@ function useSiteUnitBillingRepo() {
|
|
|
81024
81049
|
});
|
|
81025
81050
|
return result;
|
|
81026
81051
|
} catch (error) {
|
|
81027
|
-
if (error instanceof
|
|
81052
|
+
if (error instanceof AppError39) {
|
|
81028
81053
|
throw error;
|
|
81029
81054
|
} else {
|
|
81030
81055
|
throw new InternalServerError64("Failed to get site unit billing by id.");
|
|
@@ -81593,7 +81618,7 @@ import Joi106 from "joi";
|
|
|
81593
81618
|
|
|
81594
81619
|
// src/utils/resident-unit.util.ts
|
|
81595
81620
|
import { ObjectId as ObjectId142 } from "mongodb";
|
|
81596
|
-
import { UnauthorizedError as
|
|
81621
|
+
import { UnauthorizedError as UnauthorizedError21, useAtlas as useAtlas107 } from "@7365admin1/node-server-utils";
|
|
81597
81622
|
async function requireOwnUnit(req, site, unitId) {
|
|
81598
81623
|
const actor = await resolveInviteActor(callerId(req));
|
|
81599
81624
|
if (staffMayBypass(actor))
|
|
@@ -81601,7 +81626,7 @@ async function requireOwnUnit(req, site, unitId) {
|
|
|
81601
81626
|
const unit = unitId?.toString?.() ?? "";
|
|
81602
81627
|
const siteId = site?.toString?.() ?? "";
|
|
81603
81628
|
if (!ObjectId142.isValid(unit) || !ObjectId142.isValid(siteId) || !actor.id) {
|
|
81604
|
-
throw new
|
|
81629
|
+
throw new UnauthorizedError21("Not authorized.");
|
|
81605
81630
|
}
|
|
81606
81631
|
const db2 = useAtlas107.getDb();
|
|
81607
81632
|
if (!db2)
|
|
@@ -81613,7 +81638,7 @@ async function requireOwnUnit(req, site, unitId) {
|
|
|
81613
81638
|
status: { $ne: "deleted" }
|
|
81614
81639
|
});
|
|
81615
81640
|
if (!own)
|
|
81616
|
-
throw new
|
|
81641
|
+
throw new UnauthorizedError21("Not authorized.");
|
|
81617
81642
|
}
|
|
81618
81643
|
|
|
81619
81644
|
// src/controllers/site-unit-billing.controller.ts
|
|
@@ -84791,7 +84816,7 @@ function MStatementOfAccount(value) {
|
|
|
84791
84816
|
|
|
84792
84817
|
// src/repositories/site-soa.repo.ts
|
|
84793
84818
|
import {
|
|
84794
|
-
AppError as
|
|
84819
|
+
AppError as AppError40,
|
|
84795
84820
|
BadRequestError as BadRequestError195,
|
|
84796
84821
|
InternalServerError as InternalServerError67,
|
|
84797
84822
|
logger as logger162,
|
|
@@ -84854,7 +84879,7 @@ function useStatementOfAccountRepo() {
|
|
|
84854
84879
|
if (isDuplicated) {
|
|
84855
84880
|
throw new BadRequestError195("Site SOA already exist.");
|
|
84856
84881
|
}
|
|
84857
|
-
if (error instanceof
|
|
84882
|
+
if (error instanceof AppError40) {
|
|
84858
84883
|
throw error;
|
|
84859
84884
|
} else {
|
|
84860
84885
|
throw new Error("Failed to create Site SOA");
|
|
@@ -84978,7 +85003,7 @@ function useStatementOfAccountRepo() {
|
|
|
84978
85003
|
});
|
|
84979
85004
|
return result;
|
|
84980
85005
|
} catch (error) {
|
|
84981
|
-
if (error instanceof
|
|
85006
|
+
if (error instanceof AppError40) {
|
|
84982
85007
|
throw error;
|
|
84983
85008
|
} else {
|
|
84984
85009
|
throw new InternalServerError67("Failed to get soa by id.");
|
|
@@ -86567,7 +86592,7 @@ function MNfcPatrolRoute(value) {
|
|
|
86567
86592
|
|
|
86568
86593
|
// src/repositories/nfc-patrol-route.repository.ts
|
|
86569
86594
|
import {
|
|
86570
|
-
AppError as
|
|
86595
|
+
AppError as AppError41,
|
|
86571
86596
|
BadRequestError as BadRequestError203,
|
|
86572
86597
|
InternalServerError as InternalServerError70,
|
|
86573
86598
|
logger as logger171,
|
|
@@ -86788,7 +86813,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
86788
86813
|
});
|
|
86789
86814
|
return result;
|
|
86790
86815
|
} catch (error) {
|
|
86791
|
-
if (error instanceof
|
|
86816
|
+
if (error instanceof AppError41) {
|
|
86792
86817
|
throw error;
|
|
86793
86818
|
} else {
|
|
86794
86819
|
throw new InternalServerError70(
|
|
@@ -86841,7 +86866,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
86841
86866
|
if (isDuplicated) {
|
|
86842
86867
|
throw new BadRequestError203("NFC Patrol Route already exists.");
|
|
86843
86868
|
}
|
|
86844
|
-
if (error2 instanceof
|
|
86869
|
+
if (error2 instanceof AppError41) {
|
|
86845
86870
|
throw error2;
|
|
86846
86871
|
} else {
|
|
86847
86872
|
throw new Error("Failed to update NFC Patrol Route.");
|
|
@@ -89703,7 +89728,7 @@ function useOnlineFormRepo() {
|
|
|
89703
89728
|
import {
|
|
89704
89729
|
BadRequestError as BadRequestError216,
|
|
89705
89730
|
NotFoundError as NotFoundError79,
|
|
89706
|
-
UnauthorizedError as
|
|
89731
|
+
UnauthorizedError as UnauthorizedError22,
|
|
89707
89732
|
logger as logger183
|
|
89708
89733
|
} from "@7365admin1/node-server-utils";
|
|
89709
89734
|
import Joi128 from "joi";
|
|
@@ -89775,10 +89800,10 @@ function useOnlineFormController() {
|
|
|
89775
89800
|
if (site) {
|
|
89776
89801
|
await requireSiteReach(req, site);
|
|
89777
89802
|
} else if (!staffMayBypass(actor)) {
|
|
89778
|
-
throw new
|
|
89803
|
+
throw new UnauthorizedError22("Not authorized.");
|
|
89779
89804
|
}
|
|
89780
89805
|
if (org && !staffMayBypass(actor) && !actor.orgIds.includes(org)) {
|
|
89781
|
-
throw new
|
|
89806
|
+
throw new UnauthorizedError22("Not authorized.");
|
|
89782
89807
|
}
|
|
89783
89808
|
const data = await _getAll({ search, page: page2, limit, status, org, site });
|
|
89784
89809
|
res.json(data);
|
|
@@ -89843,7 +89868,7 @@ function useOnlineFormController() {
|
|
|
89843
89868
|
if (payload.org) {
|
|
89844
89869
|
const { actor } = await siteReachOf(req);
|
|
89845
89870
|
if (!staffMayBypass(actor) && !actor.orgIds.includes(payload.org)) {
|
|
89846
|
-
throw new
|
|
89871
|
+
throw new UnauthorizedError22("Not authorized.");
|
|
89847
89872
|
}
|
|
89848
89873
|
}
|
|
89849
89874
|
await _updateOnlineFormById(_id, payload);
|
|
@@ -96453,7 +96478,7 @@ import {
|
|
|
96453
96478
|
logger as logger209,
|
|
96454
96479
|
BadRequestError as BadRequestError239,
|
|
96455
96480
|
NotFoundError as NotFoundError85,
|
|
96456
|
-
AppError as
|
|
96481
|
+
AppError as AppError47,
|
|
96457
96482
|
paginate as paginate67
|
|
96458
96483
|
} from "@7365admin1/node-server-utils";
|
|
96459
96484
|
var useRedDotPaymentRepo = () => {
|
|
@@ -96514,7 +96539,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
96514
96539
|
}
|
|
96515
96540
|
return payment;
|
|
96516
96541
|
} catch (error) {
|
|
96517
|
-
if (error instanceof
|
|
96542
|
+
if (error instanceof AppError47) {
|
|
96518
96543
|
throw error;
|
|
96519
96544
|
}
|
|
96520
96545
|
logger209.log({
|
|
@@ -96539,7 +96564,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
96539
96564
|
if (isDuplicated) {
|
|
96540
96565
|
throw new BadRequestError239("Payment already exist.");
|
|
96541
96566
|
}
|
|
96542
|
-
if (error instanceof
|
|
96567
|
+
if (error instanceof AppError47) {
|
|
96543
96568
|
throw error;
|
|
96544
96569
|
} else {
|
|
96545
96570
|
throw new Error("Failed to create Payment.");
|
|
@@ -96568,7 +96593,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
96568
96593
|
if (isDuplicated) {
|
|
96569
96594
|
throw new BadRequestError239("payment already exist.");
|
|
96570
96595
|
}
|
|
96571
|
-
if (error instanceof
|
|
96596
|
+
if (error instanceof AppError47) {
|
|
96572
96597
|
throw error;
|
|
96573
96598
|
} else {
|
|
96574
96599
|
throw new Error("Failed to create payment");
|
|
@@ -96636,7 +96661,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
96636
96661
|
const data = paginate67(items, page2, limit, totalCount);
|
|
96637
96662
|
return data;
|
|
96638
96663
|
} catch (error) {
|
|
96639
|
-
if (error instanceof
|
|
96664
|
+
if (error instanceof AppError47) {
|
|
96640
96665
|
throw error;
|
|
96641
96666
|
}
|
|
96642
96667
|
logger209.log({
|
|
@@ -96848,7 +96873,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
96848
96873
|
}
|
|
96849
96874
|
return res;
|
|
96850
96875
|
} catch (error) {
|
|
96851
|
-
if (error instanceof
|
|
96876
|
+
if (error instanceof AppError47) {
|
|
96852
96877
|
throw error;
|
|
96853
96878
|
}
|
|
96854
96879
|
throw new InternalServerError83("Failed to update payment status.");
|
|
@@ -97175,7 +97200,7 @@ import {
|
|
|
97175
97200
|
BadRequestError as BadRequestError243,
|
|
97176
97201
|
NotFoundError as NotFoundError88,
|
|
97177
97202
|
InternalServerError as InternalServerError87,
|
|
97178
|
-
UnauthorizedError as
|
|
97203
|
+
UnauthorizedError as UnauthorizedError23,
|
|
97179
97204
|
useAtlas as useAtlas144,
|
|
97180
97205
|
hashPassword as hashPassword4
|
|
97181
97206
|
} from "@7365admin1/node-server-utils";
|
|
@@ -97202,7 +97227,7 @@ import {
|
|
|
97202
97227
|
BadRequestError as BadRequestError241,
|
|
97203
97228
|
paginate as paginate68,
|
|
97204
97229
|
NotFoundError as NotFoundError86,
|
|
97205
|
-
AppError as
|
|
97230
|
+
AppError as AppError48,
|
|
97206
97231
|
useCache as useCache72,
|
|
97207
97232
|
makeCacheKey as makeCacheKey65,
|
|
97208
97233
|
toObjectId as toObjectId23
|
|
@@ -97340,7 +97365,7 @@ function useUserRepoV2() {
|
|
|
97340
97365
|
);
|
|
97341
97366
|
return data;
|
|
97342
97367
|
} catch (error) {
|
|
97343
|
-
if (error instanceof
|
|
97368
|
+
if (error instanceof AppError48)
|
|
97344
97369
|
throw error;
|
|
97345
97370
|
throw new InternalServerError85("Failed to get user by id.");
|
|
97346
97371
|
}
|
|
@@ -98101,7 +98126,7 @@ function useVerificationServiceV2() {
|
|
|
98101
98126
|
const org = await getOrgById(orgId);
|
|
98102
98127
|
const actor = await resolveInviteActor(invitedBy);
|
|
98103
98128
|
if (!actor.id) {
|
|
98104
|
-
throw new
|
|
98129
|
+
throw new UnauthorizedError23("Sign in to continue.");
|
|
98105
98130
|
}
|
|
98106
98131
|
const { sender } = await assertServiceProviderInviteScope(
|
|
98107
98132
|
actor,
|
|
@@ -98426,7 +98451,7 @@ function useVerificationServiceV2() {
|
|
|
98426
98451
|
const user = await _getUserById(userId).catch(() => null);
|
|
98427
98452
|
const email = user?.email;
|
|
98428
98453
|
if (!email) {
|
|
98429
|
-
throw new
|
|
98454
|
+
throw new UnauthorizedError23("Not authorized.");
|
|
98430
98455
|
}
|
|
98431
98456
|
return email;
|
|
98432
98457
|
}
|
|
@@ -98464,7 +98489,7 @@ function useVerificationServiceV2() {
|
|
|
98464
98489
|
throw new NotFoundError88("Invitation not found.");
|
|
98465
98490
|
}
|
|
98466
98491
|
if (invite.email.toLowerCase() !== email.toLowerCase()) {
|
|
98467
|
-
throw new
|
|
98492
|
+
throw new UnauthorizedError23("Not authorized.");
|
|
98468
98493
|
}
|
|
98469
98494
|
await _setOnboardingById({
|
|
98470
98495
|
_id: inviteId,
|
|
@@ -102437,7 +102462,7 @@ import Joi164 from "joi";
|
|
|
102437
102462
|
import { ObjectId as ObjectId195 } from "mongodb";
|
|
102438
102463
|
import {
|
|
102439
102464
|
InternalServerError as InternalServerError97,
|
|
102440
|
-
UnauthorizedError as
|
|
102465
|
+
UnauthorizedError as UnauthorizedError24,
|
|
102441
102466
|
useAtlas as useAtlas156
|
|
102442
102467
|
} from "@7365admin1/node-server-utils";
|
|
102443
102468
|
function db() {
|
|
@@ -102453,7 +102478,7 @@ function asObjectId(value) {
|
|
|
102453
102478
|
function requireCaller(req) {
|
|
102454
102479
|
const id = callerId(req);
|
|
102455
102480
|
if (!id || !ObjectId195.isValid(id)) {
|
|
102456
|
-
throw new
|
|
102481
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102457
102482
|
}
|
|
102458
102483
|
return id;
|
|
102459
102484
|
}
|
|
@@ -102461,7 +102486,7 @@ function requireSelfId(req, claimed) {
|
|
|
102461
102486
|
const caller = requireCaller(req);
|
|
102462
102487
|
const asked = claimed?.toString?.() ?? "";
|
|
102463
102488
|
if (!asked || asked !== caller) {
|
|
102464
|
-
throw new
|
|
102489
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102465
102490
|
}
|
|
102466
102491
|
return caller;
|
|
102467
102492
|
}
|
|
@@ -102469,11 +102494,11 @@ async function requireOwnChannel(req, channelId) {
|
|
|
102469
102494
|
const caller = requireCaller(req);
|
|
102470
102495
|
const _id = asObjectId(channelId);
|
|
102471
102496
|
if (!_id)
|
|
102472
|
-
throw new
|
|
102497
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102473
102498
|
const channel = await db().collection("channel-preloved").findOne({ _id }, { projection: { senderId: 1, receiverId: 1, postId: 1 } });
|
|
102474
102499
|
const participants = [channel?.senderId, channel?.receiverId].map((id) => id?.toString?.() ?? "").filter(Boolean);
|
|
102475
102500
|
if (!channel || !participants.includes(caller)) {
|
|
102476
|
-
throw new
|
|
102501
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102477
102502
|
}
|
|
102478
102503
|
return { caller, channel };
|
|
102479
102504
|
}
|
|
@@ -102481,10 +102506,10 @@ async function requireOwnChatMessage(req, chatId) {
|
|
|
102481
102506
|
const caller = requireCaller(req);
|
|
102482
102507
|
const _id = asObjectId(chatId);
|
|
102483
102508
|
if (!_id)
|
|
102484
|
-
throw new
|
|
102509
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102485
102510
|
const message = await db().collection("chat-preloved").findOne({ _id }, { projection: { senderId: 1 } });
|
|
102486
102511
|
if (!message || message.senderId?.toString?.() !== caller) {
|
|
102487
|
-
throw new
|
|
102512
|
+
throw new UnauthorizedError24("Not authorized.");
|
|
102488
102513
|
}
|
|
102489
102514
|
return caller;
|
|
102490
102515
|
}
|
|
@@ -102910,7 +102935,7 @@ function useBidPrelovedService() {
|
|
|
102910
102935
|
// src/controllers/bid-preloved.controller.ts
|
|
102911
102936
|
import {
|
|
102912
102937
|
BadRequestError as BadRequestError264,
|
|
102913
|
-
UnauthorizedError as
|
|
102938
|
+
UnauthorizedError as UnauthorizedError25,
|
|
102914
102939
|
logger as logger227
|
|
102915
102940
|
} from "@7365admin1/node-server-utils";
|
|
102916
102941
|
import Joi167 from "joi";
|
|
@@ -102962,7 +102987,7 @@ function useBidPrelovedController() {
|
|
|
102962
102987
|
const bid = await _getById(params.id);
|
|
102963
102988
|
const seller = await sellerOfPost(bid?.postId);
|
|
102964
102989
|
if (!seller || seller !== caller) {
|
|
102965
|
-
throw new
|
|
102990
|
+
throw new UnauthorizedError25("Not authorized.");
|
|
102966
102991
|
}
|
|
102967
102992
|
const data = await _updateStatus(params.id, body.status);
|
|
102968
102993
|
res.status(200).json(data);
|
|
@@ -102986,7 +103011,7 @@ function useBidPrelovedController() {
|
|
|
102986
103011
|
const data = await _getById(params.id);
|
|
102987
103012
|
const seller = await sellerOfPost(data?.postId);
|
|
102988
103013
|
if (data?.buyerId?.toString?.() !== caller && seller !== caller) {
|
|
102989
|
-
throw new
|
|
103014
|
+
throw new UnauthorizedError25("Not authorized.");
|
|
102990
103015
|
}
|
|
102991
103016
|
res.status(200).json(data);
|
|
102992
103017
|
} catch (error2) {
|
|
@@ -103384,7 +103409,7 @@ function useFormEntryRepo() {
|
|
|
103384
103409
|
import {
|
|
103385
103410
|
BadRequestError as BadRequestError266,
|
|
103386
103411
|
NotFoundError as NotFoundError97,
|
|
103387
|
-
UnauthorizedError as
|
|
103412
|
+
UnauthorizedError as UnauthorizedError26,
|
|
103388
103413
|
logger as logger229
|
|
103389
103414
|
} from "@7365admin1/node-server-utils";
|
|
103390
103415
|
import Joi169 from "joi";
|
|
@@ -103494,7 +103519,7 @@ function useFormEntryController() {
|
|
|
103494
103519
|
} else {
|
|
103495
103520
|
const { actor } = await siteReachOf(req);
|
|
103496
103521
|
if (!actor.isSuperAdmin)
|
|
103497
|
-
throw new
|
|
103522
|
+
throw new UnauthorizedError26("Not authorized.");
|
|
103498
103523
|
}
|
|
103499
103524
|
const data = await _getAll({ search, page: page2, limit, status, org, site });
|
|
103500
103525
|
res.json(data);
|
|
@@ -103545,7 +103570,7 @@ function useFormEntryController() {
|
|
|
103545
103570
|
await requireSiteReach(req, rest.site);
|
|
103546
103571
|
delete rest.userId;
|
|
103547
103572
|
if (isOwner && rest.status && rest.status !== "pending") {
|
|
103548
|
-
throw new
|
|
103573
|
+
throw new UnauthorizedError26("Not authorized.");
|
|
103549
103574
|
}
|
|
103550
103575
|
await _updateFormEntryById(_id, rest);
|
|
103551
103576
|
res.json({ message: "Successfully updated online form." });
|
|
@@ -103602,7 +103627,7 @@ function useFormEntryController() {
|
|
|
103602
103627
|
async function residentFormSubmission(req, res, next) {
|
|
103603
103628
|
const userId = callerId(req);
|
|
103604
103629
|
if (!userId) {
|
|
103605
|
-
next(new
|
|
103630
|
+
next(new UnauthorizedError26("Not authorized."));
|
|
103606
103631
|
return;
|
|
103607
103632
|
}
|
|
103608
103633
|
const payload = { ...req.body, userId };
|
|
@@ -104833,7 +104858,7 @@ function useHidAmicoController() {
|
|
|
104833
104858
|
import {
|
|
104834
104859
|
BadRequestError as BadRequestError269,
|
|
104835
104860
|
logger as logger231,
|
|
104836
|
-
UnauthorizedError as
|
|
104861
|
+
UnauthorizedError as UnauthorizedError27
|
|
104837
104862
|
} from "@7365admin1/node-server-utils";
|
|
104838
104863
|
import Joi171 from "joi";
|
|
104839
104864
|
function usePlatformTermsController() {
|
|
@@ -104849,7 +104874,7 @@ function usePlatformTermsController() {
|
|
|
104849
104874
|
async function requireOwnRecord(req, user, { staffMayRead = false } = {}) {
|
|
104850
104875
|
const id = callerId(req);
|
|
104851
104876
|
if (!id) {
|
|
104852
|
-
throw new
|
|
104877
|
+
throw new UnauthorizedError27("Not authorized.");
|
|
104853
104878
|
}
|
|
104854
104879
|
if (id === user) {
|
|
104855
104880
|
return id;
|
|
@@ -104857,7 +104882,7 @@ function usePlatformTermsController() {
|
|
|
104857
104882
|
if (staffMayRead) {
|
|
104858
104883
|
return await requireConsolePermission(req, "platform-terms", "see-platform-terms");
|
|
104859
104884
|
}
|
|
104860
|
-
throw new
|
|
104885
|
+
throw new UnauthorizedError27("Not authorized.");
|
|
104861
104886
|
}
|
|
104862
104887
|
async function getLatest(_req, res, next) {
|
|
104863
104888
|
try {
|
|
@@ -105066,7 +105091,7 @@ function useConsoleAuditController() {
|
|
|
105066
105091
|
// src/controllers/notification.controller.ts
|
|
105067
105092
|
import {
|
|
105068
105093
|
BadRequestError as BadRequestError271,
|
|
105069
|
-
UnauthorizedError as
|
|
105094
|
+
UnauthorizedError as UnauthorizedError28,
|
|
105070
105095
|
logger as logger233
|
|
105071
105096
|
} from "@7365admin1/node-server-utils";
|
|
105072
105097
|
function useNotificationController() {
|
|
@@ -105084,10 +105109,10 @@ function useNotificationController() {
|
|
|
105084
105109
|
function inboxOwner(req, claimed) {
|
|
105085
105110
|
const caller = callerId5(req);
|
|
105086
105111
|
if (!caller) {
|
|
105087
|
-
throw new
|
|
105112
|
+
throw new UnauthorizedError28("Not authorized.");
|
|
105088
105113
|
}
|
|
105089
105114
|
if (claimed && claimed !== caller) {
|
|
105090
|
-
throw new
|
|
105115
|
+
throw new UnauthorizedError28("Not authorized.");
|
|
105091
105116
|
}
|
|
105092
105117
|
return caller;
|
|
105093
105118
|
}
|
|
@@ -105099,7 +105124,7 @@ function useNotificationController() {
|
|
|
105099
105124
|
}
|
|
105100
105125
|
try {
|
|
105101
105126
|
if (!await isSuperAdmin(callerId5(req))) {
|
|
105102
|
-
throw new
|
|
105127
|
+
throw new UnauthorizedError28("Not authorized.");
|
|
105103
105128
|
}
|
|
105104
105129
|
const inserted = await _addMany(value.to, {
|
|
105105
105130
|
title: value.title,
|
|
@@ -105700,7 +105725,7 @@ function emptyPersonalEmergencyChain(user) {
|
|
|
105700
105725
|
// src/repositories/personal-emergency-chain.repo.ts
|
|
105701
105726
|
import { ObjectId as ObjectId201 } from "mongodb";
|
|
105702
105727
|
import {
|
|
105703
|
-
AppError as
|
|
105728
|
+
AppError as AppError49,
|
|
105704
105729
|
BadRequestError as BadRequestError275,
|
|
105705
105730
|
InternalServerError as InternalServerError102,
|
|
105706
105731
|
logger as logger236,
|
|
@@ -105737,7 +105762,7 @@ function usePersonalEmergencyChainRepo() {
|
|
|
105737
105762
|
const doc = await collection().findOne({ user: new ObjectId201(user) });
|
|
105738
105763
|
return doc ?? emptyPersonalEmergencyChain(user);
|
|
105739
105764
|
} catch (error) {
|
|
105740
|
-
if (error instanceof
|
|
105765
|
+
if (error instanceof AppError49)
|
|
105741
105766
|
throw error;
|
|
105742
105767
|
logger236.log({ level: "error", message: error.message });
|
|
105743
105768
|
throw new InternalServerError102("Failed to retrieve emergency contacts.");
|
|
@@ -105763,7 +105788,7 @@ function usePersonalEmergencyChainRepo() {
|
|
|
105763
105788
|
);
|
|
105764
105789
|
return doc;
|
|
105765
105790
|
} catch (error) {
|
|
105766
|
-
if (error instanceof
|
|
105791
|
+
if (error instanceof AppError49)
|
|
105767
105792
|
throw error;
|
|
105768
105793
|
logger236.log({ level: "error", message: error.message });
|
|
105769
105794
|
throw new InternalServerError102("Failed to save emergency contacts.");
|