@7365admin1/core 2.25.0 → 2.27.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 +138 -51
- package/dist/index.js +500 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +543 -139
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4129,7 +4129,10 @@ function useOrgRepo() {
|
|
|
4129
4129
|
import { ObjectId as ObjectId16 } from "mongodb";
|
|
4130
4130
|
|
|
4131
4131
|
// src/models/site.model.ts
|
|
4132
|
-
import {
|
|
4132
|
+
import {
|
|
4133
|
+
BadRequestError as BadRequestError16,
|
|
4134
|
+
logger as logger11
|
|
4135
|
+
} from "@7365admin1/node-server-utils";
|
|
4133
4136
|
import Joi9 from "joi";
|
|
4134
4137
|
import { ObjectId as ObjectId15 } from "mongodb";
|
|
4135
4138
|
var addressSchema = Joi9.object({
|
|
@@ -4186,7 +4189,9 @@ var siteSchema = Joi9.object({
|
|
|
4186
4189
|
category: Joi9.string().valid(...Object.values(SiteCategories)).default("commercial" /* COMMERCIAL */),
|
|
4187
4190
|
deliveryCompanyList: Joi9.array().items(Joi9.string()).optional().allow(null),
|
|
4188
4191
|
isOpenGate: Joi9.boolean().optional().default(false),
|
|
4189
|
-
dahuaTimeExpiration: Joi9.number().optional().allow(null)
|
|
4192
|
+
dahuaTimeExpiration: Joi9.number().optional().allow(null),
|
|
4193
|
+
siteDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, "")),
|
|
4194
|
+
unitDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, ""))
|
|
4190
4195
|
});
|
|
4191
4196
|
var updateSiteSchema = Joi9.object({
|
|
4192
4197
|
_id: Joi9.string().hex().length(24).required(),
|
|
@@ -4194,7 +4199,9 @@ var updateSiteSchema = Joi9.object({
|
|
|
4194
4199
|
metadata: metadataSchema3.optional(),
|
|
4195
4200
|
deliveryCompanyList: Joi9.array().items(Joi9.string().trim()).optional().allow(null),
|
|
4196
4201
|
isOpenGate: Joi9.boolean().optional().allow(null),
|
|
4197
|
-
dahuaTimeExpiration: Joi9.number().optional().allow(null)
|
|
4202
|
+
dahuaTimeExpiration: Joi9.number().optional().allow(null),
|
|
4203
|
+
siteDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, "")),
|
|
4204
|
+
unitDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, ""))
|
|
4198
4205
|
});
|
|
4199
4206
|
function MSite(value) {
|
|
4200
4207
|
const { error } = siteSchema.validate(value);
|
|
@@ -4221,6 +4228,8 @@ function MSite(value) {
|
|
|
4221
4228
|
deliveryCompanyList: value.deliveryCompanyList ?? [],
|
|
4222
4229
|
isOpenGate: value.isOpenGate,
|
|
4223
4230
|
dahuaTimeExpiration: value.dahuaTimeExpiration,
|
|
4231
|
+
siteDocs: value.siteDocs ?? [],
|
|
4232
|
+
unitDocs: value.unitDocs ?? [],
|
|
4224
4233
|
updatedAt: value.updatedAt ?? "",
|
|
4225
4234
|
deletedAt: value.deletedAt ?? ""
|
|
4226
4235
|
};
|
|
@@ -4237,7 +4246,7 @@ import {
|
|
|
4237
4246
|
logger as logger12,
|
|
4238
4247
|
makeCacheKey as makeCacheKey9,
|
|
4239
4248
|
AppError as AppError4,
|
|
4240
|
-
toObjectId
|
|
4249
|
+
toObjectId as toObjectId2
|
|
4241
4250
|
} from "@7365admin1/node-server-utils";
|
|
4242
4251
|
import Joi10 from "joi";
|
|
4243
4252
|
function useSiteRepo() {
|
|
@@ -4623,7 +4632,7 @@ function useSiteRepo() {
|
|
|
4623
4632
|
}
|
|
4624
4633
|
}
|
|
4625
4634
|
async function updateSiteById(id, payload, session) {
|
|
4626
|
-
const _id =
|
|
4635
|
+
const _id = toObjectId2(id);
|
|
4627
4636
|
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4628
4637
|
try {
|
|
4629
4638
|
const res = await collection.updateOne(
|
|
@@ -8487,7 +8496,7 @@ import {
|
|
|
8487
8496
|
import { z } from "zod";
|
|
8488
8497
|
import { ObjectId as ObjectId25 } from "mongodb";
|
|
8489
8498
|
import { BadRequestError as BadRequestError38 } from "@7365admin1/node-server-utils";
|
|
8490
|
-
function
|
|
8499
|
+
function toObjectId3(value) {
|
|
8491
8500
|
if (typeof value === "string") {
|
|
8492
8501
|
if (!/^[a-fA-F0-9]{24}$/.test(value)) {
|
|
8493
8502
|
throw new BadRequestError38(`Invalid ObjectId format: ${value}`);
|
|
@@ -8539,7 +8548,7 @@ var TInvoice = z.object({
|
|
|
8539
8548
|
message: "Invalid ObjectId: Must be a 24-character hex string."
|
|
8540
8549
|
}),
|
|
8541
8550
|
z.instanceof(ObjectId25, { message: "Invalid ObjectId instance." })
|
|
8542
|
-
]).optional().transform((val) => val ?
|
|
8551
|
+
]).optional().transform((val) => val ? toObjectId3(val) : void 0),
|
|
8543
8552
|
invoiceNumber: z.string({ required_error: "Invoice number is required." }),
|
|
8544
8553
|
type: TInvoiceType.default("other"),
|
|
8545
8554
|
amount: z.number().min(0, { message: "Invoice amount must be at least 0." }),
|
|
@@ -12292,7 +12301,7 @@ import {
|
|
|
12292
12301
|
logger as logger46,
|
|
12293
12302
|
makeCacheKey as makeCacheKey21,
|
|
12294
12303
|
paginate as paginate16,
|
|
12295
|
-
toObjectId as
|
|
12304
|
+
toObjectId as toObjectId5,
|
|
12296
12305
|
useAtlas as useAtlas29,
|
|
12297
12306
|
useCache as useCache22
|
|
12298
12307
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12520,7 +12529,7 @@ function useSiteCameraRepo() {
|
|
|
12520
12529
|
});
|
|
12521
12530
|
}
|
|
12522
12531
|
async function getBySite(site, options = {}) {
|
|
12523
|
-
const _site =
|
|
12532
|
+
const _site = toObjectId5(site);
|
|
12524
12533
|
const cacheKeyOptions = {
|
|
12525
12534
|
site,
|
|
12526
12535
|
tag: "get-by-site",
|
|
@@ -12756,7 +12765,7 @@ import {
|
|
|
12756
12765
|
logger as logger47,
|
|
12757
12766
|
makeCacheKey as makeCacheKey22,
|
|
12758
12767
|
paginate as paginate17,
|
|
12759
|
-
toObjectId as
|
|
12768
|
+
toObjectId as toObjectId6,
|
|
12760
12769
|
useAtlas as useAtlas30,
|
|
12761
12770
|
useCache as useCache23
|
|
12762
12771
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12769,17 +12778,22 @@ import { ObjectId as ObjectId38 } from "mongodb";
|
|
|
12769
12778
|
import { BadRequestError as BadRequestError64 } from "@7365admin1/node-server-utils";
|
|
12770
12779
|
import Joi35 from "joi";
|
|
12771
12780
|
import { ObjectId as ObjectId37 } from "mongodb";
|
|
12772
|
-
var PersonTypes = /* @__PURE__ */ ((
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
return
|
|
12781
|
+
var PersonTypes = /* @__PURE__ */ ((PersonTypes3) => {
|
|
12782
|
+
PersonTypes3["WALK_IN"] = "walk-in";
|
|
12783
|
+
PersonTypes3["DROP_OFF"] = "drop-off";
|
|
12784
|
+
PersonTypes3["CONTRACTOR"] = "contractor";
|
|
12785
|
+
PersonTypes3["DELIVERY"] = "delivery";
|
|
12786
|
+
PersonTypes3["PICK_UP"] = "pick-up";
|
|
12787
|
+
PersonTypes3["GUEST"] = "guest";
|
|
12788
|
+
PersonTypes3["TENANT"] = "tenant";
|
|
12789
|
+
PersonTypes3["RESIDENT"] = "resident";
|
|
12790
|
+
return PersonTypes3;
|
|
12782
12791
|
})(PersonTypes || {});
|
|
12792
|
+
var PersonStatus = /* @__PURE__ */ ((PersonStatus2) => {
|
|
12793
|
+
PersonStatus2["ACTIVE"] = "active";
|
|
12794
|
+
PersonStatus2["DELETED"] = "deleted";
|
|
12795
|
+
return PersonStatus2;
|
|
12796
|
+
})(PersonStatus || {});
|
|
12783
12797
|
var PERSON_TYPES = [
|
|
12784
12798
|
"walk-in",
|
|
12785
12799
|
"drop-off",
|
|
@@ -13250,7 +13264,7 @@ function useVisitorTransactionRepo() {
|
|
|
13250
13264
|
}
|
|
13251
13265
|
}
|
|
13252
13266
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
13253
|
-
const _site = typeof site === "string" ? site :
|
|
13267
|
+
const _site = typeof site === "string" ? site : toObjectId6(site);
|
|
13254
13268
|
const cacheKey = makeCacheKey22(visitors_namespace_collection, {
|
|
13255
13269
|
plateNumber,
|
|
13256
13270
|
key: "get-open-transaction-plate-number",
|
|
@@ -13367,7 +13381,7 @@ function useVisitorTransactionRepo() {
|
|
|
13367
13381
|
}
|
|
13368
13382
|
}
|
|
13369
13383
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
13370
|
-
const site =
|
|
13384
|
+
const site = toObjectId6(siteId);
|
|
13371
13385
|
try {
|
|
13372
13386
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13373
13387
|
const expiredTransactions = await collection.find({
|
|
@@ -13460,6 +13474,7 @@ var VehicleSort = /* @__PURE__ */ ((VehicleSort2) => {
|
|
|
13460
13474
|
VehicleSort2["NAME"] = "name";
|
|
13461
13475
|
VehicleSort2["START"] = "start";
|
|
13462
13476
|
VehicleSort2["END"] = "end";
|
|
13477
|
+
VehicleSort2["UPDATED_AT"] = "updatedAt";
|
|
13463
13478
|
return VehicleSort2;
|
|
13464
13479
|
})(VehicleSort || {});
|
|
13465
13480
|
var OrgNature = /* @__PURE__ */ ((OrgNature2) => {
|
|
@@ -13498,7 +13513,8 @@ var vehicleSchema = Joi37.object({
|
|
|
13498
13513
|
start: Joi37.date().optional().allow("", null),
|
|
13499
13514
|
end: Joi37.date().optional().allow("", null),
|
|
13500
13515
|
unitName: Joi37.string().optional().allow("", null),
|
|
13501
|
-
status: Joi37.string().optional().valid(...Object.values(VehicleStatus)).allow("")
|
|
13516
|
+
status: Joi37.string().optional().valid(...Object.values(VehicleStatus)).allow(""),
|
|
13517
|
+
peopleId: Joi37.string().hex().length(24).optional().allow(null, "")
|
|
13502
13518
|
});
|
|
13503
13519
|
function MVehicle(value) {
|
|
13504
13520
|
const { error } = vehicleSchema.validate(value);
|
|
@@ -13527,6 +13543,13 @@ function MVehicle(value) {
|
|
|
13527
13543
|
throw new BadRequestError66("Invalid building unit ID format.");
|
|
13528
13544
|
}
|
|
13529
13545
|
}
|
|
13546
|
+
if (value.peopleId) {
|
|
13547
|
+
try {
|
|
13548
|
+
value.peopleId = new ObjectId40(value.peopleId);
|
|
13549
|
+
} catch (error2) {
|
|
13550
|
+
throw new BadRequestError66("Invalid building unit ID format.");
|
|
13551
|
+
}
|
|
13552
|
+
}
|
|
13530
13553
|
const createdAtDate = value.createdAt ? new Date(value.createdAt) : /* @__PURE__ */ new Date();
|
|
13531
13554
|
const expiredDate = new Date(createdAtDate);
|
|
13532
13555
|
expiredDate.setFullYear(expiredDate.getFullYear() + 10);
|
|
@@ -13551,8 +13574,9 @@ function MVehicle(value) {
|
|
|
13551
13574
|
end: value.end ?? expiredAt,
|
|
13552
13575
|
status: value.status ?? "active" /* ACTIVE */,
|
|
13553
13576
|
unitName: value.unitName ?? "",
|
|
13577
|
+
peopleId: value.peopleId ?? "",
|
|
13554
13578
|
createdAt,
|
|
13555
|
-
updatedAt: value.updatedAt ??
|
|
13579
|
+
updatedAt: value.updatedAt ?? createdAt,
|
|
13556
13580
|
deletedAt: value.deletedAt ?? ""
|
|
13557
13581
|
};
|
|
13558
13582
|
}
|
|
@@ -13615,7 +13639,7 @@ import {
|
|
|
13615
13639
|
makeCacheKey as makeCacheKey23,
|
|
13616
13640
|
NotFoundError as NotFoundError17,
|
|
13617
13641
|
paginate as paginate18,
|
|
13618
|
-
toObjectId as
|
|
13642
|
+
toObjectId as toObjectId7,
|
|
13619
13643
|
useAtlas as useAtlas31,
|
|
13620
13644
|
useCache as useCache24
|
|
13621
13645
|
} from "@7365admin1/node-server-utils";
|
|
@@ -13702,7 +13726,6 @@ function useVehicleRepo() {
|
|
|
13702
13726
|
...category && { category }
|
|
13703
13727
|
};
|
|
13704
13728
|
let query = { ...baseQuery };
|
|
13705
|
-
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
13706
13729
|
const cacheOptions = {
|
|
13707
13730
|
...status && { status },
|
|
13708
13731
|
...type && { type },
|
|
@@ -13748,7 +13771,9 @@ function useVehicleRepo() {
|
|
|
13748
13771
|
unitName: "$unit.name",
|
|
13749
13772
|
recNo: 1,
|
|
13750
13773
|
nric: 1,
|
|
13751
|
-
plateNumber: 1
|
|
13774
|
+
plateNumber: 1,
|
|
13775
|
+
createdAt: 1,
|
|
13776
|
+
updatedAt: 1
|
|
13752
13777
|
}
|
|
13753
13778
|
},
|
|
13754
13779
|
{
|
|
@@ -13776,6 +13801,8 @@ function useVehicleRepo() {
|
|
|
13776
13801
|
unit: { $first: "$unit" },
|
|
13777
13802
|
unitName: { $first: "$unitName" },
|
|
13778
13803
|
nric: { $first: "$nric" },
|
|
13804
|
+
createdAt: { $min: "$createdAt" },
|
|
13805
|
+
updatedAt: { $max: "$updatedAt" },
|
|
13779
13806
|
plates: {
|
|
13780
13807
|
$addToSet: {
|
|
13781
13808
|
_id: "$_id",
|
|
@@ -13811,10 +13838,19 @@ function useVehicleRepo() {
|
|
|
13811
13838
|
]
|
|
13812
13839
|
}
|
|
13813
13840
|
}
|
|
13841
|
+
},
|
|
13842
|
+
createdAt: 1,
|
|
13843
|
+
updatedAt: 1
|
|
13844
|
+
}
|
|
13845
|
+
},
|
|
13846
|
+
{
|
|
13847
|
+
$addFields: {
|
|
13848
|
+
sortDate: {
|
|
13849
|
+
$ifNull: ["$updatedAt", "$createdAt"]
|
|
13814
13850
|
}
|
|
13815
13851
|
}
|
|
13816
13852
|
},
|
|
13817
|
-
{ $sort:
|
|
13853
|
+
{ $sort: { sortDate: -1 } },
|
|
13818
13854
|
{ $skip: page * limit },
|
|
13819
13855
|
{ $limit: limit }
|
|
13820
13856
|
];
|
|
@@ -14340,7 +14376,7 @@ function useVehicleRepo() {
|
|
|
14340
14376
|
page = page > 0 ? page - 1 : 0;
|
|
14341
14377
|
const skip = page * limit;
|
|
14342
14378
|
try {
|
|
14343
|
-
const unit =
|
|
14379
|
+
const unit = toObjectId7(unitId);
|
|
14344
14380
|
const query = {
|
|
14345
14381
|
unit
|
|
14346
14382
|
};
|
|
@@ -14413,7 +14449,7 @@ import {
|
|
|
14413
14449
|
useAtlas as useAtlas32,
|
|
14414
14450
|
useCache as useCache25,
|
|
14415
14451
|
AppError as AppError10,
|
|
14416
|
-
toObjectId as
|
|
14452
|
+
toObjectId as toObjectId8
|
|
14417
14453
|
} from "@7365admin1/node-server-utils";
|
|
14418
14454
|
import { ObjectId as ObjectId42 } from "mongodb";
|
|
14419
14455
|
var site_people_namespace_collection = "site.people";
|
|
@@ -14727,7 +14763,7 @@ function usePersonRepo() {
|
|
|
14727
14763
|
}
|
|
14728
14764
|
async function getPeopleByUnit({
|
|
14729
14765
|
status = "active",
|
|
14730
|
-
type,
|
|
14766
|
+
type = [],
|
|
14731
14767
|
unit
|
|
14732
14768
|
}, session) {
|
|
14733
14769
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
@@ -14736,13 +14772,20 @@ function usePersonRepo() {
|
|
|
14736
14772
|
type,
|
|
14737
14773
|
key: "get-residents-by-unit"
|
|
14738
14774
|
});
|
|
14775
|
+
const cacheData = await getCache(cacheKey);
|
|
14776
|
+
if (cacheData) {
|
|
14777
|
+
logger50.info(`Cache hit for key: ${cacheKey}`);
|
|
14778
|
+
return cacheData;
|
|
14779
|
+
}
|
|
14739
14780
|
try {
|
|
14740
|
-
const
|
|
14741
|
-
|
|
14742
|
-
|
|
14743
|
-
|
|
14744
|
-
|
|
14745
|
-
|
|
14781
|
+
const query = {
|
|
14782
|
+
unit,
|
|
14783
|
+
status,
|
|
14784
|
+
...Array.isArray(type) && type.length > 0 && {
|
|
14785
|
+
type: { $in: type }
|
|
14786
|
+
}
|
|
14787
|
+
};
|
|
14788
|
+
const data = await collection.find(query).sort({ _id: -1 }).toArray();
|
|
14746
14789
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
14747
14790
|
logger50.info(`Cache set for key: ${cacheKey}`);
|
|
14748
14791
|
}).catch((err) => {
|
|
@@ -14884,13 +14927,14 @@ function usePersonRepo() {
|
|
|
14884
14927
|
throw new InternalServerError25("Failed to retrieve person by NRIC.");
|
|
14885
14928
|
}
|
|
14886
14929
|
}
|
|
14887
|
-
async function
|
|
14930
|
+
async function pushVehicleById(id, plate, session) {
|
|
14888
14931
|
const { plateNumber, recNo } = plate;
|
|
14889
14932
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
14933
|
+
const _id = toObjectId8(id);
|
|
14890
14934
|
try {
|
|
14891
14935
|
const updateExisting = await collection.updateOne(
|
|
14892
14936
|
{
|
|
14893
|
-
|
|
14937
|
+
_id,
|
|
14894
14938
|
"plates.plateNumber": plateNumber
|
|
14895
14939
|
},
|
|
14896
14940
|
{
|
|
@@ -14903,7 +14947,7 @@ function usePersonRepo() {
|
|
|
14903
14947
|
);
|
|
14904
14948
|
if (updateExisting.matchedCount === 0) {
|
|
14905
14949
|
await collection.updateOne(
|
|
14906
|
-
{
|
|
14950
|
+
{ _id },
|
|
14907
14951
|
{
|
|
14908
14952
|
$push: {
|
|
14909
14953
|
plates: {
|
|
@@ -14944,7 +14988,7 @@ function usePersonRepo() {
|
|
|
14944
14988
|
}
|
|
14945
14989
|
}
|
|
14946
14990
|
async function getByUserId(userId) {
|
|
14947
|
-
const user =
|
|
14991
|
+
const user = toObjectId8(userId);
|
|
14948
14992
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
14949
14993
|
user: userId
|
|
14950
14994
|
});
|
|
@@ -14995,7 +15039,7 @@ function usePersonRepo() {
|
|
|
14995
15039
|
getCompany,
|
|
14996
15040
|
getPeopleByPlateNumber,
|
|
14997
15041
|
getPeopleByNRIC,
|
|
14998
|
-
|
|
15042
|
+
pushVehicleById,
|
|
14999
15043
|
pullVehicleByRecNo,
|
|
15000
15044
|
getByUserId
|
|
15001
15045
|
};
|
|
@@ -15026,7 +15070,7 @@ function useVehicleService() {
|
|
|
15026
15070
|
} = useDahuaService();
|
|
15027
15071
|
const { getAllCameraWithPassword: _getAllSiteCameras } = useSiteCameraRepo();
|
|
15028
15072
|
const { getById: _getById } = useOrgRepo();
|
|
15029
|
-
const {
|
|
15073
|
+
const { pushVehicleById: _pushVehicleById } = usePersonRepo();
|
|
15030
15074
|
const { pullVehicleByRecNo: _pullVehicleByRecNo } = usePersonRepo();
|
|
15031
15075
|
async function add(value) {
|
|
15032
15076
|
const session = useAtlas33.getClient()?.startSession();
|
|
@@ -15133,9 +15177,9 @@ function useVehicleService() {
|
|
|
15133
15177
|
}
|
|
15134
15178
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
15135
15179
|
vehicleValue.recNo = responseData.split("=")[1]?.trim();
|
|
15136
|
-
if (value.
|
|
15137
|
-
await
|
|
15138
|
-
value.
|
|
15180
|
+
if (value.peopleId && vehicleValue.recNo) {
|
|
15181
|
+
await _pushVehicleById(
|
|
15182
|
+
value.peopleId,
|
|
15139
15183
|
{
|
|
15140
15184
|
plateNumber,
|
|
15141
15185
|
recNo: vehicleValue.recNo
|
|
@@ -15295,9 +15339,9 @@ function useVehicleService() {
|
|
|
15295
15339
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
15296
15340
|
}
|
|
15297
15341
|
value.status = "active" /* ACTIVE */;
|
|
15298
|
-
if (vehicle.
|
|
15299
|
-
await
|
|
15300
|
-
vehicle.
|
|
15342
|
+
if (vehicle.peopleId && value.recNo) {
|
|
15343
|
+
await _pushVehicleById(
|
|
15344
|
+
vehicle.peopleId,
|
|
15301
15345
|
{
|
|
15302
15346
|
plateNumber: _plateNumber,
|
|
15303
15347
|
recNo: value.recNo
|
|
@@ -15412,9 +15456,9 @@ function useVehicleService() {
|
|
|
15412
15456
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
15413
15457
|
}
|
|
15414
15458
|
value.status = "active" /* ACTIVE */;
|
|
15415
|
-
if (vehicle.
|
|
15416
|
-
await
|
|
15417
|
-
vehicle.
|
|
15459
|
+
if (vehicle.peopleId && value.recNo) {
|
|
15460
|
+
await _pushVehicleById(
|
|
15461
|
+
vehicle.peopleId,
|
|
15418
15462
|
{
|
|
15419
15463
|
plateNumber: _plateNumber,
|
|
15420
15464
|
recNo: value.recNo
|
|
@@ -15451,7 +15495,7 @@ function useVehicleService() {
|
|
|
15451
15495
|
const _start = vehicle.start;
|
|
15452
15496
|
const _end = vehicle.end;
|
|
15453
15497
|
const _recNo = plate.recNo;
|
|
15454
|
-
const _type = plate.type;
|
|
15498
|
+
const _type = value.type ? value.type : plate.type;
|
|
15455
15499
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
15456
15500
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
15457
15501
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -15479,20 +15523,60 @@ function useVehicleService() {
|
|
|
15479
15523
|
}
|
|
15480
15524
|
for (const camera of siteCameras) {
|
|
15481
15525
|
const { host, username, password } = camera;
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
|
|
15493
|
-
|
|
15494
|
-
|
|
15495
|
-
|
|
15526
|
+
if (value.type) {
|
|
15527
|
+
const removePlateNumber = {
|
|
15528
|
+
host,
|
|
15529
|
+
username,
|
|
15530
|
+
password,
|
|
15531
|
+
mode: plate.type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15532
|
+
//whitelist or blocklist
|
|
15533
|
+
recno: _recNo
|
|
15534
|
+
};
|
|
15535
|
+
const responseForDeletion = await _removePlateNumber(
|
|
15536
|
+
removePlateNumber
|
|
15537
|
+
);
|
|
15538
|
+
if (responseForDeletion?.statusCode !== 200) {
|
|
15539
|
+
throw new BadRequestError69(
|
|
15540
|
+
"Failed to delete plate number to ANPR"
|
|
15541
|
+
);
|
|
15542
|
+
}
|
|
15543
|
+
const dahuaPayload = {
|
|
15544
|
+
host,
|
|
15545
|
+
username,
|
|
15546
|
+
password,
|
|
15547
|
+
plateNumber: _plateNumber,
|
|
15548
|
+
mode: value.type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15549
|
+
//whitelist or blocklist
|
|
15550
|
+
owner: _name,
|
|
15551
|
+
...startDahua ? { start: startDahua } : {},
|
|
15552
|
+
...endDahua ? { end: endDahua } : {}
|
|
15553
|
+
};
|
|
15554
|
+
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
15555
|
+
if (dahuaResponse?.statusCode !== 200) {
|
|
15556
|
+
throw new BadRequestError69(
|
|
15557
|
+
"Failed to update plate number to ANPR"
|
|
15558
|
+
);
|
|
15559
|
+
}
|
|
15560
|
+
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
15561
|
+
value.recNo = responseData.split("=")[1]?.trim();
|
|
15562
|
+
} else {
|
|
15563
|
+
const dahuaPayload = {
|
|
15564
|
+
host,
|
|
15565
|
+
username,
|
|
15566
|
+
password,
|
|
15567
|
+
plateNumber: plateNumber ? plateNumber : _plateNumber,
|
|
15568
|
+
recno: _recNo,
|
|
15569
|
+
mode: _type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15570
|
+
start: startDahua,
|
|
15571
|
+
end: endDahua,
|
|
15572
|
+
owner: name ? name : _name
|
|
15573
|
+
};
|
|
15574
|
+
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
15575
|
+
if (dahuaResponse?.statusCode !== 200) {
|
|
15576
|
+
throw new BadRequestError69(
|
|
15577
|
+
"Failed to update plate number to ANPR"
|
|
15578
|
+
);
|
|
15579
|
+
}
|
|
15496
15580
|
}
|
|
15497
15581
|
}
|
|
15498
15582
|
}
|
|
@@ -15504,7 +15588,9 @@ function useVehicleService() {
|
|
|
15504
15588
|
...end && { end },
|
|
15505
15589
|
...unit && {
|
|
15506
15590
|
unit: typeof unit === "string" ? new ObjectId43(unit) : unit
|
|
15507
|
-
}
|
|
15591
|
+
},
|
|
15592
|
+
...value.recNo && { recNo: value.recNo },
|
|
15593
|
+
...type && { type: value.type }
|
|
15508
15594
|
};
|
|
15509
15595
|
await _updateVehicleById(_id, formattedValue, session);
|
|
15510
15596
|
await session.commitTransaction();
|
|
@@ -17014,7 +17100,7 @@ import {
|
|
|
17014
17100
|
logger as logger60,
|
|
17015
17101
|
makeCacheKey as makeCacheKey26,
|
|
17016
17102
|
paginate as paginate21,
|
|
17017
|
-
toObjectId as
|
|
17103
|
+
toObjectId as toObjectId10,
|
|
17018
17104
|
useAtlas as useAtlas37,
|
|
17019
17105
|
useCache as useCache28
|
|
17020
17106
|
} from "@7365admin1/node-server-utils";
|
|
@@ -17176,8 +17262,8 @@ function useBuildingUnitRepo() {
|
|
|
17176
17262
|
const query = {
|
|
17177
17263
|
status,
|
|
17178
17264
|
...search && { $text: { $search: search } },
|
|
17179
|
-
...site && { site:
|
|
17180
|
-
...building && { building:
|
|
17265
|
+
...site && { site: toObjectId10(site) },
|
|
17266
|
+
...building && { building: toObjectId10(building) }
|
|
17181
17267
|
};
|
|
17182
17268
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17183
17269
|
const cacheParams = {
|
|
@@ -18196,7 +18282,7 @@ function useVehicleController() {
|
|
|
18196
18282
|
search: Joi46.string().optional().allow("", null),
|
|
18197
18283
|
page: Joi46.number().integer().min(1).optional().default(1),
|
|
18198
18284
|
limit: Joi46.number().integer().min(1).max(100).optional().default(10),
|
|
18199
|
-
sort: Joi46.string().optional().valid(...Object.values(VehicleSort)),
|
|
18285
|
+
sort: Joi46.string().optional().valid(...Object.values(VehicleSort)).default("updatedAt" /* UPDATED_AT */),
|
|
18200
18286
|
order: Joi46.string().optional().valid(...Object.values(SortOrder)),
|
|
18201
18287
|
type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
18202
18288
|
category: Joi46.string().optional().valid(...Object.values(VehicleCategory)).allow(null, ""),
|
|
@@ -18212,15 +18298,20 @@ function useVehicleController() {
|
|
|
18212
18298
|
return;
|
|
18213
18299
|
}
|
|
18214
18300
|
const { search, page, limit, type, category, status, sort, order } = value;
|
|
18215
|
-
|
|
18216
|
-
|
|
18217
|
-
|
|
18301
|
+
let sortObj;
|
|
18302
|
+
if (sort === "updatedAt" /* UPDATED_AT */) {
|
|
18303
|
+
sortObj = order === "asc" /* ASC */ ? { updatedAt: 1, createdAt: 1, _id: 1 } : { updatedAt: -1, createdAt: -1, _id: -1 };
|
|
18304
|
+
} else {
|
|
18305
|
+
sortObj = {
|
|
18306
|
+
[sort]: order === "asc" /* ASC */ ? 1 : -1
|
|
18307
|
+
};
|
|
18308
|
+
}
|
|
18218
18309
|
try {
|
|
18219
18310
|
const data = await _getVehicles({
|
|
18220
18311
|
search,
|
|
18221
18312
|
page,
|
|
18222
18313
|
limit,
|
|
18223
|
-
sort: sortObj,
|
|
18314
|
+
// sort: sortObj,
|
|
18224
18315
|
type,
|
|
18225
18316
|
category,
|
|
18226
18317
|
status
|
|
@@ -19257,8 +19348,24 @@ function useCustomerSiteController() {
|
|
|
19257
19348
|
import { BadRequestError as BadRequestError88, logger as logger69 } from "@7365admin1/node-server-utils";
|
|
19258
19349
|
import Joi51 from "joi";
|
|
19259
19350
|
import { ObjectId as ObjectId50 } from "mongodb";
|
|
19351
|
+
|
|
19352
|
+
// src/models/base.model.ts
|
|
19353
|
+
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
19354
|
+
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
19355
|
+
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
19356
|
+
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
19357
|
+
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
19358
|
+
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
19359
|
+
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
19360
|
+
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
19361
|
+
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
19362
|
+
return AppServiceType2;
|
|
19363
|
+
})(AppServiceType || {});
|
|
19364
|
+
|
|
19365
|
+
// src/models/attendance-settings.model.ts
|
|
19260
19366
|
var attendanceSettingsSchema = Joi51.object({
|
|
19261
19367
|
site: Joi51.string().hex().required(),
|
|
19368
|
+
serviceType: Joi51.string().valid(...Object.values(AppServiceType)).required(),
|
|
19262
19369
|
isLocationEnabled: Joi51.boolean().required(),
|
|
19263
19370
|
location: Joi51.when("isLocationEnabled", {
|
|
19264
19371
|
is: true,
|
|
@@ -19301,6 +19408,7 @@ function MAttendanceSettings(value) {
|
|
|
19301
19408
|
}
|
|
19302
19409
|
return {
|
|
19303
19410
|
site: value.site,
|
|
19411
|
+
serviceType: value.serviceType,
|
|
19304
19412
|
isLocationEnabled: value.isLocationEnabled,
|
|
19305
19413
|
location: value.isLocationEnabled && value.location ? value.location : void 0,
|
|
19306
19414
|
isGeofencingEnabled: value.isLocationEnabled ? value.isGeofencingEnabled ?? false : void 0,
|
|
@@ -19333,7 +19441,10 @@ function useAttendanceSettingsRepository() {
|
|
|
19333
19441
|
const { delNamespace, setCache, getCache } = useCache30(namespace_collection);
|
|
19334
19442
|
async function createIndex() {
|
|
19335
19443
|
try {
|
|
19336
|
-
await collection.createIndexes([
|
|
19444
|
+
await collection.createIndexes([
|
|
19445
|
+
{ key: { site: 1 } },
|
|
19446
|
+
{ key: { serviceType: 1 } }
|
|
19447
|
+
]);
|
|
19337
19448
|
} catch (error) {
|
|
19338
19449
|
throw new InternalServerError30(
|
|
19339
19450
|
"Failed to create index on attendance settings."
|
|
@@ -19357,15 +19468,16 @@ function useAttendanceSettingsRepository() {
|
|
|
19357
19468
|
throw error;
|
|
19358
19469
|
}
|
|
19359
19470
|
}
|
|
19360
|
-
async function getAttendanceSettingsBySite(site, session) {
|
|
19471
|
+
async function getAttendanceSettingsBySite(site, serviceType, session) {
|
|
19361
19472
|
try {
|
|
19362
19473
|
site = new ObjectId51(site);
|
|
19363
19474
|
} catch (error) {
|
|
19364
19475
|
throw new BadRequestError89("Invalid attendance settings site ID format.");
|
|
19365
19476
|
}
|
|
19366
|
-
const query = { site };
|
|
19477
|
+
const query = { site, serviceType };
|
|
19367
19478
|
const cacheKey = makeCacheKey28(namespace_collection, {
|
|
19368
|
-
site: site.toString()
|
|
19479
|
+
site: site.toString(),
|
|
19480
|
+
serviceType
|
|
19369
19481
|
});
|
|
19370
19482
|
if (!session) {
|
|
19371
19483
|
const cachedData = await getCache(cacheKey);
|
|
@@ -19437,8 +19549,8 @@ function useAttendanceSettingsRepository() {
|
|
|
19437
19549
|
return {
|
|
19438
19550
|
createIndex,
|
|
19439
19551
|
createAttendanceSettings,
|
|
19440
|
-
|
|
19441
|
-
|
|
19552
|
+
getAttendanceSettingsBySite,
|
|
19553
|
+
updateAttendanceSettings
|
|
19442
19554
|
};
|
|
19443
19555
|
}
|
|
19444
19556
|
|
|
@@ -19449,9 +19561,9 @@ function useAttendanceSettingsService() {
|
|
|
19449
19561
|
createAttendanceSettings,
|
|
19450
19562
|
getAttendanceSettingsBySite: _getAttendanceSettingsBySite
|
|
19451
19563
|
} = useAttendanceSettingsRepository();
|
|
19452
|
-
async function getAttendanceSettingsBySite(site) {
|
|
19564
|
+
async function getAttendanceSettingsBySite(site, serviceType) {
|
|
19453
19565
|
try {
|
|
19454
|
-
let settings = await _getAttendanceSettingsBySite(site);
|
|
19566
|
+
let settings = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19455
19567
|
if (!settings) {
|
|
19456
19568
|
logger71.info(
|
|
19457
19569
|
`No attendance settings found for site ${site}, creating default settings`
|
|
@@ -19462,12 +19574,13 @@ function useAttendanceSettingsService() {
|
|
|
19462
19574
|
await createAttendanceSettings(
|
|
19463
19575
|
{
|
|
19464
19576
|
site,
|
|
19577
|
+
serviceType,
|
|
19465
19578
|
isLocationEnabled: false
|
|
19466
19579
|
},
|
|
19467
19580
|
session
|
|
19468
19581
|
);
|
|
19469
19582
|
await session?.commitTransaction();
|
|
19470
|
-
settings = await _getAttendanceSettingsBySite(site);
|
|
19583
|
+
settings = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19471
19584
|
} catch (error) {
|
|
19472
19585
|
await session?.abortTransaction();
|
|
19473
19586
|
throw error;
|
|
@@ -19491,16 +19604,21 @@ function useAttendanceSettingsController() {
|
|
|
19491
19604
|
const { getAttendanceSettingsBySite: _getAttendanceSettingsBySite } = useAttendanceSettingsService();
|
|
19492
19605
|
const { updateAttendanceSettings: _updateAttendanceSettings } = useAttendanceSettingsRepository();
|
|
19493
19606
|
async function getAttendanceSettingsBySite(req, res, next) {
|
|
19494
|
-
const
|
|
19495
|
-
const
|
|
19496
|
-
|
|
19607
|
+
const query = { ...req.query, ...req.params };
|
|
19608
|
+
const validation = Joi52.object({
|
|
19609
|
+
site: Joi52.string().hex().required(),
|
|
19610
|
+
serviceType: Joi52.string().valid(...Object.values(AppServiceType)).required()
|
|
19611
|
+
});
|
|
19612
|
+
const { error } = validation.validate(query);
|
|
19497
19613
|
if (error) {
|
|
19498
19614
|
logger72.log({ level: "error", message: error.message });
|
|
19499
19615
|
next(new BadRequestError90(error.message));
|
|
19500
19616
|
return;
|
|
19501
19617
|
}
|
|
19618
|
+
const site = req.params.site ?? "";
|
|
19619
|
+
const serviceType = req.query.serviceType ?? "";
|
|
19502
19620
|
try {
|
|
19503
|
-
const data = await _getAttendanceSettingsBySite(site);
|
|
19621
|
+
const data = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19504
19622
|
res.json(data);
|
|
19505
19623
|
return;
|
|
19506
19624
|
} catch (error2) {
|
|
@@ -19539,6 +19657,7 @@ import Joi53 from "joi";
|
|
|
19539
19657
|
import { ObjectId as ObjectId52 } from "mongodb";
|
|
19540
19658
|
var attendanceSchema = Joi53.object({
|
|
19541
19659
|
site: Joi53.string().hex().required(),
|
|
19660
|
+
serviceType: Joi53.string().valid(...Object.values(AppServiceType)).required(),
|
|
19542
19661
|
checkIn: Joi53.object({
|
|
19543
19662
|
timestamp: Joi53.date().required(),
|
|
19544
19663
|
location: Joi53.object({
|
|
@@ -19571,6 +19690,7 @@ function MAttendance(value) {
|
|
|
19571
19690
|
}
|
|
19572
19691
|
return {
|
|
19573
19692
|
site: value.site,
|
|
19693
|
+
serviceType: value.serviceType,
|
|
19574
19694
|
checkIn: value.checkIn,
|
|
19575
19695
|
checkOut: null,
|
|
19576
19696
|
user: value.user,
|
|
@@ -19604,6 +19724,7 @@ function useAttendanceRepository() {
|
|
|
19604
19724
|
try {
|
|
19605
19725
|
await collection.createIndexes([
|
|
19606
19726
|
{ key: { site: 1 } },
|
|
19727
|
+
{ key: { serviceType: 1 } },
|
|
19607
19728
|
{ key: { user: 1 } }
|
|
19608
19729
|
]);
|
|
19609
19730
|
} catch (error) {
|
|
@@ -19631,13 +19752,15 @@ function useAttendanceRepository() {
|
|
|
19631
19752
|
page = 1,
|
|
19632
19753
|
limit = 10,
|
|
19633
19754
|
search = "",
|
|
19634
|
-
site
|
|
19755
|
+
site,
|
|
19756
|
+
serviceType
|
|
19635
19757
|
}) {
|
|
19636
19758
|
page = page > 0 ? page - 1 : 0;
|
|
19637
|
-
const query = {};
|
|
19759
|
+
const query = { serviceType };
|
|
19638
19760
|
const cacheOptions = {
|
|
19639
19761
|
page,
|
|
19640
|
-
limit
|
|
19762
|
+
limit,
|
|
19763
|
+
serviceType
|
|
19641
19764
|
};
|
|
19642
19765
|
try {
|
|
19643
19766
|
site = new ObjectId53(site);
|
|
@@ -19726,13 +19849,15 @@ function useAttendanceRepository() {
|
|
|
19726
19849
|
limit = 10,
|
|
19727
19850
|
search = "",
|
|
19728
19851
|
site,
|
|
19852
|
+
serviceType,
|
|
19729
19853
|
user
|
|
19730
19854
|
}) {
|
|
19731
19855
|
page = page > 0 ? page - 1 : 0;
|
|
19732
|
-
const query = {};
|
|
19856
|
+
const query = { serviceType };
|
|
19733
19857
|
const cacheOptions = {
|
|
19734
19858
|
page,
|
|
19735
|
-
limit
|
|
19859
|
+
limit,
|
|
19860
|
+
serviceType
|
|
19736
19861
|
};
|
|
19737
19862
|
try {
|
|
19738
19863
|
site = new ObjectId53(site);
|
|
@@ -20014,7 +20139,11 @@ function useAttendanceService() {
|
|
|
20014
20139
|
const session = useAtlas46.getClient()?.startSession();
|
|
20015
20140
|
try {
|
|
20016
20141
|
session?.startTransaction();
|
|
20017
|
-
const setting = await getAttendanceSettingsBySite(
|
|
20142
|
+
const setting = await getAttendanceSettingsBySite(
|
|
20143
|
+
value.site,
|
|
20144
|
+
value.serviceType,
|
|
20145
|
+
session
|
|
20146
|
+
);
|
|
20018
20147
|
if (setting?.isLocationEnabled && setting?.isGeofencingEnabled) {
|
|
20019
20148
|
if (!setting.location || !value.checkIn.location) {
|
|
20020
20149
|
throw new BadRequestError93("Location data is required for check-in.");
|
|
@@ -20061,6 +20190,7 @@ function useAttendanceService() {
|
|
|
20061
20190
|
const attendance = await getRawAttendanceById(_id, session);
|
|
20062
20191
|
const setting = await getAttendanceSettingsBySite(
|
|
20063
20192
|
attendance.site,
|
|
20193
|
+
attendance.serviceType,
|
|
20064
20194
|
session
|
|
20065
20195
|
);
|
|
20066
20196
|
if (setting?.isLocationEnabled && setting?.isGeofencingEnabled) {
|
|
@@ -20146,7 +20276,8 @@ function useAttendanceController() {
|
|
|
20146
20276
|
page: Joi54.number().min(1).optional().allow("", null),
|
|
20147
20277
|
limit: Joi54.number().min(1).optional().allow("", null),
|
|
20148
20278
|
search: Joi54.string().optional().allow("", null),
|
|
20149
|
-
site: Joi54.string().hex().required()
|
|
20279
|
+
site: Joi54.string().hex().required(),
|
|
20280
|
+
serviceType: Joi54.string().valid(...Object.values(AppServiceType)).required()
|
|
20150
20281
|
});
|
|
20151
20282
|
const { error } = validation.validate(query);
|
|
20152
20283
|
if (error) {
|
|
@@ -20158,12 +20289,14 @@ function useAttendanceController() {
|
|
|
20158
20289
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
20159
20290
|
const search = req.query.search ?? "";
|
|
20160
20291
|
const site = req.params.site ?? "";
|
|
20292
|
+
const serviceType = req.query.serviceType ?? "";
|
|
20161
20293
|
try {
|
|
20162
20294
|
const data = await _getAllAttendances({
|
|
20163
20295
|
page,
|
|
20164
20296
|
limit,
|
|
20165
20297
|
search,
|
|
20166
|
-
site
|
|
20298
|
+
site,
|
|
20299
|
+
serviceType
|
|
20167
20300
|
});
|
|
20168
20301
|
res.json(data);
|
|
20169
20302
|
return;
|
|
@@ -20185,6 +20318,7 @@ function useAttendanceController() {
|
|
|
20185
20318
|
limit: Joi54.number().min(1).optional().allow("", null),
|
|
20186
20319
|
search: Joi54.string().optional().allow("", null),
|
|
20187
20320
|
site: Joi54.string().hex().required(),
|
|
20321
|
+
serviceType: Joi54.string().valid(...Object.values(AppServiceType)).required(),
|
|
20188
20322
|
user: Joi54.string().hex().required()
|
|
20189
20323
|
});
|
|
20190
20324
|
const { error } = validation.validate(query);
|
|
@@ -20197,12 +20331,14 @@ function useAttendanceController() {
|
|
|
20197
20331
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
20198
20332
|
const search = req.query.search ?? "";
|
|
20199
20333
|
const site = req.params.site ?? "";
|
|
20334
|
+
const serviceType = req.query.serviceType ?? "";
|
|
20200
20335
|
try {
|
|
20201
20336
|
const data = await _getAttendanceByUser({
|
|
20202
20337
|
page,
|
|
20203
20338
|
limit,
|
|
20204
20339
|
search,
|
|
20205
20340
|
site,
|
|
20341
|
+
serviceType,
|
|
20206
20342
|
user
|
|
20207
20343
|
});
|
|
20208
20344
|
res.json(data);
|
|
@@ -21601,20 +21737,37 @@ function usePersonController() {
|
|
|
21601
21737
|
}
|
|
21602
21738
|
}
|
|
21603
21739
|
async function getPeopleByUnit(req, res, next) {
|
|
21604
|
-
const
|
|
21605
|
-
|
|
21606
|
-
|
|
21607
|
-
|
|
21608
|
-
|
|
21609
|
-
|
|
21610
|
-
|
|
21611
|
-
|
|
21612
|
-
|
|
21613
|
-
|
|
21614
|
-
|
|
21615
|
-
|
|
21616
|
-
|
|
21617
|
-
|
|
21740
|
+
const PERSON_TYPES3 = Object.values(PersonTypes);
|
|
21741
|
+
console.log(req.query);
|
|
21742
|
+
try {
|
|
21743
|
+
const schema2 = Joi58.object({
|
|
21744
|
+
unit: Joi58.string().required(),
|
|
21745
|
+
type: Joi58.string().optional().allow("", null).custom((value2, helpers) => {
|
|
21746
|
+
if (!value2)
|
|
21747
|
+
return ["resident" /* RESIDENT */];
|
|
21748
|
+
const parsed = value2.split(",").map((v) => v.trim()).filter(Boolean);
|
|
21749
|
+
for (const t of parsed) {
|
|
21750
|
+
if (!PERSON_TYPES3.includes(t)) {
|
|
21751
|
+
return helpers.error("any.only");
|
|
21752
|
+
}
|
|
21753
|
+
}
|
|
21754
|
+
return parsed;
|
|
21755
|
+
}).messages({
|
|
21756
|
+
"any.only": `Type must be one of: ${PERSON_TYPES3.join(", ")}`
|
|
21757
|
+
}),
|
|
21758
|
+
status: Joi58.string().valid(...Object.values(PersonStatus)).optional().default("active" /* ACTIVE */)
|
|
21759
|
+
});
|
|
21760
|
+
const { error, value } = schema2.validate(
|
|
21761
|
+
{ unit: req.params.unit, ...req.query },
|
|
21762
|
+
{ abortEarly: false }
|
|
21763
|
+
);
|
|
21764
|
+
if (error) {
|
|
21765
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
21766
|
+
logger82.log({ level: "error", message: messages });
|
|
21767
|
+
next(new BadRequestError100(messages));
|
|
21768
|
+
return;
|
|
21769
|
+
}
|
|
21770
|
+
const { unit, type, status } = value;
|
|
21618
21771
|
const data = await _getPeopleByUnit({
|
|
21619
21772
|
status,
|
|
21620
21773
|
type,
|
|
@@ -21622,9 +21775,9 @@ function usePersonController() {
|
|
|
21622
21775
|
});
|
|
21623
21776
|
res.json(data);
|
|
21624
21777
|
return;
|
|
21625
|
-
} catch (
|
|
21626
|
-
logger82.log({ level: "error", message:
|
|
21627
|
-
next(
|
|
21778
|
+
} catch (error) {
|
|
21779
|
+
logger82.log({ level: "error", message: error.message });
|
|
21780
|
+
next(error);
|
|
21628
21781
|
return;
|
|
21629
21782
|
}
|
|
21630
21783
|
}
|
|
@@ -25419,7 +25572,7 @@ import {
|
|
|
25419
25572
|
makeCacheKey as makeCacheKey37,
|
|
25420
25573
|
NotFoundError as NotFoundError27,
|
|
25421
25574
|
paginate as paginate31,
|
|
25422
|
-
toObjectId as
|
|
25575
|
+
toObjectId as toObjectId11,
|
|
25423
25576
|
useAtlas as useAtlas60,
|
|
25424
25577
|
useCache as useCache39
|
|
25425
25578
|
} from "@7365admin1/node-server-utils";
|
|
@@ -25475,7 +25628,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
25475
25628
|
page = page > 0 ? page - 1 : 0;
|
|
25476
25629
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
25477
25630
|
const skip = page * limit;
|
|
25478
|
-
const siteId =
|
|
25631
|
+
const siteId = toObjectId11(site);
|
|
25479
25632
|
const query = {
|
|
25480
25633
|
site: siteId,
|
|
25481
25634
|
status,
|
|
@@ -25521,7 +25674,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
25521
25674
|
}
|
|
25522
25675
|
}
|
|
25523
25676
|
async function getSiteFacilityBookingById(id, session) {
|
|
25524
|
-
const _id =
|
|
25677
|
+
const _id = toObjectId11(id);
|
|
25525
25678
|
const cacheKey = makeCacheKey37(facility_bookings_namespace_collection, {
|
|
25526
25679
|
id
|
|
25527
25680
|
});
|
|
@@ -25547,17 +25700,17 @@ function useSiteFacilityBookingRepo() {
|
|
|
25547
25700
|
}
|
|
25548
25701
|
async function updateSiteFacilityBookingById(id, value, session) {
|
|
25549
25702
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
25550
|
-
const _id =
|
|
25703
|
+
const _id = toObjectId11(id);
|
|
25551
25704
|
if (value.site)
|
|
25552
|
-
value.site = typeof value.site === "string" ?
|
|
25705
|
+
value.site = typeof value.site === "string" ? toObjectId11(value.site) : value.site;
|
|
25553
25706
|
if (value.user)
|
|
25554
|
-
value.user = typeof value.user === "string" ?
|
|
25707
|
+
value.user = typeof value.user === "string" ? toObjectId11(value.user) : value.user;
|
|
25555
25708
|
if (value.date)
|
|
25556
25709
|
value.date = value.date ? new Date(value.date).toISOString() : value.date;
|
|
25557
25710
|
if (value.approvedBy)
|
|
25558
|
-
value.approvedBy = typeof value.approvedBy === "string" ?
|
|
25711
|
+
value.approvedBy = typeof value.approvedBy === "string" ? toObjectId11(value.approvedBy) : value.approvedBy;
|
|
25559
25712
|
if (value.createdBy)
|
|
25560
|
-
value.createdBy = typeof value.createdBy === "string" ?
|
|
25713
|
+
value.createdBy = typeof value.createdBy === "string" ? toObjectId11(value.createdBy) : value.createdBy;
|
|
25561
25714
|
try {
|
|
25562
25715
|
const res = await collection.updateOne(
|
|
25563
25716
|
{ _id },
|
|
@@ -28199,7 +28352,7 @@ function useSiteBillingConfigurationController() {
|
|
|
28199
28352
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
28200
28353
|
{}
|
|
28201
28354
|
);
|
|
28202
|
-
req.body.createdBy = cookies?.["user"].toString()
|
|
28355
|
+
req.body.createdBy = cookies?.["user"] ? cookies["user"].toString() : req.body.createdBy;
|
|
28203
28356
|
const data = { ...req.body };
|
|
28204
28357
|
const { error, value } = schemaBillingConfiguration.validate(data);
|
|
28205
28358
|
if (error) {
|
|
@@ -33639,6 +33792,11 @@ function useNfcPatrolTagController() {
|
|
|
33639
33792
|
// src/models/occurrence-book.model.ts
|
|
33640
33793
|
import { ObjectId as ObjectId87 } from "mongodb";
|
|
33641
33794
|
import Joi88 from "joi";
|
|
33795
|
+
var DOBStatus = /* @__PURE__ */ ((DOBStatus3) => {
|
|
33796
|
+
DOBStatus3["OPEN"] = "open";
|
|
33797
|
+
DOBStatus3["CLOSE"] = "close";
|
|
33798
|
+
return DOBStatus3;
|
|
33799
|
+
})(DOBStatus || {});
|
|
33642
33800
|
var schemaOccurrenceBook = Joi88.object({
|
|
33643
33801
|
_id: Joi88.string().optional().allow(null, ""),
|
|
33644
33802
|
site: Joi88.string().hex().required(),
|
|
@@ -33705,7 +33863,12 @@ function useOccurrenceBookRepo() {
|
|
|
33705
33863
|
async function createIndexes() {
|
|
33706
33864
|
try {
|
|
33707
33865
|
await collection.createIndexes([
|
|
33708
|
-
{ key: { site: 1, status: 1, date: 1, closedAt: 1 } }
|
|
33866
|
+
{ key: { site: 1, status: 1, date: 1, closedAt: 1 } },
|
|
33867
|
+
{
|
|
33868
|
+
key: { site: 1, date: 1 },
|
|
33869
|
+
unique: true,
|
|
33870
|
+
name: "unique_site_date"
|
|
33871
|
+
}
|
|
33709
33872
|
]);
|
|
33710
33873
|
} catch (error) {
|
|
33711
33874
|
throw new InternalServerError48(
|
|
@@ -34103,7 +34266,9 @@ function useOccurrenceBookService() {
|
|
|
34103
34266
|
site: site._id,
|
|
34104
34267
|
date: baseDate.toISOString(),
|
|
34105
34268
|
closedAt: closedAt.toISOString(),
|
|
34106
|
-
entryCounter
|
|
34269
|
+
entryCounter,
|
|
34270
|
+
totalInput: 0,
|
|
34271
|
+
status: "open" /* OPEN */
|
|
34107
34272
|
}));
|
|
34108
34273
|
await _bulkCreate(payloads, session);
|
|
34109
34274
|
await session?.commitTransaction();
|
|
@@ -35329,7 +35494,7 @@ function useStatementOfAccountController() {
|
|
|
35329
35494
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
35330
35495
|
{}
|
|
35331
35496
|
);
|
|
35332
|
-
req.body.createdBy = cookies?.["user"].toString()
|
|
35497
|
+
req.body.createdBy = cookies?.["user"] ? cookies["user"].toString() : req.body.createdBy;
|
|
35333
35498
|
const data = { ...req.body };
|
|
35334
35499
|
const validation = Joi93.object({
|
|
35335
35500
|
dateFrom: Joi93.string().required(),
|
|
@@ -40002,7 +40167,7 @@ import {
|
|
|
40002
40167
|
InternalServerError as InternalServerError59,
|
|
40003
40168
|
logger as logger155,
|
|
40004
40169
|
makeCacheKey as makeCacheKey57,
|
|
40005
|
-
toObjectId as
|
|
40170
|
+
toObjectId as toObjectId12,
|
|
40006
40171
|
useAtlas as useAtlas97,
|
|
40007
40172
|
useCache as useCache59
|
|
40008
40173
|
} from "@7365admin1/node-server-utils";
|
|
@@ -40094,7 +40259,7 @@ function useNewDashboardRepo() {
|
|
|
40094
40259
|
securityDashboardCollection
|
|
40095
40260
|
);
|
|
40096
40261
|
async function getMetric(collectionString, siteId, period) {
|
|
40097
|
-
const site =
|
|
40262
|
+
const site = toObjectId12(siteId);
|
|
40098
40263
|
const range = getPeriodRangeWithPrevious(period);
|
|
40099
40264
|
const collection = db.collection(collectionString);
|
|
40100
40265
|
const current = await collection.countDocuments({
|
|
@@ -42072,7 +42237,7 @@ import {
|
|
|
42072
42237
|
InternalServerError as InternalServerError63,
|
|
42073
42238
|
logger as logger163,
|
|
42074
42239
|
makeCacheKey as makeCacheKey61,
|
|
42075
|
-
toObjectId as
|
|
42240
|
+
toObjectId as toObjectId13,
|
|
42076
42241
|
useAtlas as useAtlas102,
|
|
42077
42242
|
useCache as useCache63
|
|
42078
42243
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42151,7 +42316,7 @@ function useOvernightParkingRepo() {
|
|
|
42151
42316
|
}
|
|
42152
42317
|
}
|
|
42153
42318
|
async function getSiteOvernightParking(site) {
|
|
42154
|
-
const siteId =
|
|
42319
|
+
const siteId = toObjectId13(site);
|
|
42155
42320
|
const cacheKey = makeCacheKey61(overnight_parking_namespace_collection, {
|
|
42156
42321
|
site
|
|
42157
42322
|
});
|
|
@@ -42247,7 +42412,7 @@ function useOvernightParkingController() {
|
|
|
42247
42412
|
|
|
42248
42413
|
// src/models/overnight-parking-request.model.ts
|
|
42249
42414
|
import Joi118 from "joi";
|
|
42250
|
-
import { toObjectId as
|
|
42415
|
+
import { toObjectId as toObjectId14 } from "@7365admin1/node-server-utils";
|
|
42251
42416
|
var OvernightParkingRequestStatus = /* @__PURE__ */ ((OvernightParkingRequestStatus2) => {
|
|
42252
42417
|
OvernightParkingRequestStatus2["PENDING"] = "pending";
|
|
42253
42418
|
OvernightParkingRequestStatus2["APPROVED"] = "approved";
|
|
@@ -42284,7 +42449,7 @@ function MOvernightParkingRequest(value) {
|
|
|
42284
42449
|
throw new Error(error.details[0].message);
|
|
42285
42450
|
}
|
|
42286
42451
|
if (value.site && typeof value.site === "string")
|
|
42287
|
-
value.site =
|
|
42452
|
+
value.site = toObjectId14(value.site);
|
|
42288
42453
|
const data = {
|
|
42289
42454
|
...value,
|
|
42290
42455
|
createdAt: value.createdAt ? new Date(value.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -42301,7 +42466,7 @@ import {
|
|
|
42301
42466
|
logger as logger165,
|
|
42302
42467
|
makeCacheKey as makeCacheKey62,
|
|
42303
42468
|
paginate as paginate54,
|
|
42304
|
-
toObjectId as
|
|
42469
|
+
toObjectId as toObjectId15,
|
|
42305
42470
|
useAtlas as useAtlas103,
|
|
42306
42471
|
useCache as useCache64
|
|
42307
42472
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42369,7 +42534,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42369
42534
|
}) {
|
|
42370
42535
|
page = page ? page - 1 : 0;
|
|
42371
42536
|
const skip = page * limit;
|
|
42372
|
-
const siteId =
|
|
42537
|
+
const siteId = toObjectId15(site);
|
|
42373
42538
|
const query = {
|
|
42374
42539
|
site: siteId,
|
|
42375
42540
|
...status && { status }
|
|
@@ -42420,7 +42585,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42420
42585
|
logger165.info(`Cache hit for key: ${cacheKey}`);
|
|
42421
42586
|
return cachedData;
|
|
42422
42587
|
}
|
|
42423
|
-
const _id =
|
|
42588
|
+
const _id = toObjectId15(id);
|
|
42424
42589
|
const data = await collection.findOne({ _id });
|
|
42425
42590
|
if (!data)
|
|
42426
42591
|
throw new BadRequestError187("Overnight parking request not found.");
|
|
@@ -42436,7 +42601,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42436
42601
|
}
|
|
42437
42602
|
async function updateOvernightParkingRequestById(id, value, session) {
|
|
42438
42603
|
try {
|
|
42439
|
-
const _id =
|
|
42604
|
+
const _id = toObjectId15(id);
|
|
42440
42605
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
42441
42606
|
const data = await collection.updateOne(
|
|
42442
42607
|
{ _id },
|
|
@@ -42462,7 +42627,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42462
42627
|
}
|
|
42463
42628
|
async function deleteOvernightParkingRequestById(id, session) {
|
|
42464
42629
|
try {
|
|
42465
|
-
const _id =
|
|
42630
|
+
const _id = toObjectId15(id);
|
|
42466
42631
|
const value = {
|
|
42467
42632
|
deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42468
42633
|
status: "deleted" /* DELETED */
|
|
@@ -42491,7 +42656,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42491
42656
|
}
|
|
42492
42657
|
async function updateExpiredRequests(site, session) {
|
|
42493
42658
|
try {
|
|
42494
|
-
const _site =
|
|
42659
|
+
const _site = toObjectId15(site);
|
|
42495
42660
|
const value = {
|
|
42496
42661
|
status: "expired" /* EXPIRED */
|
|
42497
42662
|
};
|
|
@@ -44258,7 +44423,6 @@ import { useAtlas as useAtlas108 } from "@7365admin1/node-server-utils";
|
|
|
44258
44423
|
import { ObjectId as ObjectId116 } from "mongodb";
|
|
44259
44424
|
import moment5 from "moment-timezone";
|
|
44260
44425
|
async function manpowerEvents(io) {
|
|
44261
|
-
console.log("Manpower events initialized");
|
|
44262
44426
|
let intervalId = null;
|
|
44263
44427
|
let activeConnections = 0;
|
|
44264
44428
|
const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
|
|
@@ -45082,6 +45246,239 @@ function useRedDotPaymentController() {
|
|
|
45082
45246
|
getMerchantDetailsById
|
|
45083
45247
|
};
|
|
45084
45248
|
}
|
|
45249
|
+
|
|
45250
|
+
// src/models/verification-v2.model.ts
|
|
45251
|
+
import { BadRequestError as BadRequestError194 } from "@7365admin1/node-server-utils";
|
|
45252
|
+
import { ObjectId as ObjectId121 } from "mongodb";
|
|
45253
|
+
var VerificationType = /* @__PURE__ */ ((VerificationType2) => {
|
|
45254
|
+
VerificationType2["USER_SIGN_UP"] = "user-sign-up";
|
|
45255
|
+
VerificationType2["FORGET_PASSWORD"] = "forget-password";
|
|
45256
|
+
VerificationType2["USER_INVITE"] = "user-invite";
|
|
45257
|
+
VerificationType2["MEMBER_INVITE"] = "member-invite";
|
|
45258
|
+
return VerificationType2;
|
|
45259
|
+
})(VerificationType || {});
|
|
45260
|
+
var MVerificationV2 = class {
|
|
45261
|
+
constructor(value) {
|
|
45262
|
+
this._id = value._id ?? new ObjectId121();
|
|
45263
|
+
this.type = value.type ?? "";
|
|
45264
|
+
this.email = value.email ?? "";
|
|
45265
|
+
if (value.metadata?.role) {
|
|
45266
|
+
try {
|
|
45267
|
+
value.metadata.role = new ObjectId121(value.metadata.role);
|
|
45268
|
+
} catch (error) {
|
|
45269
|
+
throw new BadRequestError194("Invalid role ID format.");
|
|
45270
|
+
}
|
|
45271
|
+
}
|
|
45272
|
+
if (value.metadata?.org) {
|
|
45273
|
+
try {
|
|
45274
|
+
value.metadata.org = new ObjectId121(value.metadata.org);
|
|
45275
|
+
} catch (error) {
|
|
45276
|
+
throw new BadRequestError194("Invalid org ID format.");
|
|
45277
|
+
}
|
|
45278
|
+
}
|
|
45279
|
+
if (value.metadata?.siteId) {
|
|
45280
|
+
try {
|
|
45281
|
+
value.metadata.siteId = new ObjectId121(value.metadata.siteId);
|
|
45282
|
+
} catch (error) {
|
|
45283
|
+
throw new BadRequestError194("Invalid site ID format.");
|
|
45284
|
+
}
|
|
45285
|
+
}
|
|
45286
|
+
if (value.metadata?.serviceProviderOrgId) {
|
|
45287
|
+
try {
|
|
45288
|
+
value.metadata.serviceProviderOrgId = new ObjectId121(
|
|
45289
|
+
value.metadata.serviceProviderOrgId
|
|
45290
|
+
);
|
|
45291
|
+
} catch (error) {
|
|
45292
|
+
throw new BadRequestError194("Invalid service provider ID format.");
|
|
45293
|
+
}
|
|
45294
|
+
}
|
|
45295
|
+
this.metadata = { ...value.metadata };
|
|
45296
|
+
this.status = value.status ?? "pending";
|
|
45297
|
+
this.createdAt = value.createdAt ?? /* @__PURE__ */ new Date();
|
|
45298
|
+
this.updatedAt = value.updatedAt ?? null;
|
|
45299
|
+
this.expireAt = value.expireAt ?? new Date(Date.now() + 3600 * 1e3);
|
|
45300
|
+
}
|
|
45301
|
+
};
|
|
45302
|
+
|
|
45303
|
+
// src/repositories/verification-v2.repo.ts
|
|
45304
|
+
import {
|
|
45305
|
+
InternalServerError as InternalServerError68,
|
|
45306
|
+
logger as logger175,
|
|
45307
|
+
useAtlas as useAtlas111,
|
|
45308
|
+
useCache as useCache66
|
|
45309
|
+
} from "@7365admin1/node-server-utils";
|
|
45310
|
+
function useVerificationRepoV2() {
|
|
45311
|
+
const db = useAtlas111.getDb();
|
|
45312
|
+
if (!db) {
|
|
45313
|
+
throw new InternalServerError68("Unable to connect to server.");
|
|
45314
|
+
}
|
|
45315
|
+
const namespace_collection = "verifications";
|
|
45316
|
+
const collection = db.collection(namespace_collection);
|
|
45317
|
+
async function createIndex() {
|
|
45318
|
+
try {
|
|
45319
|
+
await collection.createIndex([
|
|
45320
|
+
{ email: 1 },
|
|
45321
|
+
{ type: 1 },
|
|
45322
|
+
{ status: 1 },
|
|
45323
|
+
{ "metadata.org": 1 }
|
|
45324
|
+
]);
|
|
45325
|
+
} catch (error) {
|
|
45326
|
+
throw new InternalServerError68("Failed to create index.");
|
|
45327
|
+
}
|
|
45328
|
+
}
|
|
45329
|
+
async function createTextIndex() {
|
|
45330
|
+
try {
|
|
45331
|
+
await collection.createIndex({
|
|
45332
|
+
email: "text"
|
|
45333
|
+
});
|
|
45334
|
+
} catch (error) {
|
|
45335
|
+
throw new InternalServerError68("Failed to create text index on email.");
|
|
45336
|
+
}
|
|
45337
|
+
}
|
|
45338
|
+
const { delNamespace, setCache, getCache, delCache } = useCache66(namespace_collection);
|
|
45339
|
+
async function add(value, session) {
|
|
45340
|
+
value = new MVerificationV2(value);
|
|
45341
|
+
try {
|
|
45342
|
+
const res = await collection.insertOne(value, { session });
|
|
45343
|
+
delNamespace().then(() => {
|
|
45344
|
+
logger175.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
45345
|
+
}).catch((err) => {
|
|
45346
|
+
logger175.error(
|
|
45347
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
45348
|
+
err
|
|
45349
|
+
);
|
|
45350
|
+
});
|
|
45351
|
+
return res.insertedId;
|
|
45352
|
+
} catch (error) {
|
|
45353
|
+
logger175.log({
|
|
45354
|
+
level: "info",
|
|
45355
|
+
message: String(error)
|
|
45356
|
+
});
|
|
45357
|
+
throw new InternalServerError68("Server internal error.");
|
|
45358
|
+
}
|
|
45359
|
+
}
|
|
45360
|
+
return {
|
|
45361
|
+
createIndex,
|
|
45362
|
+
createTextIndex,
|
|
45363
|
+
add
|
|
45364
|
+
};
|
|
45365
|
+
}
|
|
45366
|
+
|
|
45367
|
+
// src/services/verification-v2.service.ts
|
|
45368
|
+
import {
|
|
45369
|
+
useMailer as useMailer4,
|
|
45370
|
+
compileHandlebar as compileHandlebar4,
|
|
45371
|
+
logger as logger176,
|
|
45372
|
+
getDirectory as getDirectory4,
|
|
45373
|
+
BadRequestError as BadRequestError196,
|
|
45374
|
+
hashPassword as hashPassword4
|
|
45375
|
+
} from "@7365admin1/node-server-utils";
|
|
45376
|
+
function useVerificationServiceV2() {
|
|
45377
|
+
const MailerConfig = {
|
|
45378
|
+
host: MAILER_TRANSPORT_HOST,
|
|
45379
|
+
port: MAILER_TRANSPORT_PORT,
|
|
45380
|
+
secure: MAILER_TRANSPORT_SECURE,
|
|
45381
|
+
email: MAILER_EMAIL,
|
|
45382
|
+
password: MAILER_PASSWORD
|
|
45383
|
+
};
|
|
45384
|
+
const mailer = new useMailer4(MailerConfig);
|
|
45385
|
+
const { add } = useVerificationRepoV2();
|
|
45386
|
+
const { getUserByEmail } = useUserRepo();
|
|
45387
|
+
async function signUp({
|
|
45388
|
+
email,
|
|
45389
|
+
metadata
|
|
45390
|
+
}) {
|
|
45391
|
+
try {
|
|
45392
|
+
const user = await getUserByEmail(email);
|
|
45393
|
+
if (user) {
|
|
45394
|
+
throw new BadRequestError196(
|
|
45395
|
+
`Email ${email} is already registered, please login to continue.`
|
|
45396
|
+
);
|
|
45397
|
+
}
|
|
45398
|
+
metadata.password = await hashPassword4(metadata.password);
|
|
45399
|
+
const value = {
|
|
45400
|
+
type: "user-sign-up" /* USER_SIGN_UP */,
|
|
45401
|
+
email,
|
|
45402
|
+
metadata,
|
|
45403
|
+
expireAt: new Date((/* @__PURE__ */ new Date()).getTime() + 5 * 60 * 1e3).toISOString(),
|
|
45404
|
+
// 5mins from now
|
|
45405
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
45406
|
+
};
|
|
45407
|
+
const res = await add(value);
|
|
45408
|
+
const dir = __dirname;
|
|
45409
|
+
const filePath = getDirectory4(dir, "./public/handlebars/sign-up");
|
|
45410
|
+
const emailContent = compileHandlebar4({
|
|
45411
|
+
context: {
|
|
45412
|
+
email,
|
|
45413
|
+
validity: "5 minutes",
|
|
45414
|
+
link: `${APP_MAIN}/sign-up/${res}`
|
|
45415
|
+
},
|
|
45416
|
+
filePath
|
|
45417
|
+
});
|
|
45418
|
+
mailer.sendMail({
|
|
45419
|
+
to: email,
|
|
45420
|
+
subject: "Sign Up Verification",
|
|
45421
|
+
html: emailContent,
|
|
45422
|
+
sender: "iService365"
|
|
45423
|
+
}).catch((error) => {
|
|
45424
|
+
logger176.log({
|
|
45425
|
+
level: "error",
|
|
45426
|
+
message: `Error sending user invite email: ${error}`
|
|
45427
|
+
});
|
|
45428
|
+
});
|
|
45429
|
+
return res;
|
|
45430
|
+
} catch (error) {
|
|
45431
|
+
throw error;
|
|
45432
|
+
}
|
|
45433
|
+
}
|
|
45434
|
+
return {
|
|
45435
|
+
signUp
|
|
45436
|
+
};
|
|
45437
|
+
}
|
|
45438
|
+
|
|
45439
|
+
// src/controllers/auth-v2.controller.ts
|
|
45440
|
+
import Joi125 from "joi";
|
|
45441
|
+
import { BadRequestError as BadRequestError197, logger as logger177 } from "@7365admin1/node-server-utils";
|
|
45442
|
+
function useAuthControllerV2() {
|
|
45443
|
+
const { signUp: _signUp } = useVerificationServiceV2();
|
|
45444
|
+
async function signUp(req, res, next) {
|
|
45445
|
+
const validation = Joi125.object({
|
|
45446
|
+
email: Joi125.string().email().lowercase().trim().required(),
|
|
45447
|
+
password: Joi125.string().trim().required(),
|
|
45448
|
+
country: Joi125.string().min(3).required(),
|
|
45449
|
+
orgName: Joi125.string().min(1).required()
|
|
45450
|
+
});
|
|
45451
|
+
const { error, value } = validation.validate(req.body, {
|
|
45452
|
+
abortEarly: false
|
|
45453
|
+
});
|
|
45454
|
+
if (error) {
|
|
45455
|
+
const messages = error.details.map((d) => d.message);
|
|
45456
|
+
logger177.log({ level: "error", message: messages.join(", ") });
|
|
45457
|
+
next(new BadRequestError197(messages.join(", ")));
|
|
45458
|
+
return;
|
|
45459
|
+
}
|
|
45460
|
+
const { email, password, country, orgName } = value;
|
|
45461
|
+
try {
|
|
45462
|
+
const message = await _signUp({
|
|
45463
|
+
email,
|
|
45464
|
+
metadata: {
|
|
45465
|
+
password,
|
|
45466
|
+
country,
|
|
45467
|
+
orgName
|
|
45468
|
+
}
|
|
45469
|
+
});
|
|
45470
|
+
res.json({ message });
|
|
45471
|
+
return;
|
|
45472
|
+
} catch (error2) {
|
|
45473
|
+
logger177.log({ level: "error", message: error2.message });
|
|
45474
|
+
next(error2);
|
|
45475
|
+
return;
|
|
45476
|
+
}
|
|
45477
|
+
}
|
|
45478
|
+
return {
|
|
45479
|
+
signUp
|
|
45480
|
+
};
|
|
45481
|
+
}
|
|
45085
45482
|
export {
|
|
45086
45483
|
ANPRMode,
|
|
45087
45484
|
AccessTypeProps,
|
|
@@ -45091,6 +45488,7 @@ export {
|
|
|
45091
45488
|
BulletinStatus,
|
|
45092
45489
|
CameraType,
|
|
45093
45490
|
DEVICE_STATUS,
|
|
45491
|
+
DOBStatus,
|
|
45094
45492
|
DayOfWeek,
|
|
45095
45493
|
EAccessCardTypes,
|
|
45096
45494
|
EAccessCardUserTypes,
|
|
@@ -45157,6 +45555,7 @@ export {
|
|
|
45157
45555
|
MVehicle,
|
|
45158
45556
|
MVehicleTransaction,
|
|
45159
45557
|
MVerification,
|
|
45558
|
+
MVerificationV2,
|
|
45160
45559
|
MVisitorTransaction,
|
|
45161
45560
|
MWorkOrder,
|
|
45162
45561
|
OrgNature,
|
|
@@ -45165,6 +45564,7 @@ export {
|
|
|
45165
45564
|
PERSON_TYPES,
|
|
45166
45565
|
PMDashboardCollection,
|
|
45167
45566
|
Period,
|
|
45567
|
+
PersonStatus,
|
|
45168
45568
|
PersonTypes,
|
|
45169
45569
|
SiteCategories,
|
|
45170
45570
|
SiteStatus,
|
|
@@ -45177,6 +45577,7 @@ export {
|
|
|
45177
45577
|
VehicleSort,
|
|
45178
45578
|
VehicleStatus,
|
|
45179
45579
|
VehicleType,
|
|
45580
|
+
VerificationType,
|
|
45180
45581
|
VisitorSort,
|
|
45181
45582
|
VisitorStatus,
|
|
45182
45583
|
addressSchema,
|
|
@@ -45301,6 +45702,7 @@ export {
|
|
|
45301
45702
|
useAttendanceSettingsRepository,
|
|
45302
45703
|
useAttendanceSettingsService,
|
|
45303
45704
|
useAuthController,
|
|
45705
|
+
useAuthControllerV2,
|
|
45304
45706
|
useAuthService,
|
|
45305
45707
|
useBuildingController,
|
|
45306
45708
|
useBuildingRepo,
|
|
@@ -45454,7 +45856,9 @@ export {
|
|
|
45454
45856
|
useVehicleService,
|
|
45455
45857
|
useVerificationController,
|
|
45456
45858
|
useVerificationRepo,
|
|
45859
|
+
useVerificationRepoV2,
|
|
45457
45860
|
useVerificationService,
|
|
45861
|
+
useVerificationServiceV2,
|
|
45458
45862
|
useVisitorTransactionController,
|
|
45459
45863
|
useVisitorTransactionRepo,
|
|
45460
45864
|
useVisitorTransactionService,
|