@7365admin1/core 2.50.0 → 2.51.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 +2 -0
- package/dist/index.js +98 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -337,6 +337,7 @@ declare function useMemberController(): {
|
|
|
337
337
|
getOrgsByMembership: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
338
338
|
updateMemberStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
339
339
|
updateRoleById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
340
|
+
createMemberDirect: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
340
341
|
};
|
|
341
342
|
|
|
342
343
|
type TVerificationMetadata = {
|
|
@@ -390,6 +391,7 @@ declare function useVerificationRepo(): {
|
|
|
390
391
|
getByIdByType: (type: string) => Promise<TVerification[]>;
|
|
391
392
|
updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
392
393
|
getByStatus: (status: string) => Promise<TVerification[]>;
|
|
394
|
+
findOne: (query: any) => Promise<mongodb.WithId<bson.Document> | null>;
|
|
393
395
|
};
|
|
394
396
|
|
|
395
397
|
type TKeyValuePair<K extends string | number | symbol = string, V = any> = {
|
package/dist/index.js
CHANGED
|
@@ -4333,6 +4333,9 @@ function useVerificationRepo() {
|
|
|
4333
4333
|
return Promise.reject(error);
|
|
4334
4334
|
}
|
|
4335
4335
|
}
|
|
4336
|
+
async function findOne(query) {
|
|
4337
|
+
return await collection.findOne(query);
|
|
4338
|
+
}
|
|
4336
4339
|
return {
|
|
4337
4340
|
createIndex,
|
|
4338
4341
|
createTextIndex,
|
|
@@ -4341,7 +4344,8 @@ function useVerificationRepo() {
|
|
|
4341
4344
|
getVerifications,
|
|
4342
4345
|
getByIdByType,
|
|
4343
4346
|
updateStatusById,
|
|
4344
|
-
getByStatus
|
|
4347
|
+
getByStatus,
|
|
4348
|
+
findOne
|
|
4345
4349
|
};
|
|
4346
4350
|
}
|
|
4347
4351
|
|
|
@@ -5645,29 +5649,28 @@ function useVerificationService() {
|
|
|
5645
5649
|
throw error;
|
|
5646
5650
|
}
|
|
5647
5651
|
}
|
|
5648
|
-
async function createSimpleUserInvite({
|
|
5649
|
-
email,
|
|
5650
|
-
metadata
|
|
5651
|
-
}) {
|
|
5652
|
+
async function createSimpleUserInvite({ email, metadata }) {
|
|
5652
5653
|
const type = "user-invite";
|
|
5654
|
+
if (metadata?.org)
|
|
5655
|
+
await getOrgById(metadata.org);
|
|
5656
|
+
if (metadata?.siteId)
|
|
5657
|
+
await getSiteById(metadata.siteId);
|
|
5658
|
+
const existing = await useVerificationRepo().findOne({
|
|
5659
|
+
type,
|
|
5660
|
+
email,
|
|
5661
|
+
"metadata.org": metadata?.org,
|
|
5662
|
+
"metadata.siteId": metadata?.siteId
|
|
5663
|
+
});
|
|
5664
|
+
if (existing)
|
|
5665
|
+
return existing._id;
|
|
5653
5666
|
const value = {
|
|
5654
5667
|
type,
|
|
5655
5668
|
email,
|
|
5656
5669
|
metadata,
|
|
5657
|
-
expireAt: new Date(
|
|
5658
|
-
(/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
|
|
5659
|
-
).toISOString(),
|
|
5670
|
+
expireAt: new Date(Date.now() + 72 * 60 * 60 * 1e3).toISOString(),
|
|
5660
5671
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5661
5672
|
};
|
|
5662
|
-
if (value.metadata?.org) {
|
|
5663
|
-
await getOrgById(value.metadata?.org);
|
|
5664
|
-
}
|
|
5665
|
-
if (value.metadata?.siteId) {
|
|
5666
|
-
await getSiteById(value.metadata?.siteId);
|
|
5667
|
-
}
|
|
5668
5673
|
const res = await add(value);
|
|
5669
|
-
const dir = __dirname;
|
|
5670
|
-
const filePath = (0, import_node_server_utils21.getDirectory)(dir, "./public/handlebars/user-invite");
|
|
5671
5674
|
const link = `${APP_MAIN}/verify/invitation/${res}`;
|
|
5672
5675
|
const emailContent = (0, import_node_server_utils21.compileHandlebar)({
|
|
5673
5676
|
context: {
|
|
@@ -5675,9 +5678,9 @@ function useVerificationService() {
|
|
|
5675
5678
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5676
5679
|
link
|
|
5677
5680
|
},
|
|
5678
|
-
filePath
|
|
5681
|
+
filePath: (0, import_node_server_utils21.getDirectory)(__dirname, "./public/handlebars/user-invite")
|
|
5679
5682
|
});
|
|
5680
|
-
mailer.sendMail({
|
|
5683
|
+
await mailer.sendMail({
|
|
5681
5684
|
to: email,
|
|
5682
5685
|
subject: "User Invite",
|
|
5683
5686
|
html: emailContent,
|
|
@@ -7504,7 +7507,7 @@ function useMemberService() {
|
|
|
7504
7507
|
getByRoles
|
|
7505
7508
|
} = useMemberRepo();
|
|
7506
7509
|
const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
|
|
7507
|
-
const { getUserByEmail, updateDefaultOrgByEmail } = useUserRepo();
|
|
7510
|
+
const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
|
|
7508
7511
|
const { getById: getOrgById } = useOrgRepo();
|
|
7509
7512
|
const { getSiteById } = useSiteRepo();
|
|
7510
7513
|
const { getOwnerRolesByTypeOrg } = useRoleRepo();
|
|
@@ -7566,6 +7569,52 @@ function useMemberService() {
|
|
|
7566
7569
|
session?.endSession();
|
|
7567
7570
|
}
|
|
7568
7571
|
}
|
|
7572
|
+
async function createMemberDirect({
|
|
7573
|
+
userId,
|
|
7574
|
+
orgId,
|
|
7575
|
+
roleId,
|
|
7576
|
+
app,
|
|
7577
|
+
siteId,
|
|
7578
|
+
siteName
|
|
7579
|
+
}) {
|
|
7580
|
+
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
7581
|
+
session?.startTransaction();
|
|
7582
|
+
try {
|
|
7583
|
+
const org = await getOrgById(orgId);
|
|
7584
|
+
if (!org)
|
|
7585
|
+
throw new import_node_server_utils30.BadRequestError("Organization not found.");
|
|
7586
|
+
const user = await getUserById(userId);
|
|
7587
|
+
if (!user)
|
|
7588
|
+
throw new import_node_server_utils30.BadRequestError("User not found.");
|
|
7589
|
+
const member = await addMember(
|
|
7590
|
+
{
|
|
7591
|
+
org: org._id?.toString() || "",
|
|
7592
|
+
orgName: org.name || "",
|
|
7593
|
+
user: user._id?.toString() || "",
|
|
7594
|
+
name: user?.email,
|
|
7595
|
+
role: roleId,
|
|
7596
|
+
type: app,
|
|
7597
|
+
siteId: siteId ?? "",
|
|
7598
|
+
siteName: siteName ?? ""
|
|
7599
|
+
},
|
|
7600
|
+
session
|
|
7601
|
+
);
|
|
7602
|
+
if (!user.defaultOrg) {
|
|
7603
|
+
await updateDefaultOrgByEmail(
|
|
7604
|
+
user.email,
|
|
7605
|
+
org._id?.toString() || "",
|
|
7606
|
+
session
|
|
7607
|
+
);
|
|
7608
|
+
}
|
|
7609
|
+
await session?.commitTransaction();
|
|
7610
|
+
return { member };
|
|
7611
|
+
} catch (error) {
|
|
7612
|
+
await session?.abortTransaction();
|
|
7613
|
+
throw error;
|
|
7614
|
+
} finally {
|
|
7615
|
+
session?.endSession();
|
|
7616
|
+
}
|
|
7617
|
+
}
|
|
7569
7618
|
async function updateRoleById(id, role, type, org) {
|
|
7570
7619
|
const owner = await getOwnerRolesByTypeOrg(type, org);
|
|
7571
7620
|
if (!owner.length) {
|
|
@@ -7593,6 +7642,7 @@ function useMemberService() {
|
|
|
7593
7642
|
}
|
|
7594
7643
|
return {
|
|
7595
7644
|
createMember,
|
|
7645
|
+
createMemberDirect,
|
|
7596
7646
|
updateRoleById
|
|
7597
7647
|
};
|
|
7598
7648
|
}
|
|
@@ -7607,7 +7657,7 @@ function useMemberController() {
|
|
|
7607
7657
|
updateMemberStatus: _updateMemberStatus,
|
|
7608
7658
|
updateStatusByUserId: _updateStatusByUserId
|
|
7609
7659
|
} = useMemberRepo();
|
|
7610
|
-
const { createMember: _createMember, updateRoleById: _updateRoleById } = useMemberService();
|
|
7660
|
+
const { createMember: _createMember, createMemberDirect: _createMemberDirect, updateRoleById: _updateRoleById } = useMemberService();
|
|
7611
7661
|
async function createMember(req, res, next) {
|
|
7612
7662
|
const validation = import_joi15.default.string().hex().required();
|
|
7613
7663
|
const _id = req.params.id;
|
|
@@ -7796,6 +7846,32 @@ function useMemberController() {
|
|
|
7796
7846
|
return;
|
|
7797
7847
|
}
|
|
7798
7848
|
}
|
|
7849
|
+
async function createMemberDirect(req, res, next) {
|
|
7850
|
+
const validation = import_joi15.default.object({
|
|
7851
|
+
userId: import_joi15.default.string().hex().required(),
|
|
7852
|
+
orgId: import_joi15.default.string().hex().required(),
|
|
7853
|
+
roleId: import_joi15.default.string().hex().required(),
|
|
7854
|
+
app: import_joi15.default.string().required(),
|
|
7855
|
+
siteId: import_joi15.default.string().hex().optional().allow("", null),
|
|
7856
|
+
siteName: import_joi15.default.string().optional().allow("", null)
|
|
7857
|
+
});
|
|
7858
|
+
const { error } = validation.validate(req.body);
|
|
7859
|
+
if (error) {
|
|
7860
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
7861
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
7862
|
+
return;
|
|
7863
|
+
}
|
|
7864
|
+
const { userId, orgId, roleId, app, siteId, siteName } = req.body;
|
|
7865
|
+
try {
|
|
7866
|
+
const data = await _createMemberDirect({ userId, orgId, roleId, app, siteId, siteName });
|
|
7867
|
+
res.status(201).json(data);
|
|
7868
|
+
return;
|
|
7869
|
+
} catch (error2) {
|
|
7870
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
7871
|
+
next(error2);
|
|
7872
|
+
return;
|
|
7873
|
+
}
|
|
7874
|
+
}
|
|
7799
7875
|
return {
|
|
7800
7876
|
createMember,
|
|
7801
7877
|
getByUserId,
|
|
@@ -7803,7 +7879,8 @@ function useMemberController() {
|
|
|
7803
7879
|
getAll,
|
|
7804
7880
|
getOrgsByMembership,
|
|
7805
7881
|
updateMemberStatus,
|
|
7806
|
-
updateRoleById
|
|
7882
|
+
updateRoleById,
|
|
7883
|
+
createMemberDirect
|
|
7807
7884
|
};
|
|
7808
7885
|
}
|
|
7809
7886
|
|