@7365admin1/core 2.60.0 → 2.61.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 +6 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +511 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +511 -20
- 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
|
|