@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/core
|
|
2
2
|
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6a87d22: release new changes for building, incident report, etc.
|
|
8
|
+
|
|
9
|
+
## 3.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 495dd90: release new changes for person API, user API, etc.
|
|
14
|
+
|
|
3
15
|
## 3.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1952,6 +1952,11 @@ declare function useBuildingRepo(): {
|
|
|
1952
1952
|
message: string;
|
|
1953
1953
|
data: bson.Document[];
|
|
1954
1954
|
}>;
|
|
1955
|
+
getBuildingWithUnitsList: (site: string | ObjectId) => Promise<{
|
|
1956
|
+
success: boolean;
|
|
1957
|
+
message: string;
|
|
1958
|
+
data: bson.Document[];
|
|
1959
|
+
}>;
|
|
1955
1960
|
};
|
|
1956
1961
|
|
|
1957
1962
|
declare function useBuildingService(): {
|
|
@@ -1981,6 +1986,7 @@ declare function useBuildingController(): {
|
|
|
1981
1986
|
uploadSpreadsheetBuilding: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1982
1987
|
getBuildingLevelWithUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1983
1988
|
getBuildingList: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1989
|
+
getBuildingWithUnitsList: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1984
1990
|
};
|
|
1985
1991
|
|
|
1986
1992
|
declare const building_units_namespace_collection = "building-units";
|
|
@@ -5427,9 +5433,9 @@ type TSiteInfo = {
|
|
|
5427
5433
|
submittedBy?: string;
|
|
5428
5434
|
};
|
|
5429
5435
|
type TPlaceOfIncident = {
|
|
5430
|
-
block?:
|
|
5431
|
-
level?: string;
|
|
5432
|
-
unit?: string | ObjectId;
|
|
5436
|
+
block?: string | ObjectId | null;
|
|
5437
|
+
level?: string | ObjectId | null;
|
|
5438
|
+
unit?: string | ObjectId | null;
|
|
5433
5439
|
other?: string | null;
|
|
5434
5440
|
isOther: boolean;
|
|
5435
5441
|
incidentLocation: string;
|
|
@@ -5484,9 +5490,9 @@ type TAffectedInjured = {
|
|
|
5484
5490
|
name: string;
|
|
5485
5491
|
contact?: string;
|
|
5486
5492
|
nric?: string;
|
|
5487
|
-
block?:
|
|
5488
|
-
level?: string;
|
|
5489
|
-
unit?: string | ObjectId;
|
|
5493
|
+
block?: string | ObjectId | null;
|
|
5494
|
+
level?: string | ObjectId | null;
|
|
5495
|
+
unit?: string | ObjectId | null;
|
|
5490
5496
|
other?: string | null;
|
|
5491
5497
|
isOther: boolean;
|
|
5492
5498
|
incidentLocation: string;
|
|
@@ -5495,9 +5501,9 @@ type TAffectedInjured = {
|
|
|
5495
5501
|
};
|
|
5496
5502
|
type TanyoneDamageToProperty = {
|
|
5497
5503
|
description: string;
|
|
5498
|
-
block
|
|
5499
|
-
level
|
|
5500
|
-
unit
|
|
5504
|
+
block?: string | ObjectId | null;
|
|
5505
|
+
level?: string | ObjectId | null;
|
|
5506
|
+
unit?: string | ObjectId | null;
|
|
5501
5507
|
blkLevelUnit: string;
|
|
5502
5508
|
name: string;
|
|
5503
5509
|
contact: string;
|
|
@@ -7342,6 +7348,7 @@ declare function MBuildingLevel(value: TBuildingLevel): {
|
|
|
7342
7348
|
|
|
7343
7349
|
declare const building_level_namespace_collection = "building-levels";
|
|
7344
7350
|
declare function useBuildingLevelRepo(): {
|
|
7351
|
+
createIndexes: () => Promise<void>;
|
|
7345
7352
|
add: (value: TBuildingLevel, session?: ClientSession) => Promise<ObjectId>;
|
|
7346
7353
|
getAll: ({ search, page, limit, sort, site, status, }?: {
|
|
7347
7354
|
search?: string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -11725,12 +11725,28 @@ function useSiteRepo() {
|
|
|
11725
11725
|
{ $match: { "buildings.0": { $exists: true } } },
|
|
11726
11726
|
{
|
|
11727
11727
|
$lookup: {
|
|
11728
|
-
from: "building-
|
|
11728
|
+
from: "building-levels",
|
|
11729
11729
|
let: { buildingIds: "$buildings._id" },
|
|
11730
11730
|
pipeline: [
|
|
11731
11731
|
{
|
|
11732
11732
|
$match: {
|
|
11733
|
-
$expr: { $in: ["$
|
|
11733
|
+
$expr: { $in: ["$blockId", "$$buildingIds"] },
|
|
11734
|
+
status: { $ne: "deleted" }
|
|
11735
|
+
}
|
|
11736
|
+
}
|
|
11737
|
+
],
|
|
11738
|
+
as: "levels"
|
|
11739
|
+
}
|
|
11740
|
+
},
|
|
11741
|
+
{ $match: { "levels.0": { $exists: true } } },
|
|
11742
|
+
{
|
|
11743
|
+
$lookup: {
|
|
11744
|
+
from: "building-units",
|
|
11745
|
+
let: { levelIds: "$levels._id" },
|
|
11746
|
+
pipeline: [
|
|
11747
|
+
{
|
|
11748
|
+
$match: {
|
|
11749
|
+
$expr: { $in: ["$level", "$$levelIds"] },
|
|
11734
11750
|
status: { $ne: "deleted" }
|
|
11735
11751
|
}
|
|
11736
11752
|
},
|
|
@@ -24609,7 +24625,7 @@ function usePersonRepo() {
|
|
|
24609
24625
|
pipeline: [
|
|
24610
24626
|
{
|
|
24611
24627
|
$match: {
|
|
24612
|
-
$expr: { $eq: [
|
|
24628
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24613
24629
|
}
|
|
24614
24630
|
},
|
|
24615
24631
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24625,7 +24641,7 @@ function usePersonRepo() {
|
|
|
24625
24641
|
pipeline: [
|
|
24626
24642
|
{
|
|
24627
24643
|
$match: {
|
|
24628
|
-
$expr: { $eq: [
|
|
24644
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24629
24645
|
}
|
|
24630
24646
|
},
|
|
24631
24647
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24856,7 +24872,7 @@ function usePersonRepo() {
|
|
|
24856
24872
|
pipeline: [
|
|
24857
24873
|
{
|
|
24858
24874
|
$match: {
|
|
24859
|
-
$expr: { $eq: [
|
|
24875
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24860
24876
|
}
|
|
24861
24877
|
},
|
|
24862
24878
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24872,7 +24888,7 @@ function usePersonRepo() {
|
|
|
24872
24888
|
pipeline: [
|
|
24873
24889
|
{
|
|
24874
24890
|
$match: {
|
|
24875
|
-
$expr: { $eq: [
|
|
24891
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24876
24892
|
}
|
|
24877
24893
|
},
|
|
24878
24894
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24946,7 +24962,7 @@ function usePersonRepo() {
|
|
|
24946
24962
|
pipeline: [
|
|
24947
24963
|
{
|
|
24948
24964
|
$match: {
|
|
24949
|
-
$expr: { $eq: [
|
|
24965
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24950
24966
|
}
|
|
24951
24967
|
},
|
|
24952
24968
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24962,7 +24978,7 @@ function usePersonRepo() {
|
|
|
24962
24978
|
pipeline: [
|
|
24963
24979
|
{
|
|
24964
24980
|
$match: {
|
|
24965
|
-
$expr: { $eq: [
|
|
24981
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24966
24982
|
}
|
|
24967
24983
|
},
|
|
24968
24984
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -25427,6 +25443,9 @@ function useBuildingUnitRepo() {
|
|
|
25427
25443
|
}
|
|
25428
25444
|
const collection = db.collection(building_units_namespace_collection);
|
|
25429
25445
|
const visitorCollection = db.collection(visitors_namespace_collection);
|
|
25446
|
+
const buildingUnitCollection = db.collection(
|
|
25447
|
+
site_people_namespace_collection
|
|
25448
|
+
);
|
|
25430
25449
|
const { getCache, setCache, delNamespace, delCache } = (0, import_node_server_utils76.useCache)(
|
|
25431
25450
|
building_units_namespace_collection
|
|
25432
25451
|
);
|
|
@@ -25508,10 +25527,8 @@ function useBuildingUnitRepo() {
|
|
|
25508
25527
|
} catch (error2) {
|
|
25509
25528
|
throw new import_node_server_utils76.BadRequestError("Invalid ID.");
|
|
25510
25529
|
}
|
|
25511
|
-
|
|
25530
|
+
if (value.level) {
|
|
25512
25531
|
value.level = new import_mongodb47.ObjectId(value.level);
|
|
25513
|
-
} catch (error2) {
|
|
25514
|
-
throw new import_node_server_utils76.BadRequestError("Invalid level ID.");
|
|
25515
25532
|
}
|
|
25516
25533
|
if (value.billing && Array.isArray(value.billing)) {
|
|
25517
25534
|
value.billing = value.billing.map((billing) => {
|
|
@@ -25959,6 +25976,12 @@ function useBuildingUnitRepo() {
|
|
|
25959
25976
|
throw new import_node_server_utils76.BadRequestError("Invalid ID.");
|
|
25960
25977
|
}
|
|
25961
25978
|
try {
|
|
25979
|
+
const existingResidents = await buildingUnitCollection.find({ unit: _id }).toArray();
|
|
25980
|
+
if (existingResidents && existingResidents.length > 0) {
|
|
25981
|
+
throw new import_node_server_utils76.BadRequestError(
|
|
25982
|
+
`Cannot delete unit: ${existingResidents.length} resident/s is currently assigned.`
|
|
25983
|
+
);
|
|
25984
|
+
}
|
|
25962
25985
|
const res = await collection.updateOne(
|
|
25963
25986
|
{ _id },
|
|
25964
25987
|
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
@@ -27737,6 +27760,9 @@ function useBuildingRepo() {
|
|
|
27737
27760
|
throw new Error("Unable to connect to server.");
|
|
27738
27761
|
}
|
|
27739
27762
|
const collection = db.collection(buildings_namespace_collection);
|
|
27763
|
+
const buildingUnitCollection = db.collection(
|
|
27764
|
+
building_units_namespace_collection
|
|
27765
|
+
);
|
|
27740
27766
|
const { getCache, setCache, delNamespace } = (0, import_node_server_utils83.useCache)(
|
|
27741
27767
|
buildings_namespace_collection
|
|
27742
27768
|
);
|
|
@@ -27784,24 +27810,30 @@ function useBuildingRepo() {
|
|
|
27784
27810
|
}
|
|
27785
27811
|
}
|
|
27786
27812
|
async function updateById(_id, value, session) {
|
|
27787
|
-
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27788
|
-
if (error) {
|
|
27789
|
-
import_node_server_utils83.logger.info(`Building Repository: ${error.message}`);
|
|
27790
|
-
throw new import_node_server_utils83.BadRequestError(error.message);
|
|
27791
|
-
}
|
|
27792
27813
|
try {
|
|
27793
|
-
|
|
27794
|
-
|
|
27795
|
-
|
|
27796
|
-
|
|
27797
|
-
|
|
27814
|
+
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27815
|
+
if (error) {
|
|
27816
|
+
import_node_server_utils83.logger.info(`Building Repository: ${error.message}`);
|
|
27817
|
+
throw new import_node_server_utils83.BadRequestError(error.message);
|
|
27818
|
+
}
|
|
27798
27819
|
try {
|
|
27799
|
-
|
|
27800
|
-
} catch {
|
|
27801
|
-
throw new import_node_server_utils83.BadRequestError("Invalid
|
|
27820
|
+
_id = new import_mongodb50.ObjectId(_id);
|
|
27821
|
+
} catch (error2) {
|
|
27822
|
+
throw new import_node_server_utils83.BadRequestError("Invalid ID.");
|
|
27802
27823
|
}
|
|
27803
|
-
|
|
27804
|
-
|
|
27824
|
+
if (value.levels && Array.isArray(value.levels)) {
|
|
27825
|
+
try {
|
|
27826
|
+
value.levels = value.levels.map((lvl) => new import_mongodb50.ObjectId(lvl));
|
|
27827
|
+
} catch {
|
|
27828
|
+
throw new import_node_server_utils83.BadRequestError("Invalid level ID format.");
|
|
27829
|
+
}
|
|
27830
|
+
}
|
|
27831
|
+
if (value.name)
|
|
27832
|
+
await buildingUnitCollection.updateMany(
|
|
27833
|
+
{ building: _id, status: "active" /* ACTIVE */ },
|
|
27834
|
+
{ $set: { buildingName: value.name } },
|
|
27835
|
+
{ session }
|
|
27836
|
+
);
|
|
27805
27837
|
const res = await collection.updateOne(
|
|
27806
27838
|
{ _id },
|
|
27807
27839
|
{ $set: value },
|
|
@@ -27809,17 +27841,17 @@ function useBuildingRepo() {
|
|
|
27809
27841
|
);
|
|
27810
27842
|
delCachedData();
|
|
27811
27843
|
return res;
|
|
27812
|
-
} catch (
|
|
27844
|
+
} catch (error) {
|
|
27813
27845
|
import_node_server_utils83.logger.log({
|
|
27814
27846
|
level: "error",
|
|
27815
|
-
message:
|
|
27847
|
+
message: error.message
|
|
27816
27848
|
});
|
|
27817
|
-
const isDuplicated =
|
|
27849
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
27818
27850
|
if (isDuplicated) {
|
|
27819
27851
|
throw new import_node_server_utils83.BadRequestError("Building already exists.");
|
|
27820
27852
|
}
|
|
27821
|
-
if (
|
|
27822
|
-
throw
|
|
27853
|
+
if (error instanceof import_node_server_utils83.AppError) {
|
|
27854
|
+
throw error;
|
|
27823
27855
|
} else {
|
|
27824
27856
|
throw new Error("Failed to update building.");
|
|
27825
27857
|
}
|
|
@@ -28260,6 +28292,49 @@ function useBuildingRepo() {
|
|
|
28260
28292
|
}
|
|
28261
28293
|
}
|
|
28262
28294
|
}
|
|
28295
|
+
async function getBuildingWithUnitsList(site) {
|
|
28296
|
+
try {
|
|
28297
|
+
site = new import_mongodb50.ObjectId(site);
|
|
28298
|
+
} catch (error) {
|
|
28299
|
+
throw new import_node_server_utils83.BadRequestError("Invalid site ID.");
|
|
28300
|
+
}
|
|
28301
|
+
const buildingUnitsQuery = {
|
|
28302
|
+
site,
|
|
28303
|
+
status: "active" /* ACTIVE */
|
|
28304
|
+
};
|
|
28305
|
+
try {
|
|
28306
|
+
const buildingsWithUnits = await buildingUnitCollection.aggregate([
|
|
28307
|
+
{ $match: buildingUnitsQuery },
|
|
28308
|
+
{ $project: { building: 1 } }
|
|
28309
|
+
]).toArray();
|
|
28310
|
+
const buildingIds = [
|
|
28311
|
+
...new Set(buildingsWithUnits.map((l) => l.building.toString()))
|
|
28312
|
+
].map((id) => new import_mongodb50.ObjectId(id));
|
|
28313
|
+
const result = await collection.aggregate([
|
|
28314
|
+
{
|
|
28315
|
+
$match: {
|
|
28316
|
+
_id: { $in: buildingIds }
|
|
28317
|
+
}
|
|
28318
|
+
},
|
|
28319
|
+
{
|
|
28320
|
+
$project: {
|
|
28321
|
+
name: 1
|
|
28322
|
+
}
|
|
28323
|
+
}
|
|
28324
|
+
]).toArray();
|
|
28325
|
+
return {
|
|
28326
|
+
success: true,
|
|
28327
|
+
message: "Buildings with units retrieved successfully",
|
|
28328
|
+
data: result
|
|
28329
|
+
};
|
|
28330
|
+
} catch (error) {
|
|
28331
|
+
if (error instanceof import_node_server_utils83.AppError) {
|
|
28332
|
+
throw error;
|
|
28333
|
+
} else {
|
|
28334
|
+
throw new import_node_server_utils83.InternalServerError("Failed to get buildings.");
|
|
28335
|
+
}
|
|
28336
|
+
}
|
|
28337
|
+
}
|
|
28263
28338
|
return {
|
|
28264
28339
|
createIndexes,
|
|
28265
28340
|
add,
|
|
@@ -28271,7 +28346,8 @@ function useBuildingRepo() {
|
|
|
28271
28346
|
getBuildingLevel,
|
|
28272
28347
|
getBuildingLevelForResident,
|
|
28273
28348
|
getBuildingLevelWithUnits,
|
|
28274
|
-
getBuildingList
|
|
28349
|
+
getBuildingList,
|
|
28350
|
+
getBuildingWithUnitsList
|
|
28275
28351
|
};
|
|
28276
28352
|
}
|
|
28277
28353
|
|
|
@@ -28367,6 +28443,32 @@ function useBuildingLevelRepo() {
|
|
|
28367
28443
|
const { delNamespace: delBuildingNamespace } = (0, import_node_server_utils86.useCache)(
|
|
28368
28444
|
buildings_namespace_collection
|
|
28369
28445
|
);
|
|
28446
|
+
async function createIndexes() {
|
|
28447
|
+
try {
|
|
28448
|
+
await collection.createIndexes([
|
|
28449
|
+
// Ensure name is unique per blockId
|
|
28450
|
+
{
|
|
28451
|
+
key: { blockId: 1, name: 1 },
|
|
28452
|
+
unique: true,
|
|
28453
|
+
name: "unique_name_per_blockId"
|
|
28454
|
+
},
|
|
28455
|
+
// Other useful indexes
|
|
28456
|
+
{ key: { site: 1 }, name: "idx_site" },
|
|
28457
|
+
{ key: { blockId: 1 }, name: "idx_blockId" },
|
|
28458
|
+
{ key: { status: 1 }, name: "idx_status" },
|
|
28459
|
+
{ key: { createdAt: 1 }, name: "idx_createdAt" },
|
|
28460
|
+
// Text index for search
|
|
28461
|
+
{
|
|
28462
|
+
key: {
|
|
28463
|
+
name: "text"
|
|
28464
|
+
},
|
|
28465
|
+
name: "text_search_index"
|
|
28466
|
+
}
|
|
28467
|
+
]);
|
|
28468
|
+
} catch (error) {
|
|
28469
|
+
throw new Error("Failed to create indexes on building levels.");
|
|
28470
|
+
}
|
|
28471
|
+
}
|
|
28370
28472
|
function delCachedData() {
|
|
28371
28473
|
delNamespace().then(() => {
|
|
28372
28474
|
import_node_server_utils86.logger.log({
|
|
@@ -28707,12 +28809,12 @@ function useBuildingLevelRepo() {
|
|
|
28707
28809
|
if (error instanceof import_node_server_utils86.AppError) {
|
|
28708
28810
|
throw error;
|
|
28709
28811
|
} else {
|
|
28710
|
-
throw new import_node_server_utils86.InternalServerError("Failed to get building.");
|
|
28812
|
+
throw new import_node_server_utils86.InternalServerError("Failed to get building level.");
|
|
28711
28813
|
}
|
|
28712
28814
|
}
|
|
28713
28815
|
}
|
|
28714
28816
|
return {
|
|
28715
|
-
|
|
28817
|
+
createIndexes,
|
|
28716
28818
|
add,
|
|
28717
28819
|
getAll,
|
|
28718
28820
|
getById,
|
|
@@ -28991,7 +29093,8 @@ function useBuildingController() {
|
|
|
28991
29093
|
getBuildingLevel: _getBuildingLevel,
|
|
28992
29094
|
getBuildingLevelForResident: _getBuildingLevelForResident,
|
|
28993
29095
|
getBuildingLevelWithUnits: _getBuildingLevelWithUnits,
|
|
28994
|
-
getBuildingList: _getBuildingList
|
|
29096
|
+
getBuildingList: _getBuildingList,
|
|
29097
|
+
getBuildingWithUnitsList: _getBuildingWithUnitsList
|
|
28995
29098
|
} = useBuildingRepo();
|
|
28996
29099
|
const {
|
|
28997
29100
|
updateById: _updateById,
|
|
@@ -29378,6 +29481,28 @@ function useBuildingController() {
|
|
|
29378
29481
|
next(error);
|
|
29379
29482
|
}
|
|
29380
29483
|
}
|
|
29484
|
+
async function getBuildingWithUnitsList(req, res, next) {
|
|
29485
|
+
try {
|
|
29486
|
+
const schema2 = import_joi46.default.object({
|
|
29487
|
+
site: import_joi46.default.string().hex().length(24).required()
|
|
29488
|
+
});
|
|
29489
|
+
const { error, value } = schema2.validate({
|
|
29490
|
+
site: req.params.siteId
|
|
29491
|
+
});
|
|
29492
|
+
if (error) {
|
|
29493
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
29494
|
+
import_node_server_utils88.logger.log({ level: "error", message: messages });
|
|
29495
|
+
next(new import_node_server_utils88.BadRequestError(messages));
|
|
29496
|
+
return;
|
|
29497
|
+
}
|
|
29498
|
+
const { site } = value;
|
|
29499
|
+
const result = await _getBuildingWithUnitsList(site);
|
|
29500
|
+
res.json(result);
|
|
29501
|
+
return;
|
|
29502
|
+
} catch (error) {
|
|
29503
|
+
next(error);
|
|
29504
|
+
}
|
|
29505
|
+
}
|
|
29381
29506
|
return {
|
|
29382
29507
|
createBuilding,
|
|
29383
29508
|
getAll,
|
|
@@ -29389,7 +29514,8 @@ function useBuildingController() {
|
|
|
29389
29514
|
getBuildingLevelForResident,
|
|
29390
29515
|
uploadSpreadsheetBuilding,
|
|
29391
29516
|
getBuildingLevelWithUnits,
|
|
29392
|
-
getBuildingList
|
|
29517
|
+
getBuildingList,
|
|
29518
|
+
getBuildingWithUnitsList
|
|
29393
29519
|
};
|
|
29394
29520
|
}
|
|
29395
29521
|
|
|
@@ -34823,7 +34949,6 @@ function usePersonService() {
|
|
|
34823
34949
|
return "People added successfully.";
|
|
34824
34950
|
} catch (error) {
|
|
34825
34951
|
console.log("error message service", error);
|
|
34826
|
-
console.log("error message service", error.message);
|
|
34827
34952
|
import_node_server_utils111.logger.error("Error in people service add:", error);
|
|
34828
34953
|
await session.abortTransaction();
|
|
34829
34954
|
throw error;
|
|
@@ -34850,6 +34975,15 @@ function usePersonService() {
|
|
|
34850
34975
|
if (value.site && typeof value.site === "string") {
|
|
34851
34976
|
value.site = new import_mongodb65.ObjectId(value.site);
|
|
34852
34977
|
}
|
|
34978
|
+
if (value.block && typeof value.block === "string") {
|
|
34979
|
+
value.block = new import_mongodb65.ObjectId(value.block);
|
|
34980
|
+
}
|
|
34981
|
+
if (value.level && typeof value.level === "string") {
|
|
34982
|
+
value.level = new import_mongodb65.ObjectId(value.level);
|
|
34983
|
+
}
|
|
34984
|
+
if (value.unit && typeof value.unit === "string") {
|
|
34985
|
+
value.unit = new import_mongodb65.ObjectId(value.unit);
|
|
34986
|
+
}
|
|
34853
34987
|
const isOrgChanged = value.org && person.org?.toString() !== value.org.toString();
|
|
34854
34988
|
await _updateById(_id, value, session);
|
|
34855
34989
|
if (isOrgChanged && person.user) {
|
|
@@ -52852,9 +52986,9 @@ var affectedInjuredStatusSchema = import_joi101.default.object({
|
|
|
52852
52986
|
contact: import_joi101.default.string().optional().allow(null, ""),
|
|
52853
52987
|
nric: import_joi101.default.string().optional().allow(null, ""),
|
|
52854
52988
|
remarks: import_joi101.default.string().optional().allow(null, ""),
|
|
52855
|
-
block: import_joi101.default.
|
|
52856
|
-
level: import_joi101.default.string().optional().allow(null, ""),
|
|
52857
|
-
unit: import_joi101.default.string().optional().allow(null, ""),
|
|
52989
|
+
block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52990
|
+
level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52991
|
+
unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52858
52992
|
incidentLocation: import_joi101.default.string().optional().allow(null, ""),
|
|
52859
52993
|
isOther: import_joi101.default.boolean().optional().allow(null, ""),
|
|
52860
52994
|
other: import_joi101.default.string().optional().allow(null, ""),
|
|
@@ -52862,9 +52996,9 @@ var affectedInjuredStatusSchema = import_joi101.default.object({
|
|
|
52862
52996
|
});
|
|
52863
52997
|
var anyoneDamageToPropertyStatusSchema = import_joi101.default.object({
|
|
52864
52998
|
description: import_joi101.default.string().optional().allow(null, ""),
|
|
52865
|
-
block: import_joi101.default.
|
|
52866
|
-
level: import_joi101.default.string().optional().allow(null, ""),
|
|
52867
|
-
unit: import_joi101.default.string().optional().allow(null, ""),
|
|
52999
|
+
block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53000
|
+
level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53001
|
+
unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52868
53002
|
blkLevelUnit: import_joi101.default.string().optional().allow(null, ""),
|
|
52869
53003
|
name: import_joi101.default.string().optional().allow(null, ""),
|
|
52870
53004
|
contact: import_joi101.default.string().optional().allow(null, ""),
|
|
@@ -52887,9 +53021,9 @@ var schemaIncidentReport = import_joi101.default.object({
|
|
|
52887
53021
|
submittedBy: import_joi101.default.string().optional().allow(null, "")
|
|
52888
53022
|
}).required(),
|
|
52889
53023
|
placeOfIncident: import_joi101.default.object({
|
|
52890
|
-
block: import_joi101.default.
|
|
52891
|
-
level: import_joi101.default.string().optional().allow(null, ""),
|
|
52892
|
-
unit: import_joi101.default.string().optional().allow(null, ""),
|
|
53024
|
+
block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53025
|
+
level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53026
|
+
unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52893
53027
|
other: import_joi101.default.string().allow(null, "").optional().allow(null, ""),
|
|
52894
53028
|
isOther: import_joi101.default.boolean().required(),
|
|
52895
53029
|
incidentLocation: import_joi101.default.string().optional().allow(null, "")
|
|
@@ -52968,9 +53102,9 @@ var schemaUpdateIncidentReport = import_joi101.default.object({
|
|
|
52968
53102
|
submittedBy: import_joi101.default.string().optional().allow(null, "")
|
|
52969
53103
|
}).allow(null, ""),
|
|
52970
53104
|
placeOfIncident: import_joi101.default.object({
|
|
52971
|
-
block: import_joi101.default.
|
|
52972
|
-
level: import_joi101.default.string().optional().allow(null, ""),
|
|
52973
|
-
unit: import_joi101.default.string().optional().allow(null, ""),
|
|
53105
|
+
block: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53106
|
+
level: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
53107
|
+
unit: import_joi101.default.string().hex().length(24).optional().allow(null, ""),
|
|
52974
53108
|
other: import_joi101.default.string().allow(null, "").optional().allow(null, ""),
|
|
52975
53109
|
isOther: import_joi101.default.boolean().allow(null, ""),
|
|
52976
53110
|
incidentLocation: import_joi101.default.string().optional().allow(null, "")
|
|
@@ -53078,6 +53212,82 @@ function MIncidentReport(value) {
|
|
|
53078
53212
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53079
53213
|
}
|
|
53080
53214
|
}
|
|
53215
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53216
|
+
if (placeOfIncident) {
|
|
53217
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53218
|
+
try {
|
|
53219
|
+
placeOfIncident.block = new import_mongodb109.ObjectId(placeOfIncident.block);
|
|
53220
|
+
} catch {
|
|
53221
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53222
|
+
}
|
|
53223
|
+
}
|
|
53224
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53225
|
+
try {
|
|
53226
|
+
placeOfIncident.level = new import_mongodb109.ObjectId(placeOfIncident.level);
|
|
53227
|
+
} catch {
|
|
53228
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53229
|
+
}
|
|
53230
|
+
}
|
|
53231
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53232
|
+
try {
|
|
53233
|
+
placeOfIncident.unit = new import_mongodb109.ObjectId(placeOfIncident.unit);
|
|
53234
|
+
} catch {
|
|
53235
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53236
|
+
}
|
|
53237
|
+
}
|
|
53238
|
+
}
|
|
53239
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53240
|
+
if (Array.isArray(affectedInjured)) {
|
|
53241
|
+
affectedInjured.forEach((item) => {
|
|
53242
|
+
if (item.block && typeof item.block === "string") {
|
|
53243
|
+
try {
|
|
53244
|
+
item.block = new import_mongodb109.ObjectId(item.block);
|
|
53245
|
+
} catch {
|
|
53246
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53247
|
+
}
|
|
53248
|
+
}
|
|
53249
|
+
if (item.level && typeof item.level === "string") {
|
|
53250
|
+
try {
|
|
53251
|
+
item.level = new import_mongodb109.ObjectId(item.level);
|
|
53252
|
+
} catch {
|
|
53253
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53254
|
+
}
|
|
53255
|
+
}
|
|
53256
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53257
|
+
try {
|
|
53258
|
+
item.unit = new import_mongodb109.ObjectId(item.unit);
|
|
53259
|
+
} catch {
|
|
53260
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53261
|
+
}
|
|
53262
|
+
}
|
|
53263
|
+
});
|
|
53264
|
+
}
|
|
53265
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53266
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53267
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53268
|
+
if (item.block && typeof item.block === "string") {
|
|
53269
|
+
try {
|
|
53270
|
+
item.block = new import_mongodb109.ObjectId(item.block);
|
|
53271
|
+
} catch {
|
|
53272
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53273
|
+
}
|
|
53274
|
+
}
|
|
53275
|
+
if (item.level && typeof item.level === "string") {
|
|
53276
|
+
try {
|
|
53277
|
+
item.level = new import_mongodb109.ObjectId(item.level);
|
|
53278
|
+
} catch {
|
|
53279
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53280
|
+
}
|
|
53281
|
+
}
|
|
53282
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53283
|
+
try {
|
|
53284
|
+
item.unit = new import_mongodb109.ObjectId(item.unit);
|
|
53285
|
+
} catch {
|
|
53286
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53287
|
+
}
|
|
53288
|
+
}
|
|
53289
|
+
});
|
|
53290
|
+
}
|
|
53081
53291
|
if (incidentInformation?.incidentTypeAndTime?.dateOfIncident && typeof incidentInformation.incidentTypeAndTime.dateOfIncident !== "string") {
|
|
53082
53292
|
incidentInformation.incidentTypeAndTime.dateOfIncident = incidentInformation.incidentTypeAndTime.dateOfIncident.toISOString();
|
|
53083
53293
|
}
|
|
@@ -53413,6 +53623,82 @@ function useIncidentReportRepo() {
|
|
|
53413
53623
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53414
53624
|
}
|
|
53415
53625
|
}
|
|
53626
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53627
|
+
if (placeOfIncident) {
|
|
53628
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53629
|
+
try {
|
|
53630
|
+
placeOfIncident.block = new import_mongodb110.ObjectId(placeOfIncident.block);
|
|
53631
|
+
} catch {
|
|
53632
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53633
|
+
}
|
|
53634
|
+
}
|
|
53635
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53636
|
+
try {
|
|
53637
|
+
placeOfIncident.level = new import_mongodb110.ObjectId(placeOfIncident.level);
|
|
53638
|
+
} catch {
|
|
53639
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53640
|
+
}
|
|
53641
|
+
}
|
|
53642
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53643
|
+
try {
|
|
53644
|
+
placeOfIncident.unit = new import_mongodb110.ObjectId(placeOfIncident.unit);
|
|
53645
|
+
} catch {
|
|
53646
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53647
|
+
}
|
|
53648
|
+
}
|
|
53649
|
+
}
|
|
53650
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53651
|
+
if (Array.isArray(affectedInjured)) {
|
|
53652
|
+
affectedInjured.forEach((item) => {
|
|
53653
|
+
if (item.block && typeof item.block === "string") {
|
|
53654
|
+
try {
|
|
53655
|
+
item.block = new import_mongodb110.ObjectId(item.block);
|
|
53656
|
+
} catch {
|
|
53657
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53658
|
+
}
|
|
53659
|
+
}
|
|
53660
|
+
if (item.level && typeof item.level === "string") {
|
|
53661
|
+
try {
|
|
53662
|
+
item.level = new import_mongodb110.ObjectId(item.level);
|
|
53663
|
+
} catch {
|
|
53664
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53665
|
+
}
|
|
53666
|
+
}
|
|
53667
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53668
|
+
try {
|
|
53669
|
+
item.unit = new import_mongodb110.ObjectId(item.unit);
|
|
53670
|
+
} catch {
|
|
53671
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53672
|
+
}
|
|
53673
|
+
}
|
|
53674
|
+
});
|
|
53675
|
+
}
|
|
53676
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53677
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53678
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53679
|
+
if (item.block && typeof item.block === "string") {
|
|
53680
|
+
try {
|
|
53681
|
+
item.block = new import_mongodb110.ObjectId(item.block);
|
|
53682
|
+
} catch {
|
|
53683
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53684
|
+
}
|
|
53685
|
+
}
|
|
53686
|
+
if (item.level && typeof item.level === "string") {
|
|
53687
|
+
try {
|
|
53688
|
+
item.level = new import_mongodb110.ObjectId(item.level);
|
|
53689
|
+
} catch {
|
|
53690
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53691
|
+
}
|
|
53692
|
+
}
|
|
53693
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53694
|
+
try {
|
|
53695
|
+
item.unit = new import_mongodb110.ObjectId(item.unit);
|
|
53696
|
+
} catch {
|
|
53697
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53698
|
+
}
|
|
53699
|
+
}
|
|
53700
|
+
});
|
|
53701
|
+
}
|
|
53416
53702
|
try {
|
|
53417
53703
|
const res = await collection.updateOne(
|
|
53418
53704
|
{ _id },
|