@7365admin1/core 2.60.0 → 2.62.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 +33 -1
- package/dist/index.js +847 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +880 -70
- package/dist/index.mjs.map +1 -1
- package/dist/public/handlebars/user-invite.hbs +157 -67
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3460,6 +3460,39 @@ function useMemberRepo() {
|
|
|
3460
3460
|
}
|
|
3461
3461
|
}
|
|
3462
3462
|
}
|
|
3463
|
+
async function getAllByUserId(user) {
|
|
3464
|
+
try {
|
|
3465
|
+
user = new import_mongodb11.ObjectId(user);
|
|
3466
|
+
} catch (error) {
|
|
3467
|
+
throw new import_node_server_utils12.BadRequestError("Invalid user ID format.");
|
|
3468
|
+
}
|
|
3469
|
+
const cacheKey = (0, import_node_server_utils12.makeCacheKey)(namespace_collection, {
|
|
3470
|
+
user: user.toString(),
|
|
3471
|
+
type: "all"
|
|
3472
|
+
});
|
|
3473
|
+
const cachedData = await getCache(cacheKey);
|
|
3474
|
+
if (cachedData) {
|
|
3475
|
+
import_node_server_utils12.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
3476
|
+
return cachedData;
|
|
3477
|
+
}
|
|
3478
|
+
try {
|
|
3479
|
+
const data = await collection.find({ user }).toArray();
|
|
3480
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3481
|
+
import_node_server_utils12.logger.info(`Cache set for key: ${cacheKey}`);
|
|
3482
|
+
}).catch((err) => {
|
|
3483
|
+
import_node_server_utils12.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3484
|
+
});
|
|
3485
|
+
return data;
|
|
3486
|
+
} catch (error) {
|
|
3487
|
+
if (error instanceof import_node_server_utils12.AppError) {
|
|
3488
|
+
throw error;
|
|
3489
|
+
} else {
|
|
3490
|
+
throw new import_node_server_utils12.InternalServerError(
|
|
3491
|
+
"Internal server error, failed to retrieve members."
|
|
3492
|
+
);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3463
3496
|
async function getByRoleId(role) {
|
|
3464
3497
|
try {
|
|
3465
3498
|
role = new import_mongodb11.ObjectId(role);
|
|
@@ -3935,6 +3968,58 @@ function useMemberRepo() {
|
|
|
3935
3968
|
throw new import_node_server_utils12.InternalServerError("Failed to count user memberships.");
|
|
3936
3969
|
}
|
|
3937
3970
|
}
|
|
3971
|
+
async function updateSiteById(_id, siteId, siteName) {
|
|
3972
|
+
try {
|
|
3973
|
+
_id = new import_mongodb11.ObjectId(_id);
|
|
3974
|
+
} catch (error) {
|
|
3975
|
+
throw new import_node_server_utils12.BadRequestError("Invalid member ID format.");
|
|
3976
|
+
}
|
|
3977
|
+
try {
|
|
3978
|
+
siteId = new import_mongodb11.ObjectId(siteId);
|
|
3979
|
+
} catch (error) {
|
|
3980
|
+
throw new import_node_server_utils12.BadRequestError("Invalid site ID format.");
|
|
3981
|
+
}
|
|
3982
|
+
try {
|
|
3983
|
+
const updateValue = {
|
|
3984
|
+
siteId,
|
|
3985
|
+
siteName,
|
|
3986
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
3987
|
+
};
|
|
3988
|
+
const res = await collection.updateOne(
|
|
3989
|
+
{ _id },
|
|
3990
|
+
{ $set: updateValue }
|
|
3991
|
+
);
|
|
3992
|
+
if (res.modifiedCount === 0) {
|
|
3993
|
+
throw new import_node_server_utils12.InternalServerError(
|
|
3994
|
+
"Unable to update member site."
|
|
3995
|
+
);
|
|
3996
|
+
}
|
|
3997
|
+
const cacheKey = (0, import_node_server_utils12.makeCacheKey)(namespace_collection, {
|
|
3998
|
+
_id: _id.toString()
|
|
3999
|
+
});
|
|
4000
|
+
delCache(cacheKey).then(() => {
|
|
4001
|
+
import_node_server_utils12.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
4002
|
+
}).catch((err) => {
|
|
4003
|
+
import_node_server_utils12.logger.error(
|
|
4004
|
+
`Failed to delete cache for key: ${cacheKey}`,
|
|
4005
|
+
err
|
|
4006
|
+
);
|
|
4007
|
+
});
|
|
4008
|
+
delNamespace().then(() => {
|
|
4009
|
+
import_node_server_utils12.logger.info(
|
|
4010
|
+
`Cache cleared for namespace: ${namespace_collection}`
|
|
4011
|
+
);
|
|
4012
|
+
}).catch((err) => {
|
|
4013
|
+
import_node_server_utils12.logger.error(
|
|
4014
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4015
|
+
err
|
|
4016
|
+
);
|
|
4017
|
+
});
|
|
4018
|
+
return res.modifiedCount;
|
|
4019
|
+
} catch (error) {
|
|
4020
|
+
throw error;
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
3938
4023
|
return {
|
|
3939
4024
|
createIndex,
|
|
3940
4025
|
createUniqueIndex,
|
|
@@ -3942,6 +4027,7 @@ function useMemberRepo() {
|
|
|
3942
4027
|
add,
|
|
3943
4028
|
getById,
|
|
3944
4029
|
getByUserId,
|
|
4030
|
+
getAllByUserId,
|
|
3945
4031
|
getByUserIdType,
|
|
3946
4032
|
getByRoleId,
|
|
3947
4033
|
getAll,
|
|
@@ -3953,7 +4039,8 @@ function useMemberRepo() {
|
|
|
3953
4039
|
countByOrg,
|
|
3954
4040
|
countUserMembershipById,
|
|
3955
4041
|
updateRoleById,
|
|
3956
|
-
getByRoles
|
|
4042
|
+
getByRoles,
|
|
4043
|
+
updateSiteById
|
|
3957
4044
|
};
|
|
3958
4045
|
}
|
|
3959
4046
|
|
|
@@ -4479,6 +4566,25 @@ function useOrgRepo() {
|
|
|
4479
4566
|
}
|
|
4480
4567
|
}
|
|
4481
4568
|
}
|
|
4569
|
+
async function update(id, value, session) {
|
|
4570
|
+
try {
|
|
4571
|
+
await collection.updateOne(
|
|
4572
|
+
{ _id: new import_mongodb15.ObjectId(id) },
|
|
4573
|
+
{
|
|
4574
|
+
$set: {
|
|
4575
|
+
...value,
|
|
4576
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
4577
|
+
}
|
|
4578
|
+
},
|
|
4579
|
+
{ session }
|
|
4580
|
+
);
|
|
4581
|
+
await delNamespace();
|
|
4582
|
+
return id;
|
|
4583
|
+
} catch (error) {
|
|
4584
|
+
import_node_server_utils17.logger.log({ level: "error", message: error.message });
|
|
4585
|
+
throw new import_node_server_utils17.InternalServerError("Failed to update organization.");
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4482
4588
|
async function getAll({
|
|
4483
4589
|
search = "",
|
|
4484
4590
|
page = 1,
|
|
@@ -4714,6 +4820,7 @@ function useOrgRepo() {
|
|
|
4714
4820
|
createTextIndex,
|
|
4715
4821
|
createUniqueIndex,
|
|
4716
4822
|
add,
|
|
4823
|
+
update,
|
|
4717
4824
|
getAll,
|
|
4718
4825
|
getById,
|
|
4719
4826
|
getByName,
|
|
@@ -5651,6 +5758,7 @@ function useVerificationService() {
|
|
|
5651
5758
|
const { getUserByEmail } = useUserRepo();
|
|
5652
5759
|
const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
|
|
5653
5760
|
const { getSiteById } = useSiteRepo();
|
|
5761
|
+
const { getByUserIdType } = useMemberRepo();
|
|
5654
5762
|
async function createUserInvite({
|
|
5655
5763
|
email,
|
|
5656
5764
|
metadata
|
|
@@ -5706,8 +5814,77 @@ function useVerificationService() {
|
|
|
5706
5814
|
throw error;
|
|
5707
5815
|
}
|
|
5708
5816
|
}
|
|
5709
|
-
async function createSimpleUserInvite({
|
|
5817
|
+
async function createSimpleUserInvite({
|
|
5818
|
+
email,
|
|
5819
|
+
metadata
|
|
5820
|
+
}) {
|
|
5710
5821
|
const type = "user-invite";
|
|
5822
|
+
const apps = Array.isArray(metadata.app) ? metadata.app : [metadata.app];
|
|
5823
|
+
if (metadata?.org) {
|
|
5824
|
+
await getOrgById(metadata.org);
|
|
5825
|
+
}
|
|
5826
|
+
if (metadata?.siteId) {
|
|
5827
|
+
await getSiteById(metadata.siteId);
|
|
5828
|
+
}
|
|
5829
|
+
const verificationIds = [];
|
|
5830
|
+
const invitedApps = [];
|
|
5831
|
+
for (const app of apps) {
|
|
5832
|
+
await useVerificationRepo().findOne({
|
|
5833
|
+
type,
|
|
5834
|
+
email,
|
|
5835
|
+
"metadata.app": app,
|
|
5836
|
+
"metadata.org": metadata.org,
|
|
5837
|
+
"metadata.siteId": metadata.siteId
|
|
5838
|
+
});
|
|
5839
|
+
const value = {
|
|
5840
|
+
type,
|
|
5841
|
+
email,
|
|
5842
|
+
metadata: {
|
|
5843
|
+
...metadata,
|
|
5844
|
+
app
|
|
5845
|
+
},
|
|
5846
|
+
expireAt: new Date(
|
|
5847
|
+
Date.now() + 72 * 60 * 60 * 1e3
|
|
5848
|
+
).toISOString(),
|
|
5849
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5850
|
+
};
|
|
5851
|
+
const createdId = await add(value);
|
|
5852
|
+
verificationIds.push(createdId.toString());
|
|
5853
|
+
invitedApps.push(app);
|
|
5854
|
+
}
|
|
5855
|
+
const link = `${APP_MAIN}/verify/invitation/${verificationIds[0]}`;
|
|
5856
|
+
const appsSet = new Set(invitedApps);
|
|
5857
|
+
const emailContent = (0, import_node_server_utils21.compileHandlebar)({
|
|
5858
|
+
context: {
|
|
5859
|
+
email,
|
|
5860
|
+
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5861
|
+
link,
|
|
5862
|
+
hasPropertyManagement: appsSet.has("property_management_agency"),
|
|
5863
|
+
hasSecurity: appsSet.has("security_agency"),
|
|
5864
|
+
hasCleaning: appsSet.has("cleaning_services"),
|
|
5865
|
+
hasMechanical: appsSet.has("mechanical_electrical_services"),
|
|
5866
|
+
hasLandscape: appsSet.has("landscaping_services"),
|
|
5867
|
+
hasPestControl: appsSet.has("pest_control_services"),
|
|
5868
|
+
hasPoolMaintenance: appsSet.has("pool_maintenance_services")
|
|
5869
|
+
},
|
|
5870
|
+
filePath: (0, import_node_server_utils21.getDirectory)(
|
|
5871
|
+
__dirname,
|
|
5872
|
+
"./public/handlebars/user-invite"
|
|
5873
|
+
)
|
|
5874
|
+
});
|
|
5875
|
+
await mailer.sendMail({
|
|
5876
|
+
to: email,
|
|
5877
|
+
subject: "User Invite",
|
|
5878
|
+
html: emailContent,
|
|
5879
|
+
sender: "iService365"
|
|
5880
|
+
});
|
|
5881
|
+
return verificationIds;
|
|
5882
|
+
}
|
|
5883
|
+
async function createSimpleMemberInvite({
|
|
5884
|
+
email,
|
|
5885
|
+
metadata
|
|
5886
|
+
}) {
|
|
5887
|
+
const type = "member-invite";
|
|
5711
5888
|
if (metadata?.org)
|
|
5712
5889
|
await getOrgById(metadata.org);
|
|
5713
5890
|
if (metadata?.siteId)
|
|
@@ -5715,12 +5892,14 @@ function useVerificationService() {
|
|
|
5715
5892
|
const existing = await useVerificationRepo().findOne({
|
|
5716
5893
|
type,
|
|
5717
5894
|
email,
|
|
5718
|
-
"metadata.app": metadata.app
|
|
5895
|
+
"metadata.app": metadata.app,
|
|
5896
|
+
"metadata.org": metadata.org,
|
|
5897
|
+
"metadata.siteId": metadata.siteId
|
|
5719
5898
|
});
|
|
5720
5899
|
if (existing) {
|
|
5721
5900
|
if (existing.status === "complete") {
|
|
5722
5901
|
throw new import_node_server_utils21.BadRequestError(
|
|
5723
|
-
`User already completed invite for app: ${metadata.app}`
|
|
5902
|
+
`User already completed member invite for app: ${metadata.app}`
|
|
5724
5903
|
);
|
|
5725
5904
|
}
|
|
5726
5905
|
return existing._id;
|
|
@@ -5733,18 +5912,18 @@ function useVerificationService() {
|
|
|
5733
5912
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5734
5913
|
};
|
|
5735
5914
|
const res = await add(value);
|
|
5736
|
-
const link = `${APP_MAIN}/verify/
|
|
5915
|
+
const link = `${APP_MAIN}/verify/membership/${res}`;
|
|
5737
5916
|
const emailContent = (0, import_node_server_utils21.compileHandlebar)({
|
|
5738
5917
|
context: {
|
|
5739
5918
|
email,
|
|
5740
5919
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5741
5920
|
link
|
|
5742
5921
|
},
|
|
5743
|
-
filePath: (0, import_node_server_utils21.getDirectory)(__dirname, "./public/handlebars/
|
|
5922
|
+
filePath: (0, import_node_server_utils21.getDirectory)(__dirname, "./public/handlebars/member-invite")
|
|
5744
5923
|
});
|
|
5745
5924
|
await mailer.sendMail({
|
|
5746
5925
|
to: email,
|
|
5747
|
-
subject: "
|
|
5926
|
+
subject: "Member Invite",
|
|
5748
5927
|
html: emailContent,
|
|
5749
5928
|
sender: "iService365"
|
|
5750
5929
|
});
|
|
@@ -5833,6 +6012,72 @@ function useVerificationService() {
|
|
|
5833
6012
|
throw error2;
|
|
5834
6013
|
}
|
|
5835
6014
|
}
|
|
6015
|
+
async function createSimpleServiceProviderInvite({ email, app, name, role, orgId, siteId, siteName }) {
|
|
6016
|
+
const schema2 = import_joi11.default.object({
|
|
6017
|
+
email: import_joi11.default.string().email().lowercase().required(),
|
|
6018
|
+
app: import_joi11.default.string().allow("", null),
|
|
6019
|
+
name: import_joi11.default.string().allow("", null),
|
|
6020
|
+
role: import_joi11.default.string().hex().allow("", null),
|
|
6021
|
+
orgId: import_joi11.default.string().hex().length(24).required(),
|
|
6022
|
+
siteId: import_joi11.default.string().hex().length(24).required(),
|
|
6023
|
+
siteName: import_joi11.default.string().required()
|
|
6024
|
+
});
|
|
6025
|
+
const { error } = schema2.validate({
|
|
6026
|
+
email,
|
|
6027
|
+
app,
|
|
6028
|
+
name,
|
|
6029
|
+
role,
|
|
6030
|
+
orgId,
|
|
6031
|
+
siteId,
|
|
6032
|
+
siteName
|
|
6033
|
+
});
|
|
6034
|
+
if (error) {
|
|
6035
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
6036
|
+
import_node_server_utils21.logger.log({ level: "error", message: messages });
|
|
6037
|
+
throw new import_node_server_utils21.BadRequestError(`Invalid input: ${error.message}`);
|
|
6038
|
+
}
|
|
6039
|
+
const subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
6040
|
+
const type = "service-provider-invite" /* SERVICE_PROVIDER_INVITE */;
|
|
6041
|
+
const value = {
|
|
6042
|
+
type,
|
|
6043
|
+
email,
|
|
6044
|
+
metadata: {
|
|
6045
|
+
app,
|
|
6046
|
+
name,
|
|
6047
|
+
role,
|
|
6048
|
+
org: orgId,
|
|
6049
|
+
siteId,
|
|
6050
|
+
siteName
|
|
6051
|
+
},
|
|
6052
|
+
expireAt: new Date(Date.now() + 72 * 60 * 60 * 1e3).toISOString(),
|
|
6053
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6054
|
+
};
|
|
6055
|
+
try {
|
|
6056
|
+
const id = await _add(value);
|
|
6057
|
+
const filePath = (0, import_node_server_utils21.getDirectory)(__dirname, `./public/handlebars/${value.type}`);
|
|
6058
|
+
const link = `${APP_MAIN}/verify/${value.type}/${id}`;
|
|
6059
|
+
const emailContent = (0, import_node_server_utils21.compileHandlebar)({
|
|
6060
|
+
context: {
|
|
6061
|
+
email,
|
|
6062
|
+
app,
|
|
6063
|
+
name,
|
|
6064
|
+
role,
|
|
6065
|
+
siteName,
|
|
6066
|
+
link
|
|
6067
|
+
},
|
|
6068
|
+
filePath
|
|
6069
|
+
});
|
|
6070
|
+
await mailer.sendMail({
|
|
6071
|
+
to: email,
|
|
6072
|
+
subject,
|
|
6073
|
+
html: emailContent,
|
|
6074
|
+
sender: "iService365" /* ISERVICE365 */
|
|
6075
|
+
});
|
|
6076
|
+
return id;
|
|
6077
|
+
} catch (error2) {
|
|
6078
|
+
throw error2;
|
|
6079
|
+
}
|
|
6080
|
+
}
|
|
5836
6081
|
async function createForgetPassword(email) {
|
|
5837
6082
|
const value = {
|
|
5838
6083
|
type: "forget-password",
|
|
@@ -6044,7 +6289,9 @@ function useVerificationService() {
|
|
|
6044
6289
|
updateStatusById,
|
|
6045
6290
|
signUp,
|
|
6046
6291
|
checkExpiredInvitation,
|
|
6047
|
-
createSimpleUserInvite
|
|
6292
|
+
createSimpleUserInvite,
|
|
6293
|
+
createSimpleMemberInvite,
|
|
6294
|
+
createSimpleServiceProviderInvite
|
|
6048
6295
|
};
|
|
6049
6296
|
}
|
|
6050
6297
|
|
|
@@ -7566,7 +7813,9 @@ function useMemberService() {
|
|
|
7566
7813
|
const {
|
|
7567
7814
|
add: addMember,
|
|
7568
7815
|
updateRoleById: _updateRoleById,
|
|
7569
|
-
getByRoles
|
|
7816
|
+
getByRoles,
|
|
7817
|
+
updateSiteById: _updateSiteById,
|
|
7818
|
+
getAllByUserId: _getAllByUserId
|
|
7570
7819
|
} = useMemberRepo();
|
|
7571
7820
|
const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
|
|
7572
7821
|
const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
|
|
@@ -7702,10 +7951,37 @@ function useMemberService() {
|
|
|
7702
7951
|
throw error;
|
|
7703
7952
|
}
|
|
7704
7953
|
}
|
|
7954
|
+
async function updateSiteById(id, siteId, siteName) {
|
|
7955
|
+
try {
|
|
7956
|
+
await _updateSiteById(
|
|
7957
|
+
id,
|
|
7958
|
+
siteId,
|
|
7959
|
+
siteName
|
|
7960
|
+
);
|
|
7961
|
+
return {
|
|
7962
|
+
message: "Member site updated successfully."
|
|
7963
|
+
};
|
|
7964
|
+
} catch (error) {
|
|
7965
|
+
throw error;
|
|
7966
|
+
}
|
|
7967
|
+
}
|
|
7968
|
+
async function getAllByUser(user) {
|
|
7969
|
+
try {
|
|
7970
|
+
const members = await _getAllByUserId(user);
|
|
7971
|
+
return {
|
|
7972
|
+
items: members,
|
|
7973
|
+
total: members.length
|
|
7974
|
+
};
|
|
7975
|
+
} catch (error) {
|
|
7976
|
+
throw error;
|
|
7977
|
+
}
|
|
7978
|
+
}
|
|
7705
7979
|
return {
|
|
7706
7980
|
createMember,
|
|
7707
7981
|
createMemberDirect,
|
|
7708
|
-
updateRoleById
|
|
7982
|
+
updateRoleById,
|
|
7983
|
+
updateSiteById,
|
|
7984
|
+
getAllByUser
|
|
7709
7985
|
};
|
|
7710
7986
|
}
|
|
7711
7987
|
|
|
@@ -7717,9 +7993,10 @@ function useMemberController() {
|
|
|
7717
7993
|
getOrgsByMembership: _getOrgsByMembership,
|
|
7718
7994
|
getByUserIdType: _getByUserIdType,
|
|
7719
7995
|
updateMemberStatus: _updateMemberStatus,
|
|
7720
|
-
updateStatusByUserId: _updateStatusByUserId
|
|
7996
|
+
updateStatusByUserId: _updateStatusByUserId,
|
|
7997
|
+
updateSiteById: _updateSiteById
|
|
7721
7998
|
} = useMemberRepo();
|
|
7722
|
-
const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById } = useMemberService();
|
|
7999
|
+
const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById, getAllByUser: _getAllByUser } = useMemberService();
|
|
7723
8000
|
async function createMember(req, res, next) {
|
|
7724
8001
|
const validation = import_joi15.default.string().hex().required();
|
|
7725
8002
|
const _id = req.params.id;
|
|
@@ -7758,6 +8035,31 @@ function useMemberController() {
|
|
|
7758
8035
|
return;
|
|
7759
8036
|
}
|
|
7760
8037
|
}
|
|
8038
|
+
async function getAllByUser(req, res, next) {
|
|
8039
|
+
const validation = import_joi15.default.string().hex().required();
|
|
8040
|
+
const userId = req.params.id;
|
|
8041
|
+
const { error } = validation.validate(userId);
|
|
8042
|
+
if (error) {
|
|
8043
|
+
import_node_server_utils31.logger.log({
|
|
8044
|
+
level: "error",
|
|
8045
|
+
message: error.message
|
|
8046
|
+
});
|
|
8047
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
8048
|
+
return;
|
|
8049
|
+
}
|
|
8050
|
+
try {
|
|
8051
|
+
const data = await _getAllByUser(userId);
|
|
8052
|
+
res.json(data);
|
|
8053
|
+
return;
|
|
8054
|
+
} catch (error2) {
|
|
8055
|
+
import_node_server_utils31.logger.log({
|
|
8056
|
+
level: "error",
|
|
8057
|
+
message: error2.message
|
|
8058
|
+
});
|
|
8059
|
+
next(error2);
|
|
8060
|
+
return;
|
|
8061
|
+
}
|
|
8062
|
+
}
|
|
7761
8063
|
async function getByUserIdType(req, res, next) {
|
|
7762
8064
|
const validation = import_joi15.default.object({
|
|
7763
8065
|
id: import_joi15.default.string().hex().required(),
|
|
@@ -7934,6 +8236,32 @@ function useMemberController() {
|
|
|
7934
8236
|
return;
|
|
7935
8237
|
}
|
|
7936
8238
|
}
|
|
8239
|
+
async function updateSiteById(req, res, next) {
|
|
8240
|
+
const id = req.body.id?.trim();
|
|
8241
|
+
const siteId = req.body.siteId?.trim();
|
|
8242
|
+
const siteName = req.body.siteName?.trim();
|
|
8243
|
+
const validation = import_joi15.default.object({
|
|
8244
|
+
id: import_joi15.default.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
|
|
8245
|
+
siteId: import_joi15.default.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
|
|
8246
|
+
siteName: import_joi15.default.string().required()
|
|
8247
|
+
});
|
|
8248
|
+
const { error } = validation.validate({
|
|
8249
|
+
id,
|
|
8250
|
+
siteId,
|
|
8251
|
+
siteName
|
|
8252
|
+
});
|
|
8253
|
+
if (error) {
|
|
8254
|
+
return next(new import_node_server_utils31.BadRequestError(error.message));
|
|
8255
|
+
}
|
|
8256
|
+
try {
|
|
8257
|
+
await _updateSiteById(id, siteId, siteName);
|
|
8258
|
+
res.json({
|
|
8259
|
+
message: "Successfully updated member site."
|
|
8260
|
+
});
|
|
8261
|
+
} catch (error2) {
|
|
8262
|
+
next(error2);
|
|
8263
|
+
}
|
|
8264
|
+
}
|
|
7937
8265
|
return {
|
|
7938
8266
|
createMember,
|
|
7939
8267
|
getByUserId,
|
|
@@ -7942,7 +8270,9 @@ function useMemberController() {
|
|
|
7942
8270
|
getOrgsByMembership,
|
|
7943
8271
|
updateMemberStatus,
|
|
7944
8272
|
updateRoleById,
|
|
7945
|
-
createMemberDirect
|
|
8273
|
+
createMemberDirect,
|
|
8274
|
+
updateSiteById,
|
|
8275
|
+
getAllByUser
|
|
7946
8276
|
};
|
|
7947
8277
|
}
|
|
7948
8278
|
|
|
@@ -7953,7 +8283,9 @@ function useVerificationController() {
|
|
|
7953
8283
|
const {
|
|
7954
8284
|
createUserInvite: _createUserInvite,
|
|
7955
8285
|
createSimpleUserInvite: _createSimpleUserInvite,
|
|
8286
|
+
createSimpleMemberInvite: _createSimpleMemberInvite,
|
|
7956
8287
|
createServiceProviderInvite: _createServiceProviderInvite,
|
|
8288
|
+
createSimpleServiceProviderInvite: _createSimpleServiceProviderInvite,
|
|
7957
8289
|
createForgetPassword: _createForgetPassword,
|
|
7958
8290
|
verify: _verify,
|
|
7959
8291
|
updateStatusById: _updateStatusById,
|
|
@@ -8008,7 +8340,7 @@ function useVerificationController() {
|
|
|
8008
8340
|
const payload = { ...req.body };
|
|
8009
8341
|
const validation = import_joi16.default.object({
|
|
8010
8342
|
email: import_joi16.default.string().email().required(),
|
|
8011
|
-
app: import_joi16.default.string().
|
|
8343
|
+
app: import_joi16.default.array().items(import_joi16.default.string()).min(1).required(),
|
|
8012
8344
|
role: import_joi16.default.string().hex().optional().allow("", null),
|
|
8013
8345
|
name: import_joi16.default.string().optional().allow("", null),
|
|
8014
8346
|
org: import_joi16.default.string().hex().optional().allow("", null),
|
|
@@ -8025,7 +8357,7 @@ function useVerificationController() {
|
|
|
8025
8357
|
return;
|
|
8026
8358
|
}
|
|
8027
8359
|
const email = req.body.email ?? "";
|
|
8028
|
-
const app = req.body.app ??
|
|
8360
|
+
const app = req.body.app ?? [];
|
|
8029
8361
|
const role = req.body.role ?? "";
|
|
8030
8362
|
const name = req.body.name ?? "";
|
|
8031
8363
|
const org = req.body.org ?? "";
|
|
@@ -8056,6 +8388,58 @@ function useVerificationController() {
|
|
|
8056
8388
|
return;
|
|
8057
8389
|
}
|
|
8058
8390
|
}
|
|
8391
|
+
async function createSimpleMemberInvite(req, res, next) {
|
|
8392
|
+
const payload = { ...req.body };
|
|
8393
|
+
const validation = import_joi16.default.object({
|
|
8394
|
+
email: import_joi16.default.string().email().required(),
|
|
8395
|
+
app: import_joi16.default.string().optional().allow("", null),
|
|
8396
|
+
role: import_joi16.default.string().hex().optional().allow("", null),
|
|
8397
|
+
name: import_joi16.default.string().optional().allow("", null),
|
|
8398
|
+
org: import_joi16.default.string().hex().optional().allow("", null),
|
|
8399
|
+
siteId: import_joi16.default.string().hex().optional().allow("", null),
|
|
8400
|
+
siteName: import_joi16.default.string().optional().allow("", null)
|
|
8401
|
+
});
|
|
8402
|
+
const { error } = validation.validate(payload);
|
|
8403
|
+
if (error) {
|
|
8404
|
+
import_node_server_utils32.logger.log({
|
|
8405
|
+
level: "error",
|
|
8406
|
+
message: `${error.message}`
|
|
8407
|
+
});
|
|
8408
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
8409
|
+
return;
|
|
8410
|
+
}
|
|
8411
|
+
const email = req.body.email ?? "";
|
|
8412
|
+
const app = req.body.app ?? "";
|
|
8413
|
+
const role = req.body.role ?? "";
|
|
8414
|
+
const name = req.body.name ?? "";
|
|
8415
|
+
const org = req.body.org ?? "";
|
|
8416
|
+
const siteId = req.body.siteId ?? "";
|
|
8417
|
+
const siteName = req.body.siteName ?? "";
|
|
8418
|
+
try {
|
|
8419
|
+
await _createSimpleMemberInvite({
|
|
8420
|
+
email,
|
|
8421
|
+
metadata: {
|
|
8422
|
+
app,
|
|
8423
|
+
role,
|
|
8424
|
+
name,
|
|
8425
|
+
org,
|
|
8426
|
+
siteId,
|
|
8427
|
+
siteName
|
|
8428
|
+
}
|
|
8429
|
+
});
|
|
8430
|
+
res.status(201).json({
|
|
8431
|
+
message: "Successfully invited member."
|
|
8432
|
+
});
|
|
8433
|
+
return;
|
|
8434
|
+
} catch (error2) {
|
|
8435
|
+
import_node_server_utils32.logger.log({
|
|
8436
|
+
level: "error",
|
|
8437
|
+
message: `${error2.message}`
|
|
8438
|
+
});
|
|
8439
|
+
next(error2);
|
|
8440
|
+
return;
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
8059
8443
|
async function createServiceProviderInvite(req, res, next) {
|
|
8060
8444
|
const payload = req.body;
|
|
8061
8445
|
const validation = import_joi16.default.object({
|
|
@@ -8085,6 +8469,56 @@ function useVerificationController() {
|
|
|
8085
8469
|
return;
|
|
8086
8470
|
}
|
|
8087
8471
|
}
|
|
8472
|
+
async function createSimpleServiceProviderInvite(req, res, next) {
|
|
8473
|
+
const payload = { ...req.body };
|
|
8474
|
+
const validation = import_joi16.default.object({
|
|
8475
|
+
email: import_joi16.default.string().email().required(),
|
|
8476
|
+
app: import_joi16.default.string().optional().allow("", null),
|
|
8477
|
+
name: import_joi16.default.string().optional().allow("", null),
|
|
8478
|
+
role: import_joi16.default.string().hex().optional().allow("", null),
|
|
8479
|
+
orgId: import_joi16.default.string().hex().required(),
|
|
8480
|
+
siteId: import_joi16.default.string().hex().required(),
|
|
8481
|
+
siteName: import_joi16.default.string().required()
|
|
8482
|
+
});
|
|
8483
|
+
const { error } = validation.validate(payload);
|
|
8484
|
+
if (error) {
|
|
8485
|
+
import_node_server_utils32.logger.log({
|
|
8486
|
+
level: "error",
|
|
8487
|
+
message: `${error.message}`
|
|
8488
|
+
});
|
|
8489
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
8490
|
+
return;
|
|
8491
|
+
}
|
|
8492
|
+
const email = req.body.email ?? "";
|
|
8493
|
+
const app = req.body.app ?? "";
|
|
8494
|
+
const name = req.body.name ?? "";
|
|
8495
|
+
const role = req.body.role ?? "";
|
|
8496
|
+
const orgId = req.body.orgId ?? "";
|
|
8497
|
+
const siteId = req.body.siteId ?? "";
|
|
8498
|
+
const siteName = req.body.siteName ?? "";
|
|
8499
|
+
try {
|
|
8500
|
+
await _createSimpleServiceProviderInvite({
|
|
8501
|
+
email,
|
|
8502
|
+
app,
|
|
8503
|
+
name,
|
|
8504
|
+
role,
|
|
8505
|
+
orgId,
|
|
8506
|
+
siteId,
|
|
8507
|
+
siteName
|
|
8508
|
+
});
|
|
8509
|
+
res.status(201).json({
|
|
8510
|
+
message: "Successfully invited service provider."
|
|
8511
|
+
});
|
|
8512
|
+
return;
|
|
8513
|
+
} catch (error2) {
|
|
8514
|
+
import_node_server_utils32.logger.log({
|
|
8515
|
+
level: "error",
|
|
8516
|
+
message: `${error2.message}`
|
|
8517
|
+
});
|
|
8518
|
+
next(error2);
|
|
8519
|
+
return;
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8088
8522
|
async function createForgetPassword(req, res, next) {
|
|
8089
8523
|
const validation = import_joi16.default.string().email().required();
|
|
8090
8524
|
const email = req.body.email;
|
|
@@ -8217,11 +8651,13 @@ function useVerificationController() {
|
|
|
8217
8651
|
getVerifications,
|
|
8218
8652
|
createUserInvite,
|
|
8219
8653
|
createServiceProviderInvite,
|
|
8654
|
+
createSimpleServiceProviderInvite,
|
|
8220
8655
|
createForgetPassword,
|
|
8221
8656
|
verify,
|
|
8222
8657
|
updateVerificationStatus,
|
|
8223
8658
|
cancelUserInvitation,
|
|
8224
|
-
createSimpleUserInvite
|
|
8659
|
+
createSimpleUserInvite,
|
|
8660
|
+
createSimpleMemberInvite
|
|
8225
8661
|
};
|
|
8226
8662
|
}
|
|
8227
8663
|
|
|
@@ -8386,7 +8822,8 @@ function useOrgController() {
|
|
|
8386
8822
|
getById: _getById,
|
|
8387
8823
|
getByEmail: _getByEmail,
|
|
8388
8824
|
getAll: _getAll,
|
|
8389
|
-
add: _add
|
|
8825
|
+
add: _add,
|
|
8826
|
+
update: _update
|
|
8390
8827
|
} = useOrgRepo();
|
|
8391
8828
|
async function add(req, res, next) {
|
|
8392
8829
|
const validation = import_joi18.default.object({
|
|
@@ -8417,7 +8854,8 @@ function useOrgController() {
|
|
|
8417
8854
|
search: import_joi18.default.string().optional().allow("", null),
|
|
8418
8855
|
page: import_joi18.default.number().integer().min(1).allow("", null).default(1),
|
|
8419
8856
|
limit: import_joi18.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
8420
|
-
nature: import_joi18.default.string().valid(...allowedNatures).optional().allow("", null)
|
|
8857
|
+
nature: import_joi18.default.string().valid(...allowedNatures).optional().allow("", null),
|
|
8858
|
+
sort: import_joi18.default.string().optional().allow("", null)
|
|
8421
8859
|
});
|
|
8422
8860
|
const query = { ...req.query };
|
|
8423
8861
|
const { error } = validation.validate(query);
|
|
@@ -8569,6 +9007,31 @@ function useOrgController() {
|
|
|
8569
9007
|
return;
|
|
8570
9008
|
}
|
|
8571
9009
|
}
|
|
9010
|
+
async function update(req, res, next) {
|
|
9011
|
+
const validation = import_joi18.default.object({
|
|
9012
|
+
name: import_joi18.default.string().optional(),
|
|
9013
|
+
type: import_joi18.default.string().optional(),
|
|
9014
|
+
nature: import_joi18.default.string().valid(...allowedNatures).optional(),
|
|
9015
|
+
email: import_joi18.default.string().email().allow("", null).optional(),
|
|
9016
|
+
contact: import_joi18.default.string().allow("", null).optional()
|
|
9017
|
+
});
|
|
9018
|
+
const { error } = validation.validate(req.body);
|
|
9019
|
+
if (error) {
|
|
9020
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
9021
|
+
return;
|
|
9022
|
+
}
|
|
9023
|
+
const id = req.params.id;
|
|
9024
|
+
try {
|
|
9025
|
+
await _update(id, req.body);
|
|
9026
|
+
const data = await _getById(id);
|
|
9027
|
+
res.json({
|
|
9028
|
+
message: "Organization updated successfully",
|
|
9029
|
+
data
|
|
9030
|
+
});
|
|
9031
|
+
} catch (err) {
|
|
9032
|
+
next(err);
|
|
9033
|
+
}
|
|
9034
|
+
}
|
|
8572
9035
|
return {
|
|
8573
9036
|
add,
|
|
8574
9037
|
addOnboardingOrg,
|
|
@@ -8576,7 +9039,8 @@ function useOrgController() {
|
|
|
8576
9039
|
getOrgsByUserId,
|
|
8577
9040
|
getByName,
|
|
8578
9041
|
getById,
|
|
8579
|
-
getByEmail
|
|
9042
|
+
getByEmail,
|
|
9043
|
+
update
|
|
8580
9044
|
};
|
|
8581
9045
|
}
|
|
8582
9046
|
|
|
@@ -17011,6 +17475,32 @@ function useBuildingUnitRepo() {
|
|
|
17011
17475
|
}
|
|
17012
17476
|
}
|
|
17013
17477
|
}
|
|
17478
|
+
async function bulkAddBuildingUnits(value, session) {
|
|
17479
|
+
try {
|
|
17480
|
+
const operations = value.map((unit) => ({
|
|
17481
|
+
insertOne: {
|
|
17482
|
+
document: unit
|
|
17483
|
+
}
|
|
17484
|
+
}));
|
|
17485
|
+
const res = await collection.bulkWrite(operations, { session });
|
|
17486
|
+
delCachedData();
|
|
17487
|
+
return res;
|
|
17488
|
+
} catch (error) {
|
|
17489
|
+
import_node_server_utils74.logger.log({
|
|
17490
|
+
level: "error",
|
|
17491
|
+
message: error.message
|
|
17492
|
+
});
|
|
17493
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
17494
|
+
if (isDuplicated) {
|
|
17495
|
+
throw new import_node_server_utils74.BadRequestError("Some building units already exist.");
|
|
17496
|
+
}
|
|
17497
|
+
if (error instanceof import_node_server_utils74.AppError) {
|
|
17498
|
+
throw error;
|
|
17499
|
+
} else {
|
|
17500
|
+
throw new Error("Failed to bulk insert building units.");
|
|
17501
|
+
}
|
|
17502
|
+
}
|
|
17503
|
+
}
|
|
17014
17504
|
return {
|
|
17015
17505
|
createIndexes,
|
|
17016
17506
|
add,
|
|
@@ -17026,7 +17516,8 @@ function useBuildingUnitRepo() {
|
|
|
17026
17516
|
getBuildingUnitsForResident,
|
|
17027
17517
|
getBuildingUnitsWithOwner,
|
|
17028
17518
|
getUnitByBlockLevelUnitNumber,
|
|
17029
|
-
getBySiteBuildingLevel
|
|
17519
|
+
getBySiteBuildingLevel,
|
|
17520
|
+
bulkAddBuildingUnits
|
|
17030
17521
|
};
|
|
17031
17522
|
}
|
|
17032
17523
|
|
|
@@ -17801,6 +18292,167 @@ function useVehicleService() {
|
|
|
17801
18292
|
throw error;
|
|
17802
18293
|
}
|
|
17803
18294
|
}
|
|
18295
|
+
async function blocklistVehicles(_id, value) {
|
|
18296
|
+
const session = import_node_server_utils75.useAtlas.getClient()?.startSession();
|
|
18297
|
+
if (!session) {
|
|
18298
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
18299
|
+
}
|
|
18300
|
+
try {
|
|
18301
|
+
session.startTransaction();
|
|
18302
|
+
const vehicle = await _getVehicleById(_id);
|
|
18303
|
+
const plate = vehicle.plates.find((p) => p._id.toString() === _id);
|
|
18304
|
+
const _name = value.name ? value.name : vehicle.name;
|
|
18305
|
+
const _plateNumber = plate?.plateNumber;
|
|
18306
|
+
const _start = vehicle.start;
|
|
18307
|
+
const _end = vehicle.end;
|
|
18308
|
+
const _recNo = plate.recNo;
|
|
18309
|
+
const _type = plate.type;
|
|
18310
|
+
if (value.peopleId) {
|
|
18311
|
+
value.peopleId = new import_mongodb46.ObjectId(value.peopleId);
|
|
18312
|
+
}
|
|
18313
|
+
const { site } = value;
|
|
18314
|
+
const startDahua = formatDahuaDate(_start);
|
|
18315
|
+
const endPlus24Hours = _end ? _end : new Date(new Date(_end).getTime() + 24 * 60 * 60 * 1e3);
|
|
18316
|
+
const endDahua = formatDahuaDate(endPlus24Hours);
|
|
18317
|
+
if (_plateNumber) {
|
|
18318
|
+
const siteCameras = [];
|
|
18319
|
+
let page = 1;
|
|
18320
|
+
let pages = 1;
|
|
18321
|
+
const limit = 20;
|
|
18322
|
+
do {
|
|
18323
|
+
const siteCameraReq = await _getAllSiteCameras({
|
|
18324
|
+
site,
|
|
18325
|
+
type: "anpr",
|
|
18326
|
+
direction: ["both", "entry"],
|
|
18327
|
+
page,
|
|
18328
|
+
limit
|
|
18329
|
+
});
|
|
18330
|
+
pages = siteCameraReq.pages || 1;
|
|
18331
|
+
siteCameras.push(...siteCameraReq.items);
|
|
18332
|
+
page++;
|
|
18333
|
+
} while (page < pages);
|
|
18334
|
+
if (!siteCameras.length) {
|
|
18335
|
+
throw new import_node_server_utils75.BadRequestError("No site cameras found.");
|
|
18336
|
+
}
|
|
18337
|
+
for (const camera of siteCameras) {
|
|
18338
|
+
const { host, username, password } = camera;
|
|
18339
|
+
const removePlateNumber = {
|
|
18340
|
+
host,
|
|
18341
|
+
username,
|
|
18342
|
+
password,
|
|
18343
|
+
mode: _type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
18344
|
+
recno: _recNo
|
|
18345
|
+
};
|
|
18346
|
+
const responseForDeletion = await _removePlateNumber(
|
|
18347
|
+
removePlateNumber
|
|
18348
|
+
);
|
|
18349
|
+
if (responseForDeletion?.statusCode !== 200) {
|
|
18350
|
+
throw new import_node_server_utils75.BadRequestError("Failed to delete plate number to ANPR");
|
|
18351
|
+
}
|
|
18352
|
+
const dahuaPayload = {
|
|
18353
|
+
host,
|
|
18354
|
+
username,
|
|
18355
|
+
password,
|
|
18356
|
+
plateNumber: _plateNumber,
|
|
18357
|
+
mode: "TrafficBlackList" /* TRAFFIC_BLACKLIST */,
|
|
18358
|
+
owner: _name,
|
|
18359
|
+
...startDahua ? { start: startDahua } : {},
|
|
18360
|
+
...endDahua ? { end: endDahua } : {}
|
|
18361
|
+
};
|
|
18362
|
+
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
18363
|
+
if (dahuaResponse?.statusCode !== 200) {
|
|
18364
|
+
throw new import_node_server_utils75.BadRequestError("Failed to update plate number to ANPR");
|
|
18365
|
+
}
|
|
18366
|
+
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
18367
|
+
value.recNo = responseData.split("=")[1]?.trim();
|
|
18368
|
+
const normalizedPlateNumber = _plateNumber;
|
|
18369
|
+
if (value.peopleId && value.recNo) {
|
|
18370
|
+
await _pushVehicleById(
|
|
18371
|
+
value.peopleId,
|
|
18372
|
+
{
|
|
18373
|
+
plateNumber: normalizedPlateNumber,
|
|
18374
|
+
recNo: value.recNo
|
|
18375
|
+
},
|
|
18376
|
+
session
|
|
18377
|
+
);
|
|
18378
|
+
}
|
|
18379
|
+
}
|
|
18380
|
+
}
|
|
18381
|
+
const formattedValue = {
|
|
18382
|
+
type: "blocklist" /* BLOCKLIST */,
|
|
18383
|
+
recNo: value.recNo
|
|
18384
|
+
};
|
|
18385
|
+
await _updateVehicleById(_id, formattedValue, session);
|
|
18386
|
+
await session.commitTransaction();
|
|
18387
|
+
} catch (error) {
|
|
18388
|
+
await session.abortTransaction();
|
|
18389
|
+
throw error;
|
|
18390
|
+
} finally {
|
|
18391
|
+
session.endSession();
|
|
18392
|
+
}
|
|
18393
|
+
}
|
|
18394
|
+
async function removeFromBlocklist(_id, value) {
|
|
18395
|
+
const session = import_node_server_utils75.useAtlas.getClient()?.startSession();
|
|
18396
|
+
if (!session) {
|
|
18397
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
18398
|
+
}
|
|
18399
|
+
try {
|
|
18400
|
+
session.startTransaction();
|
|
18401
|
+
const vehicle = await _getVehicleById(_id);
|
|
18402
|
+
const plate = vehicle.plates.find((p) => p._id.toString() === _id);
|
|
18403
|
+
const _plateNumber = plate?.plateNumber;
|
|
18404
|
+
const _recNo = plate.recNo;
|
|
18405
|
+
if (value.peopleId) {
|
|
18406
|
+
value.peopleId = new import_mongodb46.ObjectId(value.peopleId);
|
|
18407
|
+
}
|
|
18408
|
+
const { site } = value;
|
|
18409
|
+
if (_plateNumber) {
|
|
18410
|
+
const siteCameras = [];
|
|
18411
|
+
let page = 1;
|
|
18412
|
+
let pages = 1;
|
|
18413
|
+
const limit = 20;
|
|
18414
|
+
do {
|
|
18415
|
+
const siteCameraReq = await _getAllSiteCameras({
|
|
18416
|
+
site,
|
|
18417
|
+
type: "anpr",
|
|
18418
|
+
direction: ["both", "entry"],
|
|
18419
|
+
page,
|
|
18420
|
+
limit
|
|
18421
|
+
});
|
|
18422
|
+
pages = siteCameraReq.pages || 1;
|
|
18423
|
+
siteCameras.push(...siteCameraReq.items);
|
|
18424
|
+
page++;
|
|
18425
|
+
} while (page < pages);
|
|
18426
|
+
if (!siteCameras.length) {
|
|
18427
|
+
throw new import_node_server_utils75.BadRequestError("No site cameras found.");
|
|
18428
|
+
}
|
|
18429
|
+
for (const camera of siteCameras) {
|
|
18430
|
+
const { host, username, password } = camera;
|
|
18431
|
+
const removePlateNumber = {
|
|
18432
|
+
host,
|
|
18433
|
+
username,
|
|
18434
|
+
password,
|
|
18435
|
+
mode: "TrafficBlackList" /* TRAFFIC_BLACKLIST */,
|
|
18436
|
+
recno: _recNo
|
|
18437
|
+
};
|
|
18438
|
+
console.log(removePlateNumber);
|
|
18439
|
+
const responseForDeletion = await _removePlateNumber(
|
|
18440
|
+
removePlateNumber
|
|
18441
|
+
);
|
|
18442
|
+
if (responseForDeletion?.statusCode !== 200) {
|
|
18443
|
+
throw new import_node_server_utils75.BadRequestError("Failed to delete plate number to ANPR");
|
|
18444
|
+
}
|
|
18445
|
+
}
|
|
18446
|
+
}
|
|
18447
|
+
await _deleteVehicle(_id, session);
|
|
18448
|
+
await session.commitTransaction();
|
|
18449
|
+
} catch (error) {
|
|
18450
|
+
await session.abortTransaction();
|
|
18451
|
+
throw error;
|
|
18452
|
+
} finally {
|
|
18453
|
+
session.endSession();
|
|
18454
|
+
}
|
|
18455
|
+
}
|
|
17804
18456
|
return {
|
|
17805
18457
|
add,
|
|
17806
18458
|
deleteVehicle,
|
|
@@ -17808,7 +18460,9 @@ function useVehicleService() {
|
|
|
17808
18460
|
processDeletingExpiredVehicles,
|
|
17809
18461
|
reactivateVehicleById,
|
|
17810
18462
|
updateVehicleById,
|
|
17811
|
-
bulkUpsertVehicles
|
|
18463
|
+
bulkUpsertVehicles,
|
|
18464
|
+
blocklistVehicles,
|
|
18465
|
+
removeFromBlocklist
|
|
17812
18466
|
};
|
|
17813
18467
|
}
|
|
17814
18468
|
|
|
@@ -20159,7 +20813,7 @@ function useBuildingService() {
|
|
|
20159
20813
|
getByBuildingLevel,
|
|
20160
20814
|
updateLevelByBuildingLevel,
|
|
20161
20815
|
updateByBuildingId,
|
|
20162
|
-
|
|
20816
|
+
bulkAddBuildingUnits: _bulkAddBuildingUnits
|
|
20163
20817
|
} = useBuildingUnitRepo();
|
|
20164
20818
|
const { updateStatusById } = useFileRepo();
|
|
20165
20819
|
const { deleteFile } = useFileService();
|
|
@@ -20348,15 +21002,16 @@ function useBuildingService() {
|
|
|
20348
21002
|
companyName: "",
|
|
20349
21003
|
companyRegistrationNumber: "",
|
|
20350
21004
|
billing: [],
|
|
20351
|
-
unitNumber: parseInt(unit.replace("Unit ", ""), 10) || null
|
|
21005
|
+
unitNumber: parseInt(unit.replace("Unit ", ""), 10) || null,
|
|
21006
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
21007
|
+
updatedAt: "",
|
|
21008
|
+
deletedAt: ""
|
|
20352
21009
|
});
|
|
20353
21010
|
});
|
|
20354
21011
|
});
|
|
20355
21012
|
}
|
|
20356
21013
|
);
|
|
20357
|
-
|
|
20358
|
-
const result = await _addBuildingUnit(buildingUnitPayload);
|
|
20359
|
-
}
|
|
21014
|
+
await _bulkAddBuildingUnits(buildingUnitPayloads);
|
|
20360
21015
|
await session?.commitTransaction();
|
|
20361
21016
|
return { buildingPayloads, buildingUnitPayloads };
|
|
20362
21017
|
} catch (error) {
|
|
@@ -21097,7 +21752,9 @@ function useVehicleController() {
|
|
|
21097
21752
|
approveVehicleById: _approveVehicleById,
|
|
21098
21753
|
reactivateVehicleById: _reactivateVehicleById,
|
|
21099
21754
|
updateVehicleById: _updateVehicleById,
|
|
21100
|
-
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
21755
|
+
bulkUpsertVehicles: _bulkUpsertVehicles,
|
|
21756
|
+
blocklistVehicles: _blocklistVehicles,
|
|
21757
|
+
removeFromBlocklist: _removeFromBlocklist
|
|
21101
21758
|
} = useVehicleService();
|
|
21102
21759
|
const {
|
|
21103
21760
|
getSeasonPassTypes: _getSeasonPassTypes,
|
|
@@ -21674,6 +22331,68 @@ function useVehicleController() {
|
|
|
21674
22331
|
return;
|
|
21675
22332
|
}
|
|
21676
22333
|
}
|
|
22334
|
+
async function blocklistVehicles(req, res, next) {
|
|
22335
|
+
try {
|
|
22336
|
+
const schema2 = import_joi47.default.object({
|
|
22337
|
+
_id: import_joi47.default.string().hex().length(24).required(),
|
|
22338
|
+
site: import_joi47.default.string().hex().length(24).required(),
|
|
22339
|
+
peopleId: import_joi47.default.string().hex().length(24).optional().allow(null, ""),
|
|
22340
|
+
remarks: import_joi47.default.string().optional().allow("", null)
|
|
22341
|
+
});
|
|
22342
|
+
const { error, value } = schema2.validate(
|
|
22343
|
+
{
|
|
22344
|
+
_id: req.params.id,
|
|
22345
|
+
...req.body
|
|
22346
|
+
},
|
|
22347
|
+
{ abortEarly: false }
|
|
22348
|
+
);
|
|
22349
|
+
if (error) {
|
|
22350
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
22351
|
+
import_node_server_utils88.logger.log({ level: "error", message: messages });
|
|
22352
|
+
next(new import_node_server_utils88.BadRequestError(messages));
|
|
22353
|
+
return;
|
|
22354
|
+
}
|
|
22355
|
+
const { _id, ...rest } = value;
|
|
22356
|
+
await _blocklistVehicles(_id, rest);
|
|
22357
|
+
res.json({ message: "Successfully blocked vehicle." });
|
|
22358
|
+
return;
|
|
22359
|
+
} catch (error) {
|
|
22360
|
+
import_node_server_utils88.logger.log({ level: "error", message: error.message });
|
|
22361
|
+
next(error);
|
|
22362
|
+
return;
|
|
22363
|
+
}
|
|
22364
|
+
}
|
|
22365
|
+
async function removeFromBlocklist(req, res, next) {
|
|
22366
|
+
try {
|
|
22367
|
+
const schema2 = import_joi47.default.object({
|
|
22368
|
+
_id: import_joi47.default.string().hex().length(24).required(),
|
|
22369
|
+
site: import_joi47.default.string().hex().length(24).required(),
|
|
22370
|
+
peopleId: import_joi47.default.string().hex().length(24).optional().allow(null, ""),
|
|
22371
|
+
remarks: import_joi47.default.string().optional().allow("", null)
|
|
22372
|
+
});
|
|
22373
|
+
const { error, value } = schema2.validate(
|
|
22374
|
+
{
|
|
22375
|
+
_id: req.params.id,
|
|
22376
|
+
...req.body
|
|
22377
|
+
},
|
|
22378
|
+
{ abortEarly: false }
|
|
22379
|
+
);
|
|
22380
|
+
if (error) {
|
|
22381
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
22382
|
+
import_node_server_utils88.logger.log({ level: "error", message: messages });
|
|
22383
|
+
next(new import_node_server_utils88.BadRequestError(messages));
|
|
22384
|
+
return;
|
|
22385
|
+
}
|
|
22386
|
+
const { _id, ...rest } = value;
|
|
22387
|
+
await _removeFromBlocklist(_id, rest);
|
|
22388
|
+
res.json({ message: "Successfully removed vehicle from blocklist." });
|
|
22389
|
+
return;
|
|
22390
|
+
} catch (error) {
|
|
22391
|
+
import_node_server_utils88.logger.log({ level: "error", message: error.message });
|
|
22392
|
+
next(error);
|
|
22393
|
+
return;
|
|
22394
|
+
}
|
|
22395
|
+
}
|
|
21677
22396
|
return {
|
|
21678
22397
|
add,
|
|
21679
22398
|
getVehicles,
|
|
@@ -21687,7 +22406,9 @@ function useVehicleController() {
|
|
|
21687
22406
|
getAllVehiclesByUnitId,
|
|
21688
22407
|
uploadSpreadsheetVehicles,
|
|
21689
22408
|
getSpecificVehicleById,
|
|
21690
|
-
getBlocklistedVehicles
|
|
22409
|
+
getBlocklistedVehicles,
|
|
22410
|
+
blocklistVehicles,
|
|
22411
|
+
removeFromBlocklist
|
|
21691
22412
|
};
|
|
21692
22413
|
}
|
|
21693
22414
|
|
|
@@ -31178,6 +31899,18 @@ function MBulletinBoard(value) {
|
|
|
31178
31899
|
throw new Error("Invalid org ID.");
|
|
31179
31900
|
}
|
|
31180
31901
|
}
|
|
31902
|
+
if (value.file && Array.isArray(value.file)) {
|
|
31903
|
+
value.file = value.file.map((f) => {
|
|
31904
|
+
if (f._id && typeof f._id === "string") {
|
|
31905
|
+
try {
|
|
31906
|
+
return { ...f, _id: new import_mongodb78.ObjectId(f._id) };
|
|
31907
|
+
} catch {
|
|
31908
|
+
throw new Error("Invalid file ID.");
|
|
31909
|
+
}
|
|
31910
|
+
}
|
|
31911
|
+
return f;
|
|
31912
|
+
});
|
|
31913
|
+
}
|
|
31181
31914
|
return {
|
|
31182
31915
|
_id: value._id ?? new import_mongodb78.ObjectId(),
|
|
31183
31916
|
site: value.site ?? "",
|
|
@@ -31496,7 +32229,7 @@ function useBulletinBoardService() {
|
|
|
31496
32229
|
deleteBulletinBoardById: _deleteBulletinBoardById,
|
|
31497
32230
|
getBulletinBoardById: _getBulletinBoardById
|
|
31498
32231
|
} = useBulletinBoardRepo();
|
|
31499
|
-
const { deleteFileById: _deleteFileById } = useFileRepo();
|
|
32232
|
+
const { deleteFileById: _deleteFileById, updateStatusById } = useFileRepo();
|
|
31500
32233
|
async function add(value) {
|
|
31501
32234
|
const session = import_node_server_utils137.useAtlas.getClient()?.startSession();
|
|
31502
32235
|
session?.startTransaction();
|
|
@@ -31504,6 +32237,21 @@ function useBulletinBoardService() {
|
|
|
31504
32237
|
value.status = "upcoming" /* UPCOMING */;
|
|
31505
32238
|
}
|
|
31506
32239
|
try {
|
|
32240
|
+
const bulletinFiles = value?.file ?? [];
|
|
32241
|
+
if (bulletinFiles.length > 0) {
|
|
32242
|
+
for (const bulletinFile of bulletinFiles) {
|
|
32243
|
+
if (!bulletinFile._id)
|
|
32244
|
+
continue;
|
|
32245
|
+
const file = await updateStatusById(
|
|
32246
|
+
bulletinFile._id.toString(),
|
|
32247
|
+
{ status: "active" },
|
|
32248
|
+
session
|
|
32249
|
+
);
|
|
32250
|
+
if (!file) {
|
|
32251
|
+
throw new import_node_server_utils137.NotFoundError("File not found.");
|
|
32252
|
+
}
|
|
32253
|
+
}
|
|
32254
|
+
}
|
|
31507
32255
|
await _add(value, session);
|
|
31508
32256
|
await session?.commitTransaction();
|
|
31509
32257
|
return "Successfully added bulletin board.";
|
|
@@ -37265,6 +38013,19 @@ function UseAccessManagementRepo() {
|
|
|
37265
38013
|
await session?.endSession();
|
|
37266
38014
|
}
|
|
37267
38015
|
}
|
|
38016
|
+
async function uploadTemplateRepo({ site, id, name }) {
|
|
38017
|
+
site = new import_mongodb90.ObjectId(site);
|
|
38018
|
+
id = new import_mongodb90.ObjectId(id);
|
|
38019
|
+
try {
|
|
38020
|
+
const result = await collectionName("sites").updateOne(
|
|
38021
|
+
{ _id: site },
|
|
38022
|
+
{ $set: { "siteSettings.entryPass.settings.template": { id, name } } }
|
|
38023
|
+
);
|
|
38024
|
+
return result;
|
|
38025
|
+
} catch (error) {
|
|
38026
|
+
throw new Error(error.message);
|
|
38027
|
+
}
|
|
38028
|
+
}
|
|
37268
38029
|
return {
|
|
37269
38030
|
createIndexes,
|
|
37270
38031
|
createIndexForEntrypass,
|
|
@@ -37299,7 +38060,8 @@ function UseAccessManagementRepo() {
|
|
|
37299
38060
|
indexCombination,
|
|
37300
38061
|
getTransactionsRepo,
|
|
37301
38062
|
assignMultipleCardsRepo,
|
|
37302
|
-
visitorCheckoutRepo
|
|
38063
|
+
visitorCheckoutRepo,
|
|
38064
|
+
uploadTemplateRepo
|
|
37303
38065
|
};
|
|
37304
38066
|
}
|
|
37305
38067
|
|
|
@@ -37342,7 +38104,8 @@ function useAccessManagementSvc() {
|
|
|
37342
38104
|
getBlockLevelAndUnitListRepo,
|
|
37343
38105
|
getTransactionsRepo,
|
|
37344
38106
|
assignMultipleCardsRepo,
|
|
37345
|
-
visitorCheckoutRepo
|
|
38107
|
+
visitorCheckoutRepo,
|
|
38108
|
+
uploadTemplateRepo
|
|
37346
38109
|
} = UseAccessManagementRepo();
|
|
37347
38110
|
const addPhysicalCardSvc = async (payload) => {
|
|
37348
38111
|
try {
|
|
@@ -37655,7 +38418,15 @@ function useAccessManagementSvc() {
|
|
|
37655
38418
|
const response = await visitorCheckoutRepo({ userId });
|
|
37656
38419
|
return response;
|
|
37657
38420
|
} catch (err) {
|
|
37658
|
-
|
|
38421
|
+
throw new Error(err.message);
|
|
38422
|
+
}
|
|
38423
|
+
};
|
|
38424
|
+
const uploadTemplateSvc = async ({ site, id, name }) => {
|
|
38425
|
+
try {
|
|
38426
|
+
const response = await uploadTemplateRepo({ site, id, name });
|
|
38427
|
+
return response;
|
|
38428
|
+
} catch (err) {
|
|
38429
|
+
throw new Error(err.message);
|
|
37659
38430
|
}
|
|
37660
38431
|
};
|
|
37661
38432
|
return {
|
|
@@ -37695,7 +38466,8 @@ function useAccessManagementSvc() {
|
|
|
37695
38466
|
getBlockLevelAndUnitListSvc,
|
|
37696
38467
|
getTransactionsSvc,
|
|
37697
38468
|
assignMultipleCardsSvc,
|
|
37698
|
-
visitorCheckoutSvc
|
|
38469
|
+
visitorCheckoutSvc,
|
|
38470
|
+
uploadTemplateSvc
|
|
37699
38471
|
};
|
|
37700
38472
|
}
|
|
37701
38473
|
|
|
@@ -37738,7 +38510,8 @@ function useAccessManagementController() {
|
|
|
37738
38510
|
getBlockLevelAndUnitListSvc,
|
|
37739
38511
|
getTransactionsSvc,
|
|
37740
38512
|
assignMultipleCardsSvc,
|
|
37741
|
-
visitorCheckoutSvc
|
|
38513
|
+
visitorCheckoutSvc,
|
|
38514
|
+
uploadTemplateSvc
|
|
37742
38515
|
} = useAccessManagementSvc();
|
|
37743
38516
|
const addPhysicalCard = async (req, res) => {
|
|
37744
38517
|
try {
|
|
@@ -38555,7 +39328,32 @@ function useAccessManagementController() {
|
|
|
38555
39328
|
const result = await visitorCheckoutSvc({ userId });
|
|
38556
39329
|
return res.status(200).json({ message: "Success", data: result });
|
|
38557
39330
|
} catch (error) {
|
|
38558
|
-
return
|
|
39331
|
+
return res.status(400).json({
|
|
39332
|
+
data: null,
|
|
39333
|
+
message: error.message
|
|
39334
|
+
});
|
|
39335
|
+
}
|
|
39336
|
+
};
|
|
39337
|
+
const uploadTemplate = async (req, res) => {
|
|
39338
|
+
try {
|
|
39339
|
+
const { site } = req.query;
|
|
39340
|
+
const { id, name } = req.body;
|
|
39341
|
+
const schema2 = import_joi86.default.object({
|
|
39342
|
+
site: import_joi86.default.string().hex().required(),
|
|
39343
|
+
id: import_joi86.default.string().hex().required(),
|
|
39344
|
+
name: import_joi86.default.string().required()
|
|
39345
|
+
});
|
|
39346
|
+
const { error } = schema2.validate({ site, id, name });
|
|
39347
|
+
if (error) {
|
|
39348
|
+
return res.status(400).json({ message: error.message });
|
|
39349
|
+
}
|
|
39350
|
+
const result = await uploadTemplateSvc({ site, id, name });
|
|
39351
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
39352
|
+
} catch (error) {
|
|
39353
|
+
return res.status(400).json({
|
|
39354
|
+
data: null,
|
|
39355
|
+
message: error.message
|
|
39356
|
+
});
|
|
38559
39357
|
}
|
|
38560
39358
|
};
|
|
38561
39359
|
return {
|
|
@@ -38593,7 +39391,8 @@ function useAccessManagementController() {
|
|
|
38593
39391
|
getBlockLevelAndUnitList,
|
|
38594
39392
|
getTransactions: getTransactions2,
|
|
38595
39393
|
assignMultipleCards,
|
|
38596
|
-
visitorCheckout
|
|
39394
|
+
visitorCheckout,
|
|
39395
|
+
uploadTemplate
|
|
38597
39396
|
};
|
|
38598
39397
|
}
|
|
38599
39398
|
|
|
@@ -39996,11 +40795,22 @@ function useBulletinVideoService() {
|
|
|
39996
40795
|
deleteBulletinVideoById: _deleteBulletinVideoById,
|
|
39997
40796
|
getBulletinVideoById: _getBulletinVideoById
|
|
39998
40797
|
} = useBulletinVideoRepo();
|
|
39999
|
-
const { deleteFileById: _deleteFileById } = useFileRepo();
|
|
40798
|
+
const { deleteFileById: _deleteFileById, updateStatusById } = useFileRepo();
|
|
40000
40799
|
async function add(value) {
|
|
40001
40800
|
const session = import_node_server_utils163.useAtlas.getClient()?.startSession();
|
|
40002
40801
|
session?.startTransaction();
|
|
40003
40802
|
try {
|
|
40803
|
+
const bulletinVideo = value.file;
|
|
40804
|
+
if (bulletinVideo) {
|
|
40805
|
+
const file = await updateStatusById(
|
|
40806
|
+
bulletinVideo,
|
|
40807
|
+
{ status: "active" },
|
|
40808
|
+
session
|
|
40809
|
+
);
|
|
40810
|
+
if (!file) {
|
|
40811
|
+
throw new import_node_server_utils163.NotFoundError("File not found.");
|
|
40812
|
+
}
|
|
40813
|
+
}
|
|
40004
40814
|
await _add(value, session);
|
|
40005
40815
|
await session?.commitTransaction();
|
|
40006
40816
|
return "Successfully added bulletin video.";
|