@7365admin1/core 3.0.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +16 -9
- package/dist/index.js +335 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +335 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11347,12 +11347,28 @@ function useSiteRepo() {
|
|
|
11347
11347
|
{ $match: { "buildings.0": { $exists: true } } },
|
|
11348
11348
|
{
|
|
11349
11349
|
$lookup: {
|
|
11350
|
-
from: "building-
|
|
11350
|
+
from: "building-levels",
|
|
11351
11351
|
let: { buildingIds: "$buildings._id" },
|
|
11352
11352
|
pipeline: [
|
|
11353
11353
|
{
|
|
11354
11354
|
$match: {
|
|
11355
|
-
$expr: { $in: ["$
|
|
11355
|
+
$expr: { $in: ["$blockId", "$$buildingIds"] },
|
|
11356
|
+
status: { $ne: "deleted" }
|
|
11357
|
+
}
|
|
11358
|
+
}
|
|
11359
|
+
],
|
|
11360
|
+
as: "levels"
|
|
11361
|
+
}
|
|
11362
|
+
},
|
|
11363
|
+
{ $match: { "levels.0": { $exists: true } } },
|
|
11364
|
+
{
|
|
11365
|
+
$lookup: {
|
|
11366
|
+
from: "building-units",
|
|
11367
|
+
let: { levelIds: "$levels._id" },
|
|
11368
|
+
pipeline: [
|
|
11369
|
+
{
|
|
11370
|
+
$match: {
|
|
11371
|
+
$expr: { $in: ["$level", "$$levelIds"] },
|
|
11356
11372
|
status: { $ne: "deleted" }
|
|
11357
11373
|
}
|
|
11358
11374
|
},
|
|
@@ -24397,7 +24413,7 @@ function usePersonRepo() {
|
|
|
24397
24413
|
pipeline: [
|
|
24398
24414
|
{
|
|
24399
24415
|
$match: {
|
|
24400
|
-
$expr: { $eq: [
|
|
24416
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24401
24417
|
}
|
|
24402
24418
|
},
|
|
24403
24419
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24413,7 +24429,7 @@ function usePersonRepo() {
|
|
|
24413
24429
|
pipeline: [
|
|
24414
24430
|
{
|
|
24415
24431
|
$match: {
|
|
24416
|
-
$expr: { $eq: [
|
|
24432
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24417
24433
|
}
|
|
24418
24434
|
},
|
|
24419
24435
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24644,7 +24660,7 @@ function usePersonRepo() {
|
|
|
24644
24660
|
pipeline: [
|
|
24645
24661
|
{
|
|
24646
24662
|
$match: {
|
|
24647
|
-
$expr: { $eq: [
|
|
24663
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24648
24664
|
}
|
|
24649
24665
|
},
|
|
24650
24666
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24660,7 +24676,7 @@ function usePersonRepo() {
|
|
|
24660
24676
|
pipeline: [
|
|
24661
24677
|
{
|
|
24662
24678
|
$match: {
|
|
24663
|
-
$expr: { $eq: [
|
|
24679
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24664
24680
|
}
|
|
24665
24681
|
},
|
|
24666
24682
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24734,7 +24750,7 @@ function usePersonRepo() {
|
|
|
24734
24750
|
pipeline: [
|
|
24735
24751
|
{
|
|
24736
24752
|
$match: {
|
|
24737
|
-
$expr: { $eq: [
|
|
24753
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24738
24754
|
}
|
|
24739
24755
|
},
|
|
24740
24756
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24750,7 +24766,7 @@ function usePersonRepo() {
|
|
|
24750
24766
|
pipeline: [
|
|
24751
24767
|
{
|
|
24752
24768
|
$match: {
|
|
24753
|
-
$expr: { $eq: [
|
|
24769
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24754
24770
|
}
|
|
24755
24771
|
},
|
|
24756
24772
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -25225,6 +25241,9 @@ function useBuildingUnitRepo() {
|
|
|
25225
25241
|
}
|
|
25226
25242
|
const collection = db.collection(building_units_namespace_collection);
|
|
25227
25243
|
const visitorCollection = db.collection(visitors_namespace_collection);
|
|
25244
|
+
const buildingUnitCollection = db.collection(
|
|
25245
|
+
site_people_namespace_collection
|
|
25246
|
+
);
|
|
25228
25247
|
const { getCache, setCache, delNamespace, delCache } = useCache26(
|
|
25229
25248
|
building_units_namespace_collection
|
|
25230
25249
|
);
|
|
@@ -25306,10 +25325,8 @@ function useBuildingUnitRepo() {
|
|
|
25306
25325
|
} catch (error2) {
|
|
25307
25326
|
throw new BadRequestError74("Invalid ID.");
|
|
25308
25327
|
}
|
|
25309
|
-
|
|
25328
|
+
if (value.level) {
|
|
25310
25329
|
value.level = new ObjectId47(value.level);
|
|
25311
|
-
} catch (error2) {
|
|
25312
|
-
throw new BadRequestError74("Invalid level ID.");
|
|
25313
25330
|
}
|
|
25314
25331
|
if (value.billing && Array.isArray(value.billing)) {
|
|
25315
25332
|
value.billing = value.billing.map((billing) => {
|
|
@@ -25757,6 +25774,12 @@ function useBuildingUnitRepo() {
|
|
|
25757
25774
|
throw new BadRequestError74("Invalid ID.");
|
|
25758
25775
|
}
|
|
25759
25776
|
try {
|
|
25777
|
+
const existingResidents = await buildingUnitCollection.find({ unit: _id }).toArray();
|
|
25778
|
+
if (existingResidents && existingResidents.length > 0) {
|
|
25779
|
+
throw new BadRequestError74(
|
|
25780
|
+
`Cannot delete unit: ${existingResidents.length} resident/s is currently assigned.`
|
|
25781
|
+
);
|
|
25782
|
+
}
|
|
25760
25783
|
const res = await collection.updateOne(
|
|
25761
25784
|
{ _id },
|
|
25762
25785
|
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
@@ -27549,6 +27572,9 @@ function useBuildingRepo() {
|
|
|
27549
27572
|
throw new Error("Unable to connect to server.");
|
|
27550
27573
|
}
|
|
27551
27574
|
const collection = db.collection(buildings_namespace_collection);
|
|
27575
|
+
const buildingUnitCollection = db.collection(
|
|
27576
|
+
building_units_namespace_collection
|
|
27577
|
+
);
|
|
27552
27578
|
const { getCache, setCache, delNamespace } = useCache28(
|
|
27553
27579
|
buildings_namespace_collection
|
|
27554
27580
|
);
|
|
@@ -27596,24 +27622,30 @@ function useBuildingRepo() {
|
|
|
27596
27622
|
}
|
|
27597
27623
|
}
|
|
27598
27624
|
async function updateById(_id, value, session) {
|
|
27599
|
-
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27600
|
-
if (error) {
|
|
27601
|
-
logger61.info(`Building Repository: ${error.message}`);
|
|
27602
|
-
throw new BadRequestError80(error.message);
|
|
27603
|
-
}
|
|
27604
27625
|
try {
|
|
27605
|
-
|
|
27606
|
-
|
|
27607
|
-
|
|
27608
|
-
|
|
27609
|
-
|
|
27626
|
+
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27627
|
+
if (error) {
|
|
27628
|
+
logger61.info(`Building Repository: ${error.message}`);
|
|
27629
|
+
throw new BadRequestError80(error.message);
|
|
27630
|
+
}
|
|
27610
27631
|
try {
|
|
27611
|
-
|
|
27612
|
-
} catch {
|
|
27613
|
-
throw new BadRequestError80("Invalid
|
|
27632
|
+
_id = new ObjectId50(_id);
|
|
27633
|
+
} catch (error2) {
|
|
27634
|
+
throw new BadRequestError80("Invalid ID.");
|
|
27614
27635
|
}
|
|
27615
|
-
|
|
27616
|
-
|
|
27636
|
+
if (value.levels && Array.isArray(value.levels)) {
|
|
27637
|
+
try {
|
|
27638
|
+
value.levels = value.levels.map((lvl) => new ObjectId50(lvl));
|
|
27639
|
+
} catch {
|
|
27640
|
+
throw new BadRequestError80("Invalid level ID format.");
|
|
27641
|
+
}
|
|
27642
|
+
}
|
|
27643
|
+
if (value.name)
|
|
27644
|
+
await buildingUnitCollection.updateMany(
|
|
27645
|
+
{ building: _id, status: "active" /* ACTIVE */ },
|
|
27646
|
+
{ $set: { buildingName: value.name } },
|
|
27647
|
+
{ session }
|
|
27648
|
+
);
|
|
27617
27649
|
const res = await collection.updateOne(
|
|
27618
27650
|
{ _id },
|
|
27619
27651
|
{ $set: value },
|
|
@@ -27621,17 +27653,17 @@ function useBuildingRepo() {
|
|
|
27621
27653
|
);
|
|
27622
27654
|
delCachedData();
|
|
27623
27655
|
return res;
|
|
27624
|
-
} catch (
|
|
27656
|
+
} catch (error) {
|
|
27625
27657
|
logger61.log({
|
|
27626
27658
|
level: "error",
|
|
27627
|
-
message:
|
|
27659
|
+
message: error.message
|
|
27628
27660
|
});
|
|
27629
|
-
const isDuplicated =
|
|
27661
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
27630
27662
|
if (isDuplicated) {
|
|
27631
27663
|
throw new BadRequestError80("Building already exists.");
|
|
27632
27664
|
}
|
|
27633
|
-
if (
|
|
27634
|
-
throw
|
|
27665
|
+
if (error instanceof AppError13) {
|
|
27666
|
+
throw error;
|
|
27635
27667
|
} else {
|
|
27636
27668
|
throw new Error("Failed to update building.");
|
|
27637
27669
|
}
|
|
@@ -28072,6 +28104,49 @@ function useBuildingRepo() {
|
|
|
28072
28104
|
}
|
|
28073
28105
|
}
|
|
28074
28106
|
}
|
|
28107
|
+
async function getBuildingWithUnitsList(site) {
|
|
28108
|
+
try {
|
|
28109
|
+
site = new ObjectId50(site);
|
|
28110
|
+
} catch (error) {
|
|
28111
|
+
throw new BadRequestError80("Invalid site ID.");
|
|
28112
|
+
}
|
|
28113
|
+
const buildingUnitsQuery = {
|
|
28114
|
+
site,
|
|
28115
|
+
status: "active" /* ACTIVE */
|
|
28116
|
+
};
|
|
28117
|
+
try {
|
|
28118
|
+
const buildingsWithUnits = await buildingUnitCollection.aggregate([
|
|
28119
|
+
{ $match: buildingUnitsQuery },
|
|
28120
|
+
{ $project: { building: 1 } }
|
|
28121
|
+
]).toArray();
|
|
28122
|
+
const buildingIds = [
|
|
28123
|
+
...new Set(buildingsWithUnits.map((l) => l.building.toString()))
|
|
28124
|
+
].map((id) => new ObjectId50(id));
|
|
28125
|
+
const result = await collection.aggregate([
|
|
28126
|
+
{
|
|
28127
|
+
$match: {
|
|
28128
|
+
_id: { $in: buildingIds }
|
|
28129
|
+
}
|
|
28130
|
+
},
|
|
28131
|
+
{
|
|
28132
|
+
$project: {
|
|
28133
|
+
name: 1
|
|
28134
|
+
}
|
|
28135
|
+
}
|
|
28136
|
+
]).toArray();
|
|
28137
|
+
return {
|
|
28138
|
+
success: true,
|
|
28139
|
+
message: "Buildings with units retrieved successfully",
|
|
28140
|
+
data: result
|
|
28141
|
+
};
|
|
28142
|
+
} catch (error) {
|
|
28143
|
+
if (error instanceof AppError13) {
|
|
28144
|
+
throw error;
|
|
28145
|
+
} else {
|
|
28146
|
+
throw new InternalServerError29("Failed to get buildings.");
|
|
28147
|
+
}
|
|
28148
|
+
}
|
|
28149
|
+
}
|
|
28075
28150
|
return {
|
|
28076
28151
|
createIndexes,
|
|
28077
28152
|
add,
|
|
@@ -28083,7 +28158,8 @@ function useBuildingRepo() {
|
|
|
28083
28158
|
getBuildingLevel,
|
|
28084
28159
|
getBuildingLevelForResident,
|
|
28085
28160
|
getBuildingLevelWithUnits,
|
|
28086
|
-
getBuildingList
|
|
28161
|
+
getBuildingList,
|
|
28162
|
+
getBuildingWithUnitsList
|
|
28087
28163
|
};
|
|
28088
28164
|
}
|
|
28089
28165
|
|
|
@@ -28194,6 +28270,32 @@ function useBuildingLevelRepo() {
|
|
|
28194
28270
|
const { delNamespace: delBuildingNamespace } = useCache29(
|
|
28195
28271
|
buildings_namespace_collection
|
|
28196
28272
|
);
|
|
28273
|
+
async function createIndexes() {
|
|
28274
|
+
try {
|
|
28275
|
+
await collection.createIndexes([
|
|
28276
|
+
// Ensure name is unique per blockId
|
|
28277
|
+
{
|
|
28278
|
+
key: { blockId: 1, name: 1 },
|
|
28279
|
+
unique: true,
|
|
28280
|
+
name: "unique_name_per_blockId"
|
|
28281
|
+
},
|
|
28282
|
+
// Other useful indexes
|
|
28283
|
+
{ key: { site: 1 }, name: "idx_site" },
|
|
28284
|
+
{ key: { blockId: 1 }, name: "idx_blockId" },
|
|
28285
|
+
{ key: { status: 1 }, name: "idx_status" },
|
|
28286
|
+
{ key: { createdAt: 1 }, name: "idx_createdAt" },
|
|
28287
|
+
// Text index for search
|
|
28288
|
+
{
|
|
28289
|
+
key: {
|
|
28290
|
+
name: "text"
|
|
28291
|
+
},
|
|
28292
|
+
name: "text_search_index"
|
|
28293
|
+
}
|
|
28294
|
+
]);
|
|
28295
|
+
} catch (error) {
|
|
28296
|
+
throw new Error("Failed to create indexes on building levels.");
|
|
28297
|
+
}
|
|
28298
|
+
}
|
|
28197
28299
|
function delCachedData() {
|
|
28198
28300
|
delNamespace().then(() => {
|
|
28199
28301
|
logger63.log({
|
|
@@ -28534,12 +28636,12 @@ function useBuildingLevelRepo() {
|
|
|
28534
28636
|
if (error instanceof AppError14) {
|
|
28535
28637
|
throw error;
|
|
28536
28638
|
} else {
|
|
28537
|
-
throw new InternalServerError30("Failed to get building.");
|
|
28639
|
+
throw new InternalServerError30("Failed to get building level.");
|
|
28538
28640
|
}
|
|
28539
28641
|
}
|
|
28540
28642
|
}
|
|
28541
28643
|
return {
|
|
28542
|
-
|
|
28644
|
+
createIndexes,
|
|
28543
28645
|
add,
|
|
28544
28646
|
getAll,
|
|
28545
28647
|
getById,
|
|
@@ -28818,7 +28920,8 @@ function useBuildingController() {
|
|
|
28818
28920
|
getBuildingLevel: _getBuildingLevel,
|
|
28819
28921
|
getBuildingLevelForResident: _getBuildingLevelForResident,
|
|
28820
28922
|
getBuildingLevelWithUnits: _getBuildingLevelWithUnits,
|
|
28821
|
-
getBuildingList: _getBuildingList
|
|
28923
|
+
getBuildingList: _getBuildingList,
|
|
28924
|
+
getBuildingWithUnitsList: _getBuildingWithUnitsList
|
|
28822
28925
|
} = useBuildingRepo();
|
|
28823
28926
|
const {
|
|
28824
28927
|
updateById: _updateById,
|
|
@@ -29205,6 +29308,28 @@ function useBuildingController() {
|
|
|
29205
29308
|
next(error);
|
|
29206
29309
|
}
|
|
29207
29310
|
}
|
|
29311
|
+
async function getBuildingWithUnitsList(req, res, next) {
|
|
29312
|
+
try {
|
|
29313
|
+
const schema2 = Joi46.object({
|
|
29314
|
+
site: Joi46.string().hex().length(24).required()
|
|
29315
|
+
});
|
|
29316
|
+
const { error, value } = schema2.validate({
|
|
29317
|
+
site: req.params.siteId
|
|
29318
|
+
});
|
|
29319
|
+
if (error) {
|
|
29320
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
29321
|
+
logger65.log({ level: "error", message: messages });
|
|
29322
|
+
next(new BadRequestError84(messages));
|
|
29323
|
+
return;
|
|
29324
|
+
}
|
|
29325
|
+
const { site } = value;
|
|
29326
|
+
const result = await _getBuildingWithUnitsList(site);
|
|
29327
|
+
res.json(result);
|
|
29328
|
+
return;
|
|
29329
|
+
} catch (error) {
|
|
29330
|
+
next(error);
|
|
29331
|
+
}
|
|
29332
|
+
}
|
|
29208
29333
|
return {
|
|
29209
29334
|
createBuilding,
|
|
29210
29335
|
getAll,
|
|
@@ -29216,7 +29341,8 @@ function useBuildingController() {
|
|
|
29216
29341
|
getBuildingLevelForResident,
|
|
29217
29342
|
uploadSpreadsheetBuilding,
|
|
29218
29343
|
getBuildingLevelWithUnits,
|
|
29219
|
-
getBuildingList
|
|
29344
|
+
getBuildingList,
|
|
29345
|
+
getBuildingWithUnitsList
|
|
29220
29346
|
};
|
|
29221
29347
|
}
|
|
29222
29348
|
|
|
@@ -34713,7 +34839,6 @@ function usePersonService() {
|
|
|
34713
34839
|
return "People added successfully.";
|
|
34714
34840
|
} catch (error) {
|
|
34715
34841
|
console.log("error message service", error);
|
|
34716
|
-
console.log("error message service", error.message);
|
|
34717
34842
|
logger84.error("Error in people service add:", error);
|
|
34718
34843
|
await session.abortTransaction();
|
|
34719
34844
|
throw error;
|
|
@@ -34740,6 +34865,15 @@ function usePersonService() {
|
|
|
34740
34865
|
if (value.site && typeof value.site === "string") {
|
|
34741
34866
|
value.site = new ObjectId65(value.site);
|
|
34742
34867
|
}
|
|
34868
|
+
if (value.block && typeof value.block === "string") {
|
|
34869
|
+
value.block = new ObjectId65(value.block);
|
|
34870
|
+
}
|
|
34871
|
+
if (value.level && typeof value.level === "string") {
|
|
34872
|
+
value.level = new ObjectId65(value.level);
|
|
34873
|
+
}
|
|
34874
|
+
if (value.unit && typeof value.unit === "string") {
|
|
34875
|
+
value.unit = new ObjectId65(value.unit);
|
|
34876
|
+
}
|
|
34743
34877
|
const isOrgChanged = value.org && person.org?.toString() !== value.org.toString();
|
|
34744
34878
|
await _updateById(_id, value, session);
|
|
34745
34879
|
if (isOrgChanged && person.user) {
|
|
@@ -52955,9 +53089,9 @@ var affectedInjuredStatusSchema = Joi101.object({
|
|
|
52955
53089
|
contact: Joi101.string().optional().allow(null, ""),
|
|
52956
53090
|
nric: Joi101.string().optional().allow(null, ""),
|
|
52957
53091
|
remarks: Joi101.string().optional().allow(null, ""),
|
|
52958
|
-
block: Joi101.
|
|
52959
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
52960
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53092
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53093
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53094
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
52961
53095
|
incidentLocation: Joi101.string().optional().allow(null, ""),
|
|
52962
53096
|
isOther: Joi101.boolean().optional().allow(null, ""),
|
|
52963
53097
|
other: Joi101.string().optional().allow(null, ""),
|
|
@@ -52965,9 +53099,9 @@ var affectedInjuredStatusSchema = Joi101.object({
|
|
|
52965
53099
|
});
|
|
52966
53100
|
var anyoneDamageToPropertyStatusSchema = Joi101.object({
|
|
52967
53101
|
description: Joi101.string().optional().allow(null, ""),
|
|
52968
|
-
block: Joi101.
|
|
52969
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
52970
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53102
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53103
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53104
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
52971
53105
|
blkLevelUnit: Joi101.string().optional().allow(null, ""),
|
|
52972
53106
|
name: Joi101.string().optional().allow(null, ""),
|
|
52973
53107
|
contact: Joi101.string().optional().allow(null, ""),
|
|
@@ -52990,9 +53124,9 @@ var schemaIncidentReport = Joi101.object({
|
|
|
52990
53124
|
submittedBy: Joi101.string().optional().allow(null, "")
|
|
52991
53125
|
}).required(),
|
|
52992
53126
|
placeOfIncident: Joi101.object({
|
|
52993
|
-
block: Joi101.
|
|
52994
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
52995
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53127
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53128
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53129
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
52996
53130
|
other: Joi101.string().allow(null, "").optional().allow(null, ""),
|
|
52997
53131
|
isOther: Joi101.boolean().required(),
|
|
52998
53132
|
incidentLocation: Joi101.string().optional().allow(null, "")
|
|
@@ -53071,9 +53205,9 @@ var schemaUpdateIncidentReport = Joi101.object({
|
|
|
53071
53205
|
submittedBy: Joi101.string().optional().allow(null, "")
|
|
53072
53206
|
}).allow(null, ""),
|
|
53073
53207
|
placeOfIncident: Joi101.object({
|
|
53074
|
-
block: Joi101.
|
|
53075
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
53076
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53208
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53209
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53210
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53077
53211
|
other: Joi101.string().allow(null, "").optional().allow(null, ""),
|
|
53078
53212
|
isOther: Joi101.boolean().allow(null, ""),
|
|
53079
53213
|
incidentLocation: Joi101.string().optional().allow(null, "")
|
|
@@ -53181,6 +53315,82 @@ function MIncidentReport(value) {
|
|
|
53181
53315
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53182
53316
|
}
|
|
53183
53317
|
}
|
|
53318
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53319
|
+
if (placeOfIncident) {
|
|
53320
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53321
|
+
try {
|
|
53322
|
+
placeOfIncident.block = new ObjectId109(placeOfIncident.block);
|
|
53323
|
+
} catch {
|
|
53324
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53325
|
+
}
|
|
53326
|
+
}
|
|
53327
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53328
|
+
try {
|
|
53329
|
+
placeOfIncident.level = new ObjectId109(placeOfIncident.level);
|
|
53330
|
+
} catch {
|
|
53331
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53332
|
+
}
|
|
53333
|
+
}
|
|
53334
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53335
|
+
try {
|
|
53336
|
+
placeOfIncident.unit = new ObjectId109(placeOfIncident.unit);
|
|
53337
|
+
} catch {
|
|
53338
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53339
|
+
}
|
|
53340
|
+
}
|
|
53341
|
+
}
|
|
53342
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53343
|
+
if (Array.isArray(affectedInjured)) {
|
|
53344
|
+
affectedInjured.forEach((item) => {
|
|
53345
|
+
if (item.block && typeof item.block === "string") {
|
|
53346
|
+
try {
|
|
53347
|
+
item.block = new ObjectId109(item.block);
|
|
53348
|
+
} catch {
|
|
53349
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53350
|
+
}
|
|
53351
|
+
}
|
|
53352
|
+
if (item.level && typeof item.level === "string") {
|
|
53353
|
+
try {
|
|
53354
|
+
item.level = new ObjectId109(item.level);
|
|
53355
|
+
} catch {
|
|
53356
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53357
|
+
}
|
|
53358
|
+
}
|
|
53359
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53360
|
+
try {
|
|
53361
|
+
item.unit = new ObjectId109(item.unit);
|
|
53362
|
+
} catch {
|
|
53363
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53364
|
+
}
|
|
53365
|
+
}
|
|
53366
|
+
});
|
|
53367
|
+
}
|
|
53368
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53369
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53370
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53371
|
+
if (item.block && typeof item.block === "string") {
|
|
53372
|
+
try {
|
|
53373
|
+
item.block = new ObjectId109(item.block);
|
|
53374
|
+
} catch {
|
|
53375
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53376
|
+
}
|
|
53377
|
+
}
|
|
53378
|
+
if (item.level && typeof item.level === "string") {
|
|
53379
|
+
try {
|
|
53380
|
+
item.level = new ObjectId109(item.level);
|
|
53381
|
+
} catch {
|
|
53382
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53383
|
+
}
|
|
53384
|
+
}
|
|
53385
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53386
|
+
try {
|
|
53387
|
+
item.unit = new ObjectId109(item.unit);
|
|
53388
|
+
} catch {
|
|
53389
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53390
|
+
}
|
|
53391
|
+
}
|
|
53392
|
+
});
|
|
53393
|
+
}
|
|
53184
53394
|
if (incidentInformation?.incidentTypeAndTime?.dateOfIncident && typeof incidentInformation.incidentTypeAndTime.dateOfIncident !== "string") {
|
|
53185
53395
|
incidentInformation.incidentTypeAndTime.dateOfIncident = incidentInformation.incidentTypeAndTime.dateOfIncident.toISOString();
|
|
53186
53396
|
}
|
|
@@ -53529,6 +53739,82 @@ function useIncidentReportRepo() {
|
|
|
53529
53739
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53530
53740
|
}
|
|
53531
53741
|
}
|
|
53742
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53743
|
+
if (placeOfIncident) {
|
|
53744
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53745
|
+
try {
|
|
53746
|
+
placeOfIncident.block = new ObjectId110(placeOfIncident.block);
|
|
53747
|
+
} catch {
|
|
53748
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53749
|
+
}
|
|
53750
|
+
}
|
|
53751
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53752
|
+
try {
|
|
53753
|
+
placeOfIncident.level = new ObjectId110(placeOfIncident.level);
|
|
53754
|
+
} catch {
|
|
53755
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53756
|
+
}
|
|
53757
|
+
}
|
|
53758
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53759
|
+
try {
|
|
53760
|
+
placeOfIncident.unit = new ObjectId110(placeOfIncident.unit);
|
|
53761
|
+
} catch {
|
|
53762
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53763
|
+
}
|
|
53764
|
+
}
|
|
53765
|
+
}
|
|
53766
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53767
|
+
if (Array.isArray(affectedInjured)) {
|
|
53768
|
+
affectedInjured.forEach((item) => {
|
|
53769
|
+
if (item.block && typeof item.block === "string") {
|
|
53770
|
+
try {
|
|
53771
|
+
item.block = new ObjectId110(item.block);
|
|
53772
|
+
} catch {
|
|
53773
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53774
|
+
}
|
|
53775
|
+
}
|
|
53776
|
+
if (item.level && typeof item.level === "string") {
|
|
53777
|
+
try {
|
|
53778
|
+
item.level = new ObjectId110(item.level);
|
|
53779
|
+
} catch {
|
|
53780
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53781
|
+
}
|
|
53782
|
+
}
|
|
53783
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53784
|
+
try {
|
|
53785
|
+
item.unit = new ObjectId110(item.unit);
|
|
53786
|
+
} catch {
|
|
53787
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53788
|
+
}
|
|
53789
|
+
}
|
|
53790
|
+
});
|
|
53791
|
+
}
|
|
53792
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53793
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53794
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53795
|
+
if (item.block && typeof item.block === "string") {
|
|
53796
|
+
try {
|
|
53797
|
+
item.block = new ObjectId110(item.block);
|
|
53798
|
+
} catch {
|
|
53799
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53800
|
+
}
|
|
53801
|
+
}
|
|
53802
|
+
if (item.level && typeof item.level === "string") {
|
|
53803
|
+
try {
|
|
53804
|
+
item.level = new ObjectId110(item.level);
|
|
53805
|
+
} catch {
|
|
53806
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53807
|
+
}
|
|
53808
|
+
}
|
|
53809
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53810
|
+
try {
|
|
53811
|
+
item.unit = new ObjectId110(item.unit);
|
|
53812
|
+
} catch {
|
|
53813
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53814
|
+
}
|
|
53815
|
+
}
|
|
53816
|
+
});
|
|
53817
|
+
}
|
|
53532
53818
|
try {
|
|
53533
53819
|
const res = await collection.updateOne(
|
|
53534
53820
|
{ _id },
|