@7365admin1/core 3.1.0 → 3.3.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 +24 -11
- package/dist/index.js +353 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +352 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -25241,6 +25241,9 @@ function useBuildingUnitRepo() {
|
|
|
25241
25241
|
}
|
|
25242
25242
|
const collection = db.collection(building_units_namespace_collection);
|
|
25243
25243
|
const visitorCollection = db.collection(visitors_namespace_collection);
|
|
25244
|
+
const buildingUnitCollection = db.collection(
|
|
25245
|
+
site_people_namespace_collection
|
|
25246
|
+
);
|
|
25244
25247
|
const { getCache, setCache, delNamespace, delCache } = useCache26(
|
|
25245
25248
|
building_units_namespace_collection
|
|
25246
25249
|
);
|
|
@@ -25322,10 +25325,8 @@ function useBuildingUnitRepo() {
|
|
|
25322
25325
|
} catch (error2) {
|
|
25323
25326
|
throw new BadRequestError74("Invalid ID.");
|
|
25324
25327
|
}
|
|
25325
|
-
|
|
25328
|
+
if (value.level) {
|
|
25326
25329
|
value.level = new ObjectId47(value.level);
|
|
25327
|
-
} catch (error2) {
|
|
25328
|
-
throw new BadRequestError74("Invalid level ID.");
|
|
25329
25330
|
}
|
|
25330
25331
|
if (value.billing && Array.isArray(value.billing)) {
|
|
25331
25332
|
value.billing = value.billing.map((billing) => {
|
|
@@ -25773,6 +25774,12 @@ function useBuildingUnitRepo() {
|
|
|
25773
25774
|
throw new BadRequestError74("Invalid ID.");
|
|
25774
25775
|
}
|
|
25775
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
|
+
}
|
|
25776
25783
|
const res = await collection.updateOne(
|
|
25777
25784
|
{ _id },
|
|
25778
25785
|
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
@@ -27615,24 +27622,30 @@ function useBuildingRepo() {
|
|
|
27615
27622
|
}
|
|
27616
27623
|
}
|
|
27617
27624
|
async function updateById(_id, value, session) {
|
|
27618
|
-
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27619
|
-
if (error) {
|
|
27620
|
-
logger61.info(`Building Repository: ${error.message}`);
|
|
27621
|
-
throw new BadRequestError80(error.message);
|
|
27622
|
-
}
|
|
27623
27625
|
try {
|
|
27624
|
-
|
|
27625
|
-
|
|
27626
|
-
|
|
27627
|
-
|
|
27628
|
-
|
|
27626
|
+
const { error } = schemaBuildingUpdateOptions.validate(value);
|
|
27627
|
+
if (error) {
|
|
27628
|
+
logger61.info(`Building Repository: ${error.message}`);
|
|
27629
|
+
throw new BadRequestError80(error.message);
|
|
27630
|
+
}
|
|
27629
27631
|
try {
|
|
27630
|
-
|
|
27631
|
-
} catch {
|
|
27632
|
-
throw new BadRequestError80("Invalid
|
|
27632
|
+
_id = new ObjectId50(_id);
|
|
27633
|
+
} catch (error2) {
|
|
27634
|
+
throw new BadRequestError80("Invalid ID.");
|
|
27633
27635
|
}
|
|
27634
|
-
|
|
27635
|
-
|
|
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
|
+
);
|
|
27636
27649
|
const res = await collection.updateOne(
|
|
27637
27650
|
{ _id },
|
|
27638
27651
|
{ $set: value },
|
|
@@ -27640,17 +27653,17 @@ function useBuildingRepo() {
|
|
|
27640
27653
|
);
|
|
27641
27654
|
delCachedData();
|
|
27642
27655
|
return res;
|
|
27643
|
-
} catch (
|
|
27656
|
+
} catch (error) {
|
|
27644
27657
|
logger61.log({
|
|
27645
27658
|
level: "error",
|
|
27646
|
-
message:
|
|
27659
|
+
message: error.message
|
|
27647
27660
|
});
|
|
27648
|
-
const isDuplicated =
|
|
27661
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
27649
27662
|
if (isDuplicated) {
|
|
27650
27663
|
throw new BadRequestError80("Building already exists.");
|
|
27651
27664
|
}
|
|
27652
|
-
if (
|
|
27653
|
-
throw
|
|
27665
|
+
if (error instanceof AppError13) {
|
|
27666
|
+
throw error;
|
|
27654
27667
|
} else {
|
|
27655
27668
|
throw new Error("Failed to update building.");
|
|
27656
27669
|
}
|
|
@@ -28257,6 +28270,32 @@ function useBuildingLevelRepo() {
|
|
|
28257
28270
|
const { delNamespace: delBuildingNamespace } = useCache29(
|
|
28258
28271
|
buildings_namespace_collection
|
|
28259
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
|
+
}
|
|
28260
28299
|
function delCachedData() {
|
|
28261
28300
|
delNamespace().then(() => {
|
|
28262
28301
|
logger63.log({
|
|
@@ -28602,7 +28641,7 @@ function useBuildingLevelRepo() {
|
|
|
28602
28641
|
}
|
|
28603
28642
|
}
|
|
28604
28643
|
return {
|
|
28605
|
-
|
|
28644
|
+
createIndexes,
|
|
28606
28645
|
add,
|
|
28607
28646
|
getAll,
|
|
28608
28647
|
getById,
|
|
@@ -35010,10 +35049,37 @@ function usePersonService() {
|
|
|
35010
35049
|
session?.endSession();
|
|
35011
35050
|
}
|
|
35012
35051
|
}
|
|
35052
|
+
async function suspendResidentById(id) {
|
|
35053
|
+
const session = useAtlas53.getClient()?.startSession();
|
|
35054
|
+
if (!session) {
|
|
35055
|
+
throw new BadRequestError104("Database session not available.");
|
|
35056
|
+
}
|
|
35057
|
+
try {
|
|
35058
|
+
session.startTransaction();
|
|
35059
|
+
const person = await _getByUserId(id.toString());
|
|
35060
|
+
if (!person)
|
|
35061
|
+
throw new NotFoundError23("Person not found.");
|
|
35062
|
+
await _updateById(person._id, { status: "deleted" }, session);
|
|
35063
|
+
if (person.user) {
|
|
35064
|
+
await _updateUserFieldById(
|
|
35065
|
+
{ _id: person.user.toString(), field: "status", value: "suspended" },
|
|
35066
|
+
session
|
|
35067
|
+
);
|
|
35068
|
+
}
|
|
35069
|
+
await session.commitTransaction();
|
|
35070
|
+
return "Resident suspended successfully.";
|
|
35071
|
+
} catch (error) {
|
|
35072
|
+
await session.abortTransaction();
|
|
35073
|
+
throw error;
|
|
35074
|
+
} finally {
|
|
35075
|
+
session.endSession();
|
|
35076
|
+
}
|
|
35077
|
+
}
|
|
35013
35078
|
return {
|
|
35014
35079
|
add,
|
|
35015
35080
|
updateById,
|
|
35016
|
-
reviewResidentPerson
|
|
35081
|
+
reviewResidentPerson,
|
|
35082
|
+
suspendResidentById
|
|
35017
35083
|
};
|
|
35018
35084
|
}
|
|
35019
35085
|
|
|
@@ -35033,7 +35099,8 @@ function usePersonController() {
|
|
|
35033
35099
|
const {
|
|
35034
35100
|
add: _add,
|
|
35035
35101
|
updateById: _updateById,
|
|
35036
|
-
reviewResidentPerson: _reviewResidentPerson
|
|
35102
|
+
reviewResidentPerson: _reviewResidentPerson,
|
|
35103
|
+
suspendResidentById: _suspendResidentById
|
|
35037
35104
|
} = usePersonService();
|
|
35038
35105
|
async function add(req, res, next) {
|
|
35039
35106
|
const payload = { ...req.body };
|
|
@@ -35377,6 +35444,26 @@ function usePersonController() {
|
|
|
35377
35444
|
const result = await _reviewResidentPerson(_id, req.body);
|
|
35378
35445
|
res.status(200).json({ message: result });
|
|
35379
35446
|
return;
|
|
35447
|
+
} catch (error2) {
|
|
35448
|
+
console.log("error", error2.message);
|
|
35449
|
+
console.log("error", error2);
|
|
35450
|
+
logger85.log({ level: "error", message: error2.message });
|
|
35451
|
+
next(error2);
|
|
35452
|
+
return;
|
|
35453
|
+
}
|
|
35454
|
+
}
|
|
35455
|
+
async function suspendResidentById(req, res, next) {
|
|
35456
|
+
const _id = req.params.id;
|
|
35457
|
+
const { error } = Joi60.string().hex().required().validate(_id);
|
|
35458
|
+
if (error) {
|
|
35459
|
+
logger85.log({ level: "error", message: error.message });
|
|
35460
|
+
next(new BadRequestError105(error.message));
|
|
35461
|
+
return;
|
|
35462
|
+
}
|
|
35463
|
+
try {
|
|
35464
|
+
const result = await _suspendResidentById(_id);
|
|
35465
|
+
res.status(200).json({ message: result });
|
|
35466
|
+
return;
|
|
35380
35467
|
} catch (error2) {
|
|
35381
35468
|
logger85.log({ level: "error", message: error2.message });
|
|
35382
35469
|
next(error2);
|
|
@@ -35395,7 +35482,8 @@ function usePersonController() {
|
|
|
35395
35482
|
getPeopleByPlateNumber,
|
|
35396
35483
|
getPeopleByNRIC,
|
|
35397
35484
|
getPersonByUserId,
|
|
35398
|
-
reviewResidentPerson
|
|
35485
|
+
reviewResidentPerson,
|
|
35486
|
+
suspendResidentById
|
|
35399
35487
|
};
|
|
35400
35488
|
}
|
|
35401
35489
|
|
|
@@ -53050,9 +53138,9 @@ var affectedInjuredStatusSchema = Joi101.object({
|
|
|
53050
53138
|
contact: Joi101.string().optional().allow(null, ""),
|
|
53051
53139
|
nric: Joi101.string().optional().allow(null, ""),
|
|
53052
53140
|
remarks: Joi101.string().optional().allow(null, ""),
|
|
53053
|
-
block: Joi101.
|
|
53054
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
53055
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53141
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53142
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53143
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53056
53144
|
incidentLocation: Joi101.string().optional().allow(null, ""),
|
|
53057
53145
|
isOther: Joi101.boolean().optional().allow(null, ""),
|
|
53058
53146
|
other: Joi101.string().optional().allow(null, ""),
|
|
@@ -53060,9 +53148,9 @@ var affectedInjuredStatusSchema = Joi101.object({
|
|
|
53060
53148
|
});
|
|
53061
53149
|
var anyoneDamageToPropertyStatusSchema = Joi101.object({
|
|
53062
53150
|
description: Joi101.string().optional().allow(null, ""),
|
|
53063
|
-
block: Joi101.
|
|
53064
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
53065
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53151
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53152
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53153
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53066
53154
|
blkLevelUnit: Joi101.string().optional().allow(null, ""),
|
|
53067
53155
|
name: Joi101.string().optional().allow(null, ""),
|
|
53068
53156
|
contact: Joi101.string().optional().allow(null, ""),
|
|
@@ -53085,9 +53173,9 @@ var schemaIncidentReport = Joi101.object({
|
|
|
53085
53173
|
submittedBy: Joi101.string().optional().allow(null, "")
|
|
53086
53174
|
}).required(),
|
|
53087
53175
|
placeOfIncident: Joi101.object({
|
|
53088
|
-
block: Joi101.
|
|
53089
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
53090
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53176
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53177
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53178
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53091
53179
|
other: Joi101.string().allow(null, "").optional().allow(null, ""),
|
|
53092
53180
|
isOther: Joi101.boolean().required(),
|
|
53093
53181
|
incidentLocation: Joi101.string().optional().allow(null, "")
|
|
@@ -53166,9 +53254,9 @@ var schemaUpdateIncidentReport = Joi101.object({
|
|
|
53166
53254
|
submittedBy: Joi101.string().optional().allow(null, "")
|
|
53167
53255
|
}).allow(null, ""),
|
|
53168
53256
|
placeOfIncident: Joi101.object({
|
|
53169
|
-
block: Joi101.
|
|
53170
|
-
level: Joi101.string().optional().allow(null, ""),
|
|
53171
|
-
unit: Joi101.string().optional().allow(null, ""),
|
|
53257
|
+
block: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53258
|
+
level: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53259
|
+
unit: Joi101.string().hex().length(24).optional().allow(null, ""),
|
|
53172
53260
|
other: Joi101.string().allow(null, "").optional().allow(null, ""),
|
|
53173
53261
|
isOther: Joi101.boolean().allow(null, ""),
|
|
53174
53262
|
incidentLocation: Joi101.string().optional().allow(null, "")
|
|
@@ -53276,6 +53364,82 @@ function MIncidentReport(value) {
|
|
|
53276
53364
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53277
53365
|
}
|
|
53278
53366
|
}
|
|
53367
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53368
|
+
if (placeOfIncident) {
|
|
53369
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53370
|
+
try {
|
|
53371
|
+
placeOfIncident.block = new ObjectId109(placeOfIncident.block);
|
|
53372
|
+
} catch {
|
|
53373
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53374
|
+
}
|
|
53375
|
+
}
|
|
53376
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53377
|
+
try {
|
|
53378
|
+
placeOfIncident.level = new ObjectId109(placeOfIncident.level);
|
|
53379
|
+
} catch {
|
|
53380
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53381
|
+
}
|
|
53382
|
+
}
|
|
53383
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53384
|
+
try {
|
|
53385
|
+
placeOfIncident.unit = new ObjectId109(placeOfIncident.unit);
|
|
53386
|
+
} catch {
|
|
53387
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53388
|
+
}
|
|
53389
|
+
}
|
|
53390
|
+
}
|
|
53391
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53392
|
+
if (Array.isArray(affectedInjured)) {
|
|
53393
|
+
affectedInjured.forEach((item) => {
|
|
53394
|
+
if (item.block && typeof item.block === "string") {
|
|
53395
|
+
try {
|
|
53396
|
+
item.block = new ObjectId109(item.block);
|
|
53397
|
+
} catch {
|
|
53398
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53399
|
+
}
|
|
53400
|
+
}
|
|
53401
|
+
if (item.level && typeof item.level === "string") {
|
|
53402
|
+
try {
|
|
53403
|
+
item.level = new ObjectId109(item.level);
|
|
53404
|
+
} catch {
|
|
53405
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53406
|
+
}
|
|
53407
|
+
}
|
|
53408
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53409
|
+
try {
|
|
53410
|
+
item.unit = new ObjectId109(item.unit);
|
|
53411
|
+
} catch {
|
|
53412
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53413
|
+
}
|
|
53414
|
+
}
|
|
53415
|
+
});
|
|
53416
|
+
}
|
|
53417
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53418
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53419
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53420
|
+
if (item.block && typeof item.block === "string") {
|
|
53421
|
+
try {
|
|
53422
|
+
item.block = new ObjectId109(item.block);
|
|
53423
|
+
} catch {
|
|
53424
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53425
|
+
}
|
|
53426
|
+
}
|
|
53427
|
+
if (item.level && typeof item.level === "string") {
|
|
53428
|
+
try {
|
|
53429
|
+
item.level = new ObjectId109(item.level);
|
|
53430
|
+
} catch {
|
|
53431
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53432
|
+
}
|
|
53433
|
+
}
|
|
53434
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53435
|
+
try {
|
|
53436
|
+
item.unit = new ObjectId109(item.unit);
|
|
53437
|
+
} catch {
|
|
53438
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53439
|
+
}
|
|
53440
|
+
}
|
|
53441
|
+
});
|
|
53442
|
+
}
|
|
53279
53443
|
if (incidentInformation?.incidentTypeAndTime?.dateOfIncident && typeof incidentInformation.incidentTypeAndTime.dateOfIncident !== "string") {
|
|
53280
53444
|
incidentInformation.incidentTypeAndTime.dateOfIncident = incidentInformation.incidentTypeAndTime.dateOfIncident.toISOString();
|
|
53281
53445
|
}
|
|
@@ -53296,7 +53460,7 @@ function MIncidentReport(value) {
|
|
|
53296
53460
|
approvedByName: value.approvedByName ?? "",
|
|
53297
53461
|
remarks: value.remarks ?? null,
|
|
53298
53462
|
status: value.status ?? "pending",
|
|
53299
|
-
|
|
53463
|
+
platform: value.platform ?? "",
|
|
53300
53464
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
53301
53465
|
updatedAt: value.updatedAt,
|
|
53302
53466
|
deletedAt: value.deletedAt
|
|
@@ -53624,6 +53788,82 @@ function useIncidentReportRepo() {
|
|
|
53624
53788
|
throw new Error("Invalid siteInfo.site ID.");
|
|
53625
53789
|
}
|
|
53626
53790
|
}
|
|
53791
|
+
const placeOfIncident = incidentInformation?.placeOfIncident;
|
|
53792
|
+
if (placeOfIncident) {
|
|
53793
|
+
if (placeOfIncident.block && typeof placeOfIncident.block === "string") {
|
|
53794
|
+
try {
|
|
53795
|
+
placeOfIncident.block = new ObjectId110(placeOfIncident.block);
|
|
53796
|
+
} catch {
|
|
53797
|
+
throw new Error("Invalid placeOfIncident.block ID.");
|
|
53798
|
+
}
|
|
53799
|
+
}
|
|
53800
|
+
if (placeOfIncident.level && typeof placeOfIncident.level === "string") {
|
|
53801
|
+
try {
|
|
53802
|
+
placeOfIncident.level = new ObjectId110(placeOfIncident.level);
|
|
53803
|
+
} catch {
|
|
53804
|
+
throw new Error("Invalid placeOfIncident.level ID.");
|
|
53805
|
+
}
|
|
53806
|
+
}
|
|
53807
|
+
if (placeOfIncident.unit && typeof placeOfIncident.unit === "string") {
|
|
53808
|
+
try {
|
|
53809
|
+
placeOfIncident.unit = new ObjectId110(placeOfIncident.unit);
|
|
53810
|
+
} catch {
|
|
53811
|
+
throw new Error("Invalid placeOfIncident.unit ID.");
|
|
53812
|
+
}
|
|
53813
|
+
}
|
|
53814
|
+
}
|
|
53815
|
+
const affectedInjured = value.affectedEntities?.affectedInjured;
|
|
53816
|
+
if (Array.isArray(affectedInjured)) {
|
|
53817
|
+
affectedInjured.forEach((item) => {
|
|
53818
|
+
if (item.block && typeof item.block === "string") {
|
|
53819
|
+
try {
|
|
53820
|
+
item.block = new ObjectId110(item.block);
|
|
53821
|
+
} catch {
|
|
53822
|
+
throw new Error("Invalid affectedInjured.block ID.");
|
|
53823
|
+
}
|
|
53824
|
+
}
|
|
53825
|
+
if (item.level && typeof item.level === "string") {
|
|
53826
|
+
try {
|
|
53827
|
+
item.level = new ObjectId110(item.level);
|
|
53828
|
+
} catch {
|
|
53829
|
+
throw new Error("Invalid affectedInjured.level ID.");
|
|
53830
|
+
}
|
|
53831
|
+
}
|
|
53832
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53833
|
+
try {
|
|
53834
|
+
item.unit = new ObjectId110(item.unit);
|
|
53835
|
+
} catch {
|
|
53836
|
+
throw new Error("Invalid affectedInjured.unit ID.");
|
|
53837
|
+
}
|
|
53838
|
+
}
|
|
53839
|
+
});
|
|
53840
|
+
}
|
|
53841
|
+
const anyoneDamageToProperty = value.affectedEntities?.anyoneDamageToProperty;
|
|
53842
|
+
if (Array.isArray(anyoneDamageToProperty)) {
|
|
53843
|
+
anyoneDamageToProperty.forEach((item) => {
|
|
53844
|
+
if (item.block && typeof item.block === "string") {
|
|
53845
|
+
try {
|
|
53846
|
+
item.block = new ObjectId110(item.block);
|
|
53847
|
+
} catch {
|
|
53848
|
+
throw new Error("Invalid anyoneDamageToProperty.block ID.");
|
|
53849
|
+
}
|
|
53850
|
+
}
|
|
53851
|
+
if (item.level && typeof item.level === "string") {
|
|
53852
|
+
try {
|
|
53853
|
+
item.level = new ObjectId110(item.level);
|
|
53854
|
+
} catch {
|
|
53855
|
+
throw new Error("Invalid anyoneDamageToProperty.level ID.");
|
|
53856
|
+
}
|
|
53857
|
+
}
|
|
53858
|
+
if (item.unit && typeof item.unit === "string") {
|
|
53859
|
+
try {
|
|
53860
|
+
item.unit = new ObjectId110(item.unit);
|
|
53861
|
+
} catch {
|
|
53862
|
+
throw new Error("Invalid anyoneDamageToProperty.unit ID.");
|
|
53863
|
+
}
|
|
53864
|
+
}
|
|
53865
|
+
});
|
|
53866
|
+
}
|
|
53627
53867
|
try {
|
|
53628
53868
|
const res = await collection.updateOne(
|
|
53629
53869
|
{ _id },
|
|
@@ -65133,6 +65373,26 @@ function MFormEntry(value) {
|
|
|
65133
65373
|
deletedAt: value.deletedAt ?? null
|
|
65134
65374
|
};
|
|
65135
65375
|
}
|
|
65376
|
+
var residentFormEntry = Joi144.object({
|
|
65377
|
+
_id: Joi144.string().hex().optional().allow("", null),
|
|
65378
|
+
typeOfForm: Joi144.string().required(),
|
|
65379
|
+
unitNumber: Joi144.string().optional().allow(null, ""),
|
|
65380
|
+
fields: Joi144.object().pattern(
|
|
65381
|
+
Joi144.string(),
|
|
65382
|
+
Joi144.alternatives().try(
|
|
65383
|
+
Joi144.string(),
|
|
65384
|
+
Joi144.number(),
|
|
65385
|
+
Joi144.boolean(),
|
|
65386
|
+
Joi144.valid(null)
|
|
65387
|
+
)
|
|
65388
|
+
).required(),
|
|
65389
|
+
status: Joi144.string().optional().allow("", null),
|
|
65390
|
+
org: Joi144.string().hex().optional().allow("", null),
|
|
65391
|
+
site: Joi144.string().hex().optional().allow("", null),
|
|
65392
|
+
createdAt: Joi144.date().optional().allow("", null),
|
|
65393
|
+
updatedAt: Joi144.date().optional().allow("", null),
|
|
65394
|
+
deletedAt: Joi144.date().optional().allow("", null)
|
|
65395
|
+
});
|
|
65136
65396
|
|
|
65137
65397
|
// src/repositories/online-forms-v2.repository.ts
|
|
65138
65398
|
import {
|
|
@@ -65340,13 +65600,38 @@ function useFormEntryRepo() {
|
|
|
65340
65600
|
throw new Error(error.message);
|
|
65341
65601
|
}
|
|
65342
65602
|
}
|
|
65603
|
+
async function addResidentForm(value, session) {
|
|
65604
|
+
try {
|
|
65605
|
+
value.site = new ObjectId146(value.site);
|
|
65606
|
+
value.org = new ObjectId146(value.org);
|
|
65607
|
+
const res = await collection.insertOne(value, { session });
|
|
65608
|
+
delNamespace().then(() => {
|
|
65609
|
+
logger195.info(
|
|
65610
|
+
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
65611
|
+
);
|
|
65612
|
+
}).catch((err) => {
|
|
65613
|
+
logger195.error(
|
|
65614
|
+
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
65615
|
+
err
|
|
65616
|
+
);
|
|
65617
|
+
});
|
|
65618
|
+
return res.insertedId;
|
|
65619
|
+
} catch (error) {
|
|
65620
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
65621
|
+
if (isDuplicated) {
|
|
65622
|
+
throw new BadRequestError223("Online Form already exists.");
|
|
65623
|
+
}
|
|
65624
|
+
throw error;
|
|
65625
|
+
}
|
|
65626
|
+
}
|
|
65343
65627
|
return {
|
|
65344
65628
|
add,
|
|
65345
65629
|
getAll,
|
|
65346
65630
|
getFormEntryById,
|
|
65347
65631
|
updateFormEntryById,
|
|
65348
65632
|
createTextIndex,
|
|
65349
|
-
deleteOnlineFormById
|
|
65633
|
+
deleteOnlineFormById,
|
|
65634
|
+
addResidentForm
|
|
65350
65635
|
};
|
|
65351
65636
|
}
|
|
65352
65637
|
|
|
@@ -65361,7 +65646,8 @@ function useFormEntryController() {
|
|
|
65361
65646
|
getAll: _getAll,
|
|
65362
65647
|
getFormEntryById: _getFormEntryById,
|
|
65363
65648
|
updateFormEntryById: _updateFormEntryById,
|
|
65364
|
-
deleteOnlineFormById: _deleteOnlineFormById
|
|
65649
|
+
deleteOnlineFormById: _deleteOnlineFormById,
|
|
65650
|
+
addResidentForm: _addResidentForm
|
|
65365
65651
|
} = useFormEntryRepo();
|
|
65366
65652
|
function toCamelCase(str) {
|
|
65367
65653
|
return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
|
|
@@ -65540,13 +65826,35 @@ function useFormEntryController() {
|
|
|
65540
65826
|
return;
|
|
65541
65827
|
}
|
|
65542
65828
|
}
|
|
65829
|
+
async function residentFormSubmission(req, res, next) {
|
|
65830
|
+
const payload = { ...req.body };
|
|
65831
|
+
const { error } = residentFormEntry.validate(payload, {
|
|
65832
|
+
abortEarly: false
|
|
65833
|
+
});
|
|
65834
|
+
if (error) {
|
|
65835
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
65836
|
+
logger196.log({ level: "error", message: messages });
|
|
65837
|
+
next(new BadRequestError224(messages));
|
|
65838
|
+
return;
|
|
65839
|
+
}
|
|
65840
|
+
try {
|
|
65841
|
+
const data = await _addResidentForm(payload);
|
|
65842
|
+
res.status(201).json({ message: data });
|
|
65843
|
+
return;
|
|
65844
|
+
} catch (error2) {
|
|
65845
|
+
logger196.log({ level: "error", message: error2.message });
|
|
65846
|
+
next(error2);
|
|
65847
|
+
return;
|
|
65848
|
+
}
|
|
65849
|
+
}
|
|
65543
65850
|
return {
|
|
65544
65851
|
add,
|
|
65545
65852
|
uploadFormEntrys,
|
|
65546
65853
|
getAll,
|
|
65547
65854
|
getFormEntryById,
|
|
65548
65855
|
updateFormEntryById,
|
|
65549
|
-
deleteFormEntryById
|
|
65856
|
+
deleteFormEntryById,
|
|
65857
|
+
residentFormSubmission
|
|
65550
65858
|
};
|
|
65551
65859
|
}
|
|
65552
65860
|
|
|
@@ -65945,6 +66253,7 @@ export {
|
|
|
65945
66253
|
poolDashboardCollection,
|
|
65946
66254
|
promoCodeSchema,
|
|
65947
66255
|
remarksSchema,
|
|
66256
|
+
residentFormEntry,
|
|
65948
66257
|
robotSchema,
|
|
65949
66258
|
schema,
|
|
65950
66259
|
schemaApprovedBy,
|