@7365admin1/core 3.79.1-staging.347 → 3.79.1-staging.348
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/dist/index.d.ts +1 -0
- package/dist/index.js +34 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/unit-owner.test.mjs +67 -16
package/dist/index.d.ts
CHANGED
|
@@ -6626,6 +6626,7 @@ declare function usePersonRepo(): {
|
|
|
6626
6626
|
updateById: (_id: string | ObjectId, value: Partial<TPerson>, session?: ClientSession) => Promise<mongodb.UpdateResult<TPerson>>;
|
|
6627
6627
|
deleteById: (_id: string | ObjectId) => Promise<number>;
|
|
6628
6628
|
getById: (_id: string | ObjectId) => Promise<TPerson | null>;
|
|
6629
|
+
getByIdFresh: (_id: string | ObjectId) => Promise<mongodb.WithId<TPerson> | null>;
|
|
6629
6630
|
setAcceptedTerms: (personId: string | ObjectId, termsId: string | ObjectId) => Promise<void>;
|
|
6630
6631
|
getAcceptedTerms: (personId: string | ObjectId) => Promise<mongodb.WithId<TPerson> | null>;
|
|
6631
6632
|
createTextIndex: () => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -14520,6 +14520,14 @@ function usePersonRepo() {
|
|
|
14520
14520
|
throw error;
|
|
14521
14521
|
}
|
|
14522
14522
|
}
|
|
14523
|
+
async function getByIdFresh(_id) {
|
|
14524
|
+
try {
|
|
14525
|
+
_id = new import_mongodb41.ObjectId(_id);
|
|
14526
|
+
} catch {
|
|
14527
|
+
throw new import_node_server_utils47.BadRequestError("Invalid person ID.");
|
|
14528
|
+
}
|
|
14529
|
+
return collection.findOne({ _id });
|
|
14530
|
+
}
|
|
14523
14531
|
async function getById(_id) {
|
|
14524
14532
|
try {
|
|
14525
14533
|
_id = new import_mongodb41.ObjectId(_id);
|
|
@@ -15253,6 +15261,7 @@ function usePersonRepo() {
|
|
|
15253
15261
|
updateById,
|
|
15254
15262
|
deleteById,
|
|
15255
15263
|
getById,
|
|
15264
|
+
getByIdFresh,
|
|
15256
15265
|
setAcceptedTerms,
|
|
15257
15266
|
getAcceptedTerms,
|
|
15258
15267
|
createTextIndex,
|
|
@@ -44094,15 +44103,18 @@ function holdsUnitOwner(person) {
|
|
|
44094
44103
|
}
|
|
44095
44104
|
return person.isOwner === true;
|
|
44096
44105
|
}
|
|
44097
|
-
function
|
|
44106
|
+
function currentUnitOwner(peopleAtUnit, selfId) {
|
|
44098
44107
|
const self = selfId ? String(selfId) : "";
|
|
44099
44108
|
return (peopleAtUnit ?? []).find(
|
|
44100
44109
|
(person) => holdsUnitOwner(person) && person?.status !== "deleted" /* DELETED */ && String(person?._id ?? "") !== self
|
|
44101
44110
|
);
|
|
44102
44111
|
}
|
|
44103
|
-
function
|
|
44104
|
-
|
|
44105
|
-
|
|
44112
|
+
function mustHandOverBeforeDeactivating(person) {
|
|
44113
|
+
return person?.occupancyRole === "owner" /* OWNER */;
|
|
44114
|
+
}
|
|
44115
|
+
function ownerHandoverRequiredMessage(name) {
|
|
44116
|
+
const who = name?.trim() ? `"${name.trim()}"` : "This person";
|
|
44117
|
+
return `${who} is the owner of this unit. Assign the owner role to another tenant at the same block, level and unit before deactivating them.`;
|
|
44106
44118
|
}
|
|
44107
44119
|
|
|
44108
44120
|
// src/services/person.service.ts
|
|
@@ -44537,17 +44549,21 @@ function usePersonService() {
|
|
|
44537
44549
|
}
|
|
44538
44550
|
return userId.toString();
|
|
44539
44551
|
}
|
|
44540
|
-
async function
|
|
44552
|
+
async function handOverUnitOwner(role, unit, session, selfId) {
|
|
44541
44553
|
if (role !== "owner" /* OWNER */ || !unit)
|
|
44542
44554
|
return;
|
|
44543
44555
|
const peopleAtUnit = await _getPeopleByUnit(
|
|
44544
44556
|
{ status: "active", unit: unit.toString() },
|
|
44545
44557
|
session
|
|
44546
44558
|
);
|
|
44547
|
-
const
|
|
44548
|
-
if (
|
|
44549
|
-
|
|
44550
|
-
|
|
44559
|
+
const incumbent = currentUnitOwner(peopleAtUnit, selfId);
|
|
44560
|
+
if (!incumbent?._id)
|
|
44561
|
+
return;
|
|
44562
|
+
await _updateById(
|
|
44563
|
+
incumbent._id,
|
|
44564
|
+
{ occupancyRole: "occupant" /* OCCUPANT */, isOwner: false },
|
|
44565
|
+
session
|
|
44566
|
+
);
|
|
44551
44567
|
}
|
|
44552
44568
|
async function add(value) {
|
|
44553
44569
|
const session = import_node_server_utils140.useAtlas.getClient()?.startSession();
|
|
@@ -44556,7 +44572,7 @@ function usePersonService() {
|
|
|
44556
44572
|
}
|
|
44557
44573
|
try {
|
|
44558
44574
|
session.startTransaction();
|
|
44559
|
-
await
|
|
44575
|
+
await handOverUnitOwner(
|
|
44560
44576
|
value.occupancyRole,
|
|
44561
44577
|
value.unit,
|
|
44562
44578
|
session
|
|
@@ -44634,7 +44650,7 @@ function usePersonService() {
|
|
|
44634
44650
|
if (value.status === "active" /* ACTIVE */) {
|
|
44635
44651
|
value.deletedAt = "";
|
|
44636
44652
|
}
|
|
44637
|
-
await
|
|
44653
|
+
await handOverUnitOwner(
|
|
44638
44654
|
value.occupancyRole,
|
|
44639
44655
|
value.unit ?? person.unit,
|
|
44640
44656
|
session,
|
|
@@ -59653,7 +59669,8 @@ function usePersonController() {
|
|
|
59653
59669
|
getPeopleByPlateNumber: _getPeopleByPlateNumber,
|
|
59654
59670
|
getPeopleByNRIC: _getPeopleByNRIC,
|
|
59655
59671
|
getByUserId: _getByUserId,
|
|
59656
|
-
getById: _getById
|
|
59672
|
+
getById: _getById,
|
|
59673
|
+
getByIdFresh: _getByIdFresh
|
|
59657
59674
|
} = usePersonRepo();
|
|
59658
59675
|
const {
|
|
59659
59676
|
add: _add,
|
|
@@ -59911,6 +59928,11 @@ function usePersonController() {
|
|
|
59911
59928
|
}
|
|
59912
59929
|
try {
|
|
59913
59930
|
await entitlePerson(req, _id);
|
|
59931
|
+
const person = await _getByIdFresh(_id);
|
|
59932
|
+
if (mustHandOverBeforeDeactivating(person)) {
|
|
59933
|
+
next(new import_node_server_utils151.BadRequestError(ownerHandoverRequiredMessage(person?.name)));
|
|
59934
|
+
return;
|
|
59935
|
+
}
|
|
59914
59936
|
await _deleteById(_id);
|
|
59915
59937
|
res.status(200).json({ message: "Successfully deleted visitor guest." });
|
|
59916
59938
|
return;
|