@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.mjs
CHANGED
|
@@ -3060,6 +3060,39 @@ function useMemberRepo() {
|
|
|
3060
3060
|
}
|
|
3061
3061
|
}
|
|
3062
3062
|
}
|
|
3063
|
+
async function getAllByUserId(user) {
|
|
3064
|
+
try {
|
|
3065
|
+
user = new ObjectId11(user);
|
|
3066
|
+
} catch (error) {
|
|
3067
|
+
throw new BadRequestError11("Invalid user ID format.");
|
|
3068
|
+
}
|
|
3069
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
3070
|
+
user: user.toString(),
|
|
3071
|
+
type: "all"
|
|
3072
|
+
});
|
|
3073
|
+
const cachedData = await getCache(cacheKey);
|
|
3074
|
+
if (cachedData) {
|
|
3075
|
+
logger8.info(`Cache hit for key: ${cacheKey}`);
|
|
3076
|
+
return cachedData;
|
|
3077
|
+
}
|
|
3078
|
+
try {
|
|
3079
|
+
const data = await collection.find({ user }).toArray();
|
|
3080
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3081
|
+
logger8.info(`Cache set for key: ${cacheKey}`);
|
|
3082
|
+
}).catch((err) => {
|
|
3083
|
+
logger8.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3084
|
+
});
|
|
3085
|
+
return data;
|
|
3086
|
+
} catch (error) {
|
|
3087
|
+
if (error instanceof AppError2) {
|
|
3088
|
+
throw error;
|
|
3089
|
+
} else {
|
|
3090
|
+
throw new InternalServerError6(
|
|
3091
|
+
"Internal server error, failed to retrieve members."
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3063
3096
|
async function getByRoleId(role) {
|
|
3064
3097
|
try {
|
|
3065
3098
|
role = new ObjectId11(role);
|
|
@@ -3535,6 +3568,58 @@ function useMemberRepo() {
|
|
|
3535
3568
|
throw new InternalServerError6("Failed to count user memberships.");
|
|
3536
3569
|
}
|
|
3537
3570
|
}
|
|
3571
|
+
async function updateSiteById(_id, siteId, siteName) {
|
|
3572
|
+
try {
|
|
3573
|
+
_id = new ObjectId11(_id);
|
|
3574
|
+
} catch (error) {
|
|
3575
|
+
throw new BadRequestError11("Invalid member ID format.");
|
|
3576
|
+
}
|
|
3577
|
+
try {
|
|
3578
|
+
siteId = new ObjectId11(siteId);
|
|
3579
|
+
} catch (error) {
|
|
3580
|
+
throw new BadRequestError11("Invalid site ID format.");
|
|
3581
|
+
}
|
|
3582
|
+
try {
|
|
3583
|
+
const updateValue = {
|
|
3584
|
+
siteId,
|
|
3585
|
+
siteName,
|
|
3586
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
3587
|
+
};
|
|
3588
|
+
const res = await collection.updateOne(
|
|
3589
|
+
{ _id },
|
|
3590
|
+
{ $set: updateValue }
|
|
3591
|
+
);
|
|
3592
|
+
if (res.modifiedCount === 0) {
|
|
3593
|
+
throw new InternalServerError6(
|
|
3594
|
+
"Unable to update member site."
|
|
3595
|
+
);
|
|
3596
|
+
}
|
|
3597
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
3598
|
+
_id: _id.toString()
|
|
3599
|
+
});
|
|
3600
|
+
delCache(cacheKey).then(() => {
|
|
3601
|
+
logger8.info(`Cache deleted for key: ${cacheKey}`);
|
|
3602
|
+
}).catch((err) => {
|
|
3603
|
+
logger8.error(
|
|
3604
|
+
`Failed to delete cache for key: ${cacheKey}`,
|
|
3605
|
+
err
|
|
3606
|
+
);
|
|
3607
|
+
});
|
|
3608
|
+
delNamespace().then(() => {
|
|
3609
|
+
logger8.info(
|
|
3610
|
+
`Cache cleared for namespace: ${namespace_collection}`
|
|
3611
|
+
);
|
|
3612
|
+
}).catch((err) => {
|
|
3613
|
+
logger8.error(
|
|
3614
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3615
|
+
err
|
|
3616
|
+
);
|
|
3617
|
+
});
|
|
3618
|
+
return res.modifiedCount;
|
|
3619
|
+
} catch (error) {
|
|
3620
|
+
throw error;
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3538
3623
|
return {
|
|
3539
3624
|
createIndex,
|
|
3540
3625
|
createUniqueIndex,
|
|
@@ -3542,6 +3627,7 @@ function useMemberRepo() {
|
|
|
3542
3627
|
add,
|
|
3543
3628
|
getById,
|
|
3544
3629
|
getByUserId,
|
|
3630
|
+
getAllByUserId,
|
|
3545
3631
|
getByUserIdType,
|
|
3546
3632
|
getByRoleId,
|
|
3547
3633
|
getAll,
|
|
@@ -3553,7 +3639,8 @@ function useMemberRepo() {
|
|
|
3553
3639
|
countByOrg,
|
|
3554
3640
|
countUserMembershipById,
|
|
3555
3641
|
updateRoleById,
|
|
3556
|
-
getByRoles
|
|
3642
|
+
getByRoles,
|
|
3643
|
+
updateSiteById
|
|
3557
3644
|
};
|
|
3558
3645
|
}
|
|
3559
3646
|
|
|
@@ -4106,6 +4193,25 @@ function useOrgRepo() {
|
|
|
4106
4193
|
}
|
|
4107
4194
|
}
|
|
4108
4195
|
}
|
|
4196
|
+
async function update(id, value, session) {
|
|
4197
|
+
try {
|
|
4198
|
+
await collection.updateOne(
|
|
4199
|
+
{ _id: new ObjectId15(id) },
|
|
4200
|
+
{
|
|
4201
|
+
$set: {
|
|
4202
|
+
...value,
|
|
4203
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
4204
|
+
}
|
|
4205
|
+
},
|
|
4206
|
+
{ session }
|
|
4207
|
+
);
|
|
4208
|
+
await delNamespace();
|
|
4209
|
+
return id;
|
|
4210
|
+
} catch (error) {
|
|
4211
|
+
logger10.log({ level: "error", message: error.message });
|
|
4212
|
+
throw new InternalServerError9("Failed to update organization.");
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4109
4215
|
async function getAll({
|
|
4110
4216
|
search = "",
|
|
4111
4217
|
page = 1,
|
|
@@ -4341,6 +4447,7 @@ function useOrgRepo() {
|
|
|
4341
4447
|
createTextIndex,
|
|
4342
4448
|
createUniqueIndex,
|
|
4343
4449
|
add,
|
|
4450
|
+
update,
|
|
4344
4451
|
getAll,
|
|
4345
4452
|
getById,
|
|
4346
4453
|
getByName,
|
|
@@ -5301,6 +5408,7 @@ function useVerificationService() {
|
|
|
5301
5408
|
const { getUserByEmail } = useUserRepo();
|
|
5302
5409
|
const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
|
|
5303
5410
|
const { getSiteById } = useSiteRepo();
|
|
5411
|
+
const { getByUserIdType } = useMemberRepo();
|
|
5304
5412
|
async function createUserInvite({
|
|
5305
5413
|
email,
|
|
5306
5414
|
metadata
|
|
@@ -5356,8 +5464,77 @@ function useVerificationService() {
|
|
|
5356
5464
|
throw error;
|
|
5357
5465
|
}
|
|
5358
5466
|
}
|
|
5359
|
-
async function createSimpleUserInvite({
|
|
5467
|
+
async function createSimpleUserInvite({
|
|
5468
|
+
email,
|
|
5469
|
+
metadata
|
|
5470
|
+
}) {
|
|
5360
5471
|
const type = "user-invite";
|
|
5472
|
+
const apps = Array.isArray(metadata.app) ? metadata.app : [metadata.app];
|
|
5473
|
+
if (metadata?.org) {
|
|
5474
|
+
await getOrgById(metadata.org);
|
|
5475
|
+
}
|
|
5476
|
+
if (metadata?.siteId) {
|
|
5477
|
+
await getSiteById(metadata.siteId);
|
|
5478
|
+
}
|
|
5479
|
+
const verificationIds = [];
|
|
5480
|
+
const invitedApps = [];
|
|
5481
|
+
for (const app of apps) {
|
|
5482
|
+
await useVerificationRepo().findOne({
|
|
5483
|
+
type,
|
|
5484
|
+
email,
|
|
5485
|
+
"metadata.app": app,
|
|
5486
|
+
"metadata.org": metadata.org,
|
|
5487
|
+
"metadata.siteId": metadata.siteId
|
|
5488
|
+
});
|
|
5489
|
+
const value = {
|
|
5490
|
+
type,
|
|
5491
|
+
email,
|
|
5492
|
+
metadata: {
|
|
5493
|
+
...metadata,
|
|
5494
|
+
app
|
|
5495
|
+
},
|
|
5496
|
+
expireAt: new Date(
|
|
5497
|
+
Date.now() + 72 * 60 * 60 * 1e3
|
|
5498
|
+
).toISOString(),
|
|
5499
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5500
|
+
};
|
|
5501
|
+
const createdId = await add(value);
|
|
5502
|
+
verificationIds.push(createdId.toString());
|
|
5503
|
+
invitedApps.push(app);
|
|
5504
|
+
}
|
|
5505
|
+
const link = `${APP_MAIN}/verify/invitation/${verificationIds[0]}`;
|
|
5506
|
+
const appsSet = new Set(invitedApps);
|
|
5507
|
+
const emailContent = compileHandlebar({
|
|
5508
|
+
context: {
|
|
5509
|
+
email,
|
|
5510
|
+
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5511
|
+
link,
|
|
5512
|
+
hasPropertyManagement: appsSet.has("property_management_agency"),
|
|
5513
|
+
hasSecurity: appsSet.has("security_agency"),
|
|
5514
|
+
hasCleaning: appsSet.has("cleaning_services"),
|
|
5515
|
+
hasMechanical: appsSet.has("mechanical_electrical_services"),
|
|
5516
|
+
hasLandscape: appsSet.has("landscaping_services"),
|
|
5517
|
+
hasPestControl: appsSet.has("pest_control_services"),
|
|
5518
|
+
hasPoolMaintenance: appsSet.has("pool_maintenance_services")
|
|
5519
|
+
},
|
|
5520
|
+
filePath: getDirectory(
|
|
5521
|
+
__dirname,
|
|
5522
|
+
"./public/handlebars/user-invite"
|
|
5523
|
+
)
|
|
5524
|
+
});
|
|
5525
|
+
await mailer.sendMail({
|
|
5526
|
+
to: email,
|
|
5527
|
+
subject: "User Invite",
|
|
5528
|
+
html: emailContent,
|
|
5529
|
+
sender: "iService365"
|
|
5530
|
+
});
|
|
5531
|
+
return verificationIds;
|
|
5532
|
+
}
|
|
5533
|
+
async function createSimpleMemberInvite({
|
|
5534
|
+
email,
|
|
5535
|
+
metadata
|
|
5536
|
+
}) {
|
|
5537
|
+
const type = "member-invite";
|
|
5361
5538
|
if (metadata?.org)
|
|
5362
5539
|
await getOrgById(metadata.org);
|
|
5363
5540
|
if (metadata?.siteId)
|
|
@@ -5365,12 +5542,14 @@ function useVerificationService() {
|
|
|
5365
5542
|
const existing = await useVerificationRepo().findOne({
|
|
5366
5543
|
type,
|
|
5367
5544
|
email,
|
|
5368
|
-
"metadata.app": metadata.app
|
|
5545
|
+
"metadata.app": metadata.app,
|
|
5546
|
+
"metadata.org": metadata.org,
|
|
5547
|
+
"metadata.siteId": metadata.siteId
|
|
5369
5548
|
});
|
|
5370
5549
|
if (existing) {
|
|
5371
5550
|
if (existing.status === "complete") {
|
|
5372
5551
|
throw new BadRequestError20(
|
|
5373
|
-
`User already completed invite for app: ${metadata.app}`
|
|
5552
|
+
`User already completed member invite for app: ${metadata.app}`
|
|
5374
5553
|
);
|
|
5375
5554
|
}
|
|
5376
5555
|
return existing._id;
|
|
@@ -5383,18 +5562,18 @@ function useVerificationService() {
|
|
|
5383
5562
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5384
5563
|
};
|
|
5385
5564
|
const res = await add(value);
|
|
5386
|
-
const link = `${APP_MAIN}/verify/
|
|
5565
|
+
const link = `${APP_MAIN}/verify/membership/${res}`;
|
|
5387
5566
|
const emailContent = compileHandlebar({
|
|
5388
5567
|
context: {
|
|
5389
5568
|
email,
|
|
5390
5569
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5391
5570
|
link
|
|
5392
5571
|
},
|
|
5393
|
-
filePath: getDirectory(__dirname, "./public/handlebars/
|
|
5572
|
+
filePath: getDirectory(__dirname, "./public/handlebars/member-invite")
|
|
5394
5573
|
});
|
|
5395
5574
|
await mailer.sendMail({
|
|
5396
5575
|
to: email,
|
|
5397
|
-
subject: "
|
|
5576
|
+
subject: "Member Invite",
|
|
5398
5577
|
html: emailContent,
|
|
5399
5578
|
sender: "iService365"
|
|
5400
5579
|
});
|
|
@@ -5483,6 +5662,72 @@ function useVerificationService() {
|
|
|
5483
5662
|
throw error2;
|
|
5484
5663
|
}
|
|
5485
5664
|
}
|
|
5665
|
+
async function createSimpleServiceProviderInvite({ email, app, name, role, orgId, siteId, siteName }) {
|
|
5666
|
+
const schema2 = Joi11.object({
|
|
5667
|
+
email: Joi11.string().email().lowercase().required(),
|
|
5668
|
+
app: Joi11.string().allow("", null),
|
|
5669
|
+
name: Joi11.string().allow("", null),
|
|
5670
|
+
role: Joi11.string().hex().allow("", null),
|
|
5671
|
+
orgId: Joi11.string().hex().length(24).required(),
|
|
5672
|
+
siteId: Joi11.string().hex().length(24).required(),
|
|
5673
|
+
siteName: Joi11.string().required()
|
|
5674
|
+
});
|
|
5675
|
+
const { error } = schema2.validate({
|
|
5676
|
+
email,
|
|
5677
|
+
app,
|
|
5678
|
+
name,
|
|
5679
|
+
role,
|
|
5680
|
+
orgId,
|
|
5681
|
+
siteId,
|
|
5682
|
+
siteName
|
|
5683
|
+
});
|
|
5684
|
+
if (error) {
|
|
5685
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
5686
|
+
logger14.log({ level: "error", message: messages });
|
|
5687
|
+
throw new BadRequestError20(`Invalid input: ${error.message}`);
|
|
5688
|
+
}
|
|
5689
|
+
const subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
5690
|
+
const type = "service-provider-invite" /* SERVICE_PROVIDER_INVITE */;
|
|
5691
|
+
const value = {
|
|
5692
|
+
type,
|
|
5693
|
+
email,
|
|
5694
|
+
metadata: {
|
|
5695
|
+
app,
|
|
5696
|
+
name,
|
|
5697
|
+
role,
|
|
5698
|
+
org: orgId,
|
|
5699
|
+
siteId,
|
|
5700
|
+
siteName
|
|
5701
|
+
},
|
|
5702
|
+
expireAt: new Date(Date.now() + 72 * 60 * 60 * 1e3).toISOString(),
|
|
5703
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5704
|
+
};
|
|
5705
|
+
try {
|
|
5706
|
+
const id = await _add(value);
|
|
5707
|
+
const filePath = getDirectory(__dirname, `./public/handlebars/${value.type}`);
|
|
5708
|
+
const link = `${APP_MAIN}/verify/${value.type}/${id}`;
|
|
5709
|
+
const emailContent = compileHandlebar({
|
|
5710
|
+
context: {
|
|
5711
|
+
email,
|
|
5712
|
+
app,
|
|
5713
|
+
name,
|
|
5714
|
+
role,
|
|
5715
|
+
siteName,
|
|
5716
|
+
link
|
|
5717
|
+
},
|
|
5718
|
+
filePath
|
|
5719
|
+
});
|
|
5720
|
+
await mailer.sendMail({
|
|
5721
|
+
to: email,
|
|
5722
|
+
subject,
|
|
5723
|
+
html: emailContent,
|
|
5724
|
+
sender: "iService365" /* ISERVICE365 */
|
|
5725
|
+
});
|
|
5726
|
+
return id;
|
|
5727
|
+
} catch (error2) {
|
|
5728
|
+
throw error2;
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5486
5731
|
async function createForgetPassword(email) {
|
|
5487
5732
|
const value = {
|
|
5488
5733
|
type: "forget-password",
|
|
@@ -5694,7 +5939,9 @@ function useVerificationService() {
|
|
|
5694
5939
|
updateStatusById,
|
|
5695
5940
|
signUp,
|
|
5696
5941
|
checkExpiredInvitation,
|
|
5697
|
-
createSimpleUserInvite
|
|
5942
|
+
createSimpleUserInvite,
|
|
5943
|
+
createSimpleMemberInvite,
|
|
5944
|
+
createSimpleServiceProviderInvite
|
|
5698
5945
|
};
|
|
5699
5946
|
}
|
|
5700
5947
|
|
|
@@ -7241,7 +7488,9 @@ function useMemberService() {
|
|
|
7241
7488
|
const {
|
|
7242
7489
|
add: addMember,
|
|
7243
7490
|
updateRoleById: _updateRoleById,
|
|
7244
|
-
getByRoles
|
|
7491
|
+
getByRoles,
|
|
7492
|
+
updateSiteById: _updateSiteById,
|
|
7493
|
+
getAllByUserId: _getAllByUserId
|
|
7245
7494
|
} = useMemberRepo();
|
|
7246
7495
|
const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
|
|
7247
7496
|
const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
|
|
@@ -7377,10 +7626,37 @@ function useMemberService() {
|
|
|
7377
7626
|
throw error;
|
|
7378
7627
|
}
|
|
7379
7628
|
}
|
|
7629
|
+
async function updateSiteById(id, siteId, siteName) {
|
|
7630
|
+
try {
|
|
7631
|
+
await _updateSiteById(
|
|
7632
|
+
id,
|
|
7633
|
+
siteId,
|
|
7634
|
+
siteName
|
|
7635
|
+
);
|
|
7636
|
+
return {
|
|
7637
|
+
message: "Member site updated successfully."
|
|
7638
|
+
};
|
|
7639
|
+
} catch (error) {
|
|
7640
|
+
throw error;
|
|
7641
|
+
}
|
|
7642
|
+
}
|
|
7643
|
+
async function getAllByUser(user) {
|
|
7644
|
+
try {
|
|
7645
|
+
const members = await _getAllByUserId(user);
|
|
7646
|
+
return {
|
|
7647
|
+
items: members,
|
|
7648
|
+
total: members.length
|
|
7649
|
+
};
|
|
7650
|
+
} catch (error) {
|
|
7651
|
+
throw error;
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7380
7654
|
return {
|
|
7381
7655
|
createMember,
|
|
7382
7656
|
createMemberDirect,
|
|
7383
|
-
updateRoleById
|
|
7657
|
+
updateRoleById,
|
|
7658
|
+
updateSiteById,
|
|
7659
|
+
getAllByUser
|
|
7384
7660
|
};
|
|
7385
7661
|
}
|
|
7386
7662
|
|
|
@@ -7392,9 +7668,10 @@ function useMemberController() {
|
|
|
7392
7668
|
getOrgsByMembership: _getOrgsByMembership,
|
|
7393
7669
|
getByUserIdType: _getByUserIdType,
|
|
7394
7670
|
updateMemberStatus: _updateMemberStatus,
|
|
7395
|
-
updateStatusByUserId: _updateStatusByUserId
|
|
7671
|
+
updateStatusByUserId: _updateStatusByUserId,
|
|
7672
|
+
updateSiteById: _updateSiteById
|
|
7396
7673
|
} = useMemberRepo();
|
|
7397
|
-
const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById } = useMemberService();
|
|
7674
|
+
const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById, getAllByUser: _getAllByUser } = useMemberService();
|
|
7398
7675
|
async function createMember(req, res, next) {
|
|
7399
7676
|
const validation = Joi15.string().hex().required();
|
|
7400
7677
|
const _id = req.params.id;
|
|
@@ -7433,6 +7710,31 @@ function useMemberController() {
|
|
|
7433
7710
|
return;
|
|
7434
7711
|
}
|
|
7435
7712
|
}
|
|
7713
|
+
async function getAllByUser(req, res, next) {
|
|
7714
|
+
const validation = Joi15.string().hex().required();
|
|
7715
|
+
const userId = req.params.id;
|
|
7716
|
+
const { error } = validation.validate(userId);
|
|
7717
|
+
if (error) {
|
|
7718
|
+
logger21.log({
|
|
7719
|
+
level: "error",
|
|
7720
|
+
message: error.message
|
|
7721
|
+
});
|
|
7722
|
+
next(new BadRequestError30(error.message));
|
|
7723
|
+
return;
|
|
7724
|
+
}
|
|
7725
|
+
try {
|
|
7726
|
+
const data = await _getAllByUser(userId);
|
|
7727
|
+
res.json(data);
|
|
7728
|
+
return;
|
|
7729
|
+
} catch (error2) {
|
|
7730
|
+
logger21.log({
|
|
7731
|
+
level: "error",
|
|
7732
|
+
message: error2.message
|
|
7733
|
+
});
|
|
7734
|
+
next(error2);
|
|
7735
|
+
return;
|
|
7736
|
+
}
|
|
7737
|
+
}
|
|
7436
7738
|
async function getByUserIdType(req, res, next) {
|
|
7437
7739
|
const validation = Joi15.object({
|
|
7438
7740
|
id: Joi15.string().hex().required(),
|
|
@@ -7609,6 +7911,32 @@ function useMemberController() {
|
|
|
7609
7911
|
return;
|
|
7610
7912
|
}
|
|
7611
7913
|
}
|
|
7914
|
+
async function updateSiteById(req, res, next) {
|
|
7915
|
+
const id = req.body.id?.trim();
|
|
7916
|
+
const siteId = req.body.siteId?.trim();
|
|
7917
|
+
const siteName = req.body.siteName?.trim();
|
|
7918
|
+
const validation = Joi15.object({
|
|
7919
|
+
id: Joi15.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
|
|
7920
|
+
siteId: Joi15.string().pattern(/^[0-9a-fA-F]{24}$/).required(),
|
|
7921
|
+
siteName: Joi15.string().required()
|
|
7922
|
+
});
|
|
7923
|
+
const { error } = validation.validate({
|
|
7924
|
+
id,
|
|
7925
|
+
siteId,
|
|
7926
|
+
siteName
|
|
7927
|
+
});
|
|
7928
|
+
if (error) {
|
|
7929
|
+
return next(new BadRequestError30(error.message));
|
|
7930
|
+
}
|
|
7931
|
+
try {
|
|
7932
|
+
await _updateSiteById(id, siteId, siteName);
|
|
7933
|
+
res.json({
|
|
7934
|
+
message: "Successfully updated member site."
|
|
7935
|
+
});
|
|
7936
|
+
} catch (error2) {
|
|
7937
|
+
next(error2);
|
|
7938
|
+
}
|
|
7939
|
+
}
|
|
7612
7940
|
return {
|
|
7613
7941
|
createMember,
|
|
7614
7942
|
getByUserId,
|
|
@@ -7617,7 +7945,9 @@ function useMemberController() {
|
|
|
7617
7945
|
getOrgsByMembership,
|
|
7618
7946
|
updateMemberStatus,
|
|
7619
7947
|
updateRoleById,
|
|
7620
|
-
createMemberDirect
|
|
7948
|
+
createMemberDirect,
|
|
7949
|
+
updateSiteById,
|
|
7950
|
+
getAllByUser
|
|
7621
7951
|
};
|
|
7622
7952
|
}
|
|
7623
7953
|
|
|
@@ -7628,7 +7958,9 @@ function useVerificationController() {
|
|
|
7628
7958
|
const {
|
|
7629
7959
|
createUserInvite: _createUserInvite,
|
|
7630
7960
|
createSimpleUserInvite: _createSimpleUserInvite,
|
|
7961
|
+
createSimpleMemberInvite: _createSimpleMemberInvite,
|
|
7631
7962
|
createServiceProviderInvite: _createServiceProviderInvite,
|
|
7963
|
+
createSimpleServiceProviderInvite: _createSimpleServiceProviderInvite,
|
|
7632
7964
|
createForgetPassword: _createForgetPassword,
|
|
7633
7965
|
verify: _verify,
|
|
7634
7966
|
updateStatusById: _updateStatusById,
|
|
@@ -7683,7 +8015,7 @@ function useVerificationController() {
|
|
|
7683
8015
|
const payload = { ...req.body };
|
|
7684
8016
|
const validation = Joi16.object({
|
|
7685
8017
|
email: Joi16.string().email().required(),
|
|
7686
|
-
app: Joi16.string().
|
|
8018
|
+
app: Joi16.array().items(Joi16.string()).min(1).required(),
|
|
7687
8019
|
role: Joi16.string().hex().optional().allow("", null),
|
|
7688
8020
|
name: Joi16.string().optional().allow("", null),
|
|
7689
8021
|
org: Joi16.string().hex().optional().allow("", null),
|
|
@@ -7700,7 +8032,7 @@ function useVerificationController() {
|
|
|
7700
8032
|
return;
|
|
7701
8033
|
}
|
|
7702
8034
|
const email = req.body.email ?? "";
|
|
7703
|
-
const app = req.body.app ??
|
|
8035
|
+
const app = req.body.app ?? [];
|
|
7704
8036
|
const role = req.body.role ?? "";
|
|
7705
8037
|
const name = req.body.name ?? "";
|
|
7706
8038
|
const org = req.body.org ?? "";
|
|
@@ -7731,6 +8063,58 @@ function useVerificationController() {
|
|
|
7731
8063
|
return;
|
|
7732
8064
|
}
|
|
7733
8065
|
}
|
|
8066
|
+
async function createSimpleMemberInvite(req, res, next) {
|
|
8067
|
+
const payload = { ...req.body };
|
|
8068
|
+
const validation = Joi16.object({
|
|
8069
|
+
email: Joi16.string().email().required(),
|
|
8070
|
+
app: Joi16.string().optional().allow("", null),
|
|
8071
|
+
role: Joi16.string().hex().optional().allow("", null),
|
|
8072
|
+
name: Joi16.string().optional().allow("", null),
|
|
8073
|
+
org: Joi16.string().hex().optional().allow("", null),
|
|
8074
|
+
siteId: Joi16.string().hex().optional().allow("", null),
|
|
8075
|
+
siteName: Joi16.string().optional().allow("", null)
|
|
8076
|
+
});
|
|
8077
|
+
const { error } = validation.validate(payload);
|
|
8078
|
+
if (error) {
|
|
8079
|
+
logger22.log({
|
|
8080
|
+
level: "error",
|
|
8081
|
+
message: `${error.message}`
|
|
8082
|
+
});
|
|
8083
|
+
next(new BadRequestError31(error.message));
|
|
8084
|
+
return;
|
|
8085
|
+
}
|
|
8086
|
+
const email = req.body.email ?? "";
|
|
8087
|
+
const app = req.body.app ?? "";
|
|
8088
|
+
const role = req.body.role ?? "";
|
|
8089
|
+
const name = req.body.name ?? "";
|
|
8090
|
+
const org = req.body.org ?? "";
|
|
8091
|
+
const siteId = req.body.siteId ?? "";
|
|
8092
|
+
const siteName = req.body.siteName ?? "";
|
|
8093
|
+
try {
|
|
8094
|
+
await _createSimpleMemberInvite({
|
|
8095
|
+
email,
|
|
8096
|
+
metadata: {
|
|
8097
|
+
app,
|
|
8098
|
+
role,
|
|
8099
|
+
name,
|
|
8100
|
+
org,
|
|
8101
|
+
siteId,
|
|
8102
|
+
siteName
|
|
8103
|
+
}
|
|
8104
|
+
});
|
|
8105
|
+
res.status(201).json({
|
|
8106
|
+
message: "Successfully invited member."
|
|
8107
|
+
});
|
|
8108
|
+
return;
|
|
8109
|
+
} catch (error2) {
|
|
8110
|
+
logger22.log({
|
|
8111
|
+
level: "error",
|
|
8112
|
+
message: `${error2.message}`
|
|
8113
|
+
});
|
|
8114
|
+
next(error2);
|
|
8115
|
+
return;
|
|
8116
|
+
}
|
|
8117
|
+
}
|
|
7734
8118
|
async function createServiceProviderInvite(req, res, next) {
|
|
7735
8119
|
const payload = req.body;
|
|
7736
8120
|
const validation = Joi16.object({
|
|
@@ -7760,6 +8144,56 @@ function useVerificationController() {
|
|
|
7760
8144
|
return;
|
|
7761
8145
|
}
|
|
7762
8146
|
}
|
|
8147
|
+
async function createSimpleServiceProviderInvite(req, res, next) {
|
|
8148
|
+
const payload = { ...req.body };
|
|
8149
|
+
const validation = Joi16.object({
|
|
8150
|
+
email: Joi16.string().email().required(),
|
|
8151
|
+
app: Joi16.string().optional().allow("", null),
|
|
8152
|
+
name: Joi16.string().optional().allow("", null),
|
|
8153
|
+
role: Joi16.string().hex().optional().allow("", null),
|
|
8154
|
+
orgId: Joi16.string().hex().required(),
|
|
8155
|
+
siteId: Joi16.string().hex().required(),
|
|
8156
|
+
siteName: Joi16.string().required()
|
|
8157
|
+
});
|
|
8158
|
+
const { error } = validation.validate(payload);
|
|
8159
|
+
if (error) {
|
|
8160
|
+
logger22.log({
|
|
8161
|
+
level: "error",
|
|
8162
|
+
message: `${error.message}`
|
|
8163
|
+
});
|
|
8164
|
+
next(new BadRequestError31(error.message));
|
|
8165
|
+
return;
|
|
8166
|
+
}
|
|
8167
|
+
const email = req.body.email ?? "";
|
|
8168
|
+
const app = req.body.app ?? "";
|
|
8169
|
+
const name = req.body.name ?? "";
|
|
8170
|
+
const role = req.body.role ?? "";
|
|
8171
|
+
const orgId = req.body.orgId ?? "";
|
|
8172
|
+
const siteId = req.body.siteId ?? "";
|
|
8173
|
+
const siteName = req.body.siteName ?? "";
|
|
8174
|
+
try {
|
|
8175
|
+
await _createSimpleServiceProviderInvite({
|
|
8176
|
+
email,
|
|
8177
|
+
app,
|
|
8178
|
+
name,
|
|
8179
|
+
role,
|
|
8180
|
+
orgId,
|
|
8181
|
+
siteId,
|
|
8182
|
+
siteName
|
|
8183
|
+
});
|
|
8184
|
+
res.status(201).json({
|
|
8185
|
+
message: "Successfully invited service provider."
|
|
8186
|
+
});
|
|
8187
|
+
return;
|
|
8188
|
+
} catch (error2) {
|
|
8189
|
+
logger22.log({
|
|
8190
|
+
level: "error",
|
|
8191
|
+
message: `${error2.message}`
|
|
8192
|
+
});
|
|
8193
|
+
next(error2);
|
|
8194
|
+
return;
|
|
8195
|
+
}
|
|
8196
|
+
}
|
|
7763
8197
|
async function createForgetPassword(req, res, next) {
|
|
7764
8198
|
const validation = Joi16.string().email().required();
|
|
7765
8199
|
const email = req.body.email;
|
|
@@ -7892,11 +8326,13 @@ function useVerificationController() {
|
|
|
7892
8326
|
getVerifications,
|
|
7893
8327
|
createUserInvite,
|
|
7894
8328
|
createServiceProviderInvite,
|
|
8329
|
+
createSimpleServiceProviderInvite,
|
|
7895
8330
|
createForgetPassword,
|
|
7896
8331
|
verify,
|
|
7897
8332
|
updateVerificationStatus,
|
|
7898
8333
|
cancelUserInvitation,
|
|
7899
|
-
createSimpleUserInvite
|
|
8334
|
+
createSimpleUserInvite,
|
|
8335
|
+
createSimpleMemberInvite
|
|
7900
8336
|
};
|
|
7901
8337
|
}
|
|
7902
8338
|
|
|
@@ -8065,7 +8501,8 @@ function useOrgController() {
|
|
|
8065
8501
|
getById: _getById,
|
|
8066
8502
|
getByEmail: _getByEmail,
|
|
8067
8503
|
getAll: _getAll,
|
|
8068
|
-
add: _add
|
|
8504
|
+
add: _add,
|
|
8505
|
+
update: _update
|
|
8069
8506
|
} = useOrgRepo();
|
|
8070
8507
|
async function add(req, res, next) {
|
|
8071
8508
|
const validation = Joi18.object({
|
|
@@ -8096,7 +8533,8 @@ function useOrgController() {
|
|
|
8096
8533
|
search: Joi18.string().optional().allow("", null),
|
|
8097
8534
|
page: Joi18.number().integer().min(1).allow("", null).default(1),
|
|
8098
8535
|
limit: Joi18.number().integer().min(1).max(100).allow("", null).default(10),
|
|
8099
|
-
nature: Joi18.string().valid(...allowedNatures).optional().allow("", null)
|
|
8536
|
+
nature: Joi18.string().valid(...allowedNatures).optional().allow("", null),
|
|
8537
|
+
sort: Joi18.string().optional().allow("", null)
|
|
8100
8538
|
});
|
|
8101
8539
|
const query = { ...req.query };
|
|
8102
8540
|
const { error } = validation.validate(query);
|
|
@@ -8248,6 +8686,31 @@ function useOrgController() {
|
|
|
8248
8686
|
return;
|
|
8249
8687
|
}
|
|
8250
8688
|
}
|
|
8689
|
+
async function update(req, res, next) {
|
|
8690
|
+
const validation = Joi18.object({
|
|
8691
|
+
name: Joi18.string().optional(),
|
|
8692
|
+
type: Joi18.string().optional(),
|
|
8693
|
+
nature: Joi18.string().valid(...allowedNatures).optional(),
|
|
8694
|
+
email: Joi18.string().email().allow("", null).optional(),
|
|
8695
|
+
contact: Joi18.string().allow("", null).optional()
|
|
8696
|
+
});
|
|
8697
|
+
const { error } = validation.validate(req.body);
|
|
8698
|
+
if (error) {
|
|
8699
|
+
next(new BadRequestError33(error.message));
|
|
8700
|
+
return;
|
|
8701
|
+
}
|
|
8702
|
+
const id = req.params.id;
|
|
8703
|
+
try {
|
|
8704
|
+
await _update(id, req.body);
|
|
8705
|
+
const data = await _getById(id);
|
|
8706
|
+
res.json({
|
|
8707
|
+
message: "Organization updated successfully",
|
|
8708
|
+
data
|
|
8709
|
+
});
|
|
8710
|
+
} catch (err) {
|
|
8711
|
+
next(err);
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8251
8714
|
return {
|
|
8252
8715
|
add,
|
|
8253
8716
|
addOnboardingOrg,
|
|
@@ -8255,7 +8718,8 @@ function useOrgController() {
|
|
|
8255
8718
|
getOrgsByUserId,
|
|
8256
8719
|
getByName,
|
|
8257
8720
|
getById,
|
|
8258
|
-
getByEmail
|
|
8721
|
+
getByEmail,
|
|
8722
|
+
update
|
|
8259
8723
|
};
|
|
8260
8724
|
}
|
|
8261
8725
|
|
|
@@ -16828,6 +17292,32 @@ function useBuildingUnitRepo() {
|
|
|
16828
17292
|
}
|
|
16829
17293
|
}
|
|
16830
17294
|
}
|
|
17295
|
+
async function bulkAddBuildingUnits(value, session) {
|
|
17296
|
+
try {
|
|
17297
|
+
const operations = value.map((unit) => ({
|
|
17298
|
+
insertOne: {
|
|
17299
|
+
document: unit
|
|
17300
|
+
}
|
|
17301
|
+
}));
|
|
17302
|
+
const res = await collection.bulkWrite(operations, { session });
|
|
17303
|
+
delCachedData();
|
|
17304
|
+
return res;
|
|
17305
|
+
} catch (error) {
|
|
17306
|
+
logger53.log({
|
|
17307
|
+
level: "error",
|
|
17308
|
+
message: error.message
|
|
17309
|
+
});
|
|
17310
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
17311
|
+
if (isDuplicated) {
|
|
17312
|
+
throw new BadRequestError72("Some building units already exist.");
|
|
17313
|
+
}
|
|
17314
|
+
if (error instanceof AppError10) {
|
|
17315
|
+
throw error;
|
|
17316
|
+
} else {
|
|
17317
|
+
throw new Error("Failed to bulk insert building units.");
|
|
17318
|
+
}
|
|
17319
|
+
}
|
|
17320
|
+
}
|
|
16831
17321
|
return {
|
|
16832
17322
|
createIndexes,
|
|
16833
17323
|
add,
|
|
@@ -16843,7 +17333,8 @@ function useBuildingUnitRepo() {
|
|
|
16843
17333
|
getBuildingUnitsForResident,
|
|
16844
17334
|
getBuildingUnitsWithOwner,
|
|
16845
17335
|
getUnitByBlockLevelUnitNumber,
|
|
16846
|
-
getBySiteBuildingLevel
|
|
17336
|
+
getBySiteBuildingLevel,
|
|
17337
|
+
bulkAddBuildingUnits
|
|
16847
17338
|
};
|
|
16848
17339
|
}
|
|
16849
17340
|
|