@goweekdays/core 2.11.14 → 2.11.16
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 +17 -1
- package/dist/index.js +247 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +245 -10
- package/dist/index.mjs.map +1 -1
- package/dist/public/handlebars/org-invite.hbs +46 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -522,6 +522,10 @@ var schemaInviteMember = Joi2.object({
|
|
|
522
522
|
app: Joi2.string().required(),
|
|
523
523
|
org: Joi2.string().hex().optional().allow("", null)
|
|
524
524
|
});
|
|
525
|
+
var schemaVerificationOrgInvite = Joi2.object({
|
|
526
|
+
email: Joi2.string().email().required(),
|
|
527
|
+
pilot: Joi2.boolean().optional()
|
|
528
|
+
});
|
|
525
529
|
var schemaVerification = Joi2.object({
|
|
526
530
|
type: Joi2.string().required(),
|
|
527
531
|
email: Joi2.string().email().required(),
|
|
@@ -536,7 +540,8 @@ var schemaVerification = Joi2.object({
|
|
|
536
540
|
contact: Joi2.string().optional().allow("", null),
|
|
537
541
|
seats: Joi2.number().optional().allow("", null),
|
|
538
542
|
createdBy: Joi2.string().optional().allow("", null),
|
|
539
|
-
amount: Joi2.number().optional().allow("", null)
|
|
543
|
+
amount: Joi2.number().optional().allow("", null),
|
|
544
|
+
pilot: Joi2.boolean().optional().allow("", null)
|
|
540
545
|
}).optional(),
|
|
541
546
|
expireAt: Joi2.date().optional().allow("", null)
|
|
542
547
|
});
|
|
@@ -4417,13 +4422,17 @@ var schema = {
|
|
|
4417
4422
|
name: Joi15.string().max(255).required(),
|
|
4418
4423
|
description: Joi15.string().max(1024).optional().allow("", null),
|
|
4419
4424
|
email: Joi15.string().email().max(255).required(),
|
|
4420
|
-
contact: Joi15.string().max(50).optional().allow("", null)
|
|
4421
|
-
promoCode: Joi15.string().max(50).optional().allow("", null)
|
|
4425
|
+
contact: Joi15.string().max(50).optional().allow("", null)
|
|
4422
4426
|
};
|
|
4423
4427
|
var schemaOrg = Joi15.object({
|
|
4424
4428
|
...schema,
|
|
4425
4429
|
createdBy: Joi15.string().hex().required()
|
|
4426
4430
|
});
|
|
4431
|
+
var schemaOrgPilot = Joi15.object({
|
|
4432
|
+
...schema,
|
|
4433
|
+
createdBy: Joi15.string().hex().required(),
|
|
4434
|
+
verificationCode: Joi15.string().hex().required()
|
|
4435
|
+
});
|
|
4427
4436
|
var schemaOrgAdd = Joi15.object({
|
|
4428
4437
|
...schema,
|
|
4429
4438
|
createdBy: Joi15.string().hex().required()
|
|
@@ -9328,7 +9337,8 @@ function useVerificationController() {
|
|
|
9328
9337
|
signUp: _signUp,
|
|
9329
9338
|
cancelInviteMember: _cancelInviteMember,
|
|
9330
9339
|
forgetPassword: _forgetPassword,
|
|
9331
|
-
orgSetupFee: _orgSetupFee
|
|
9340
|
+
orgSetupFee: _orgSetupFee,
|
|
9341
|
+
inviteOrg: _inviteOrg
|
|
9332
9342
|
} = useVerificationService();
|
|
9333
9343
|
const { getVerifications: _getVerifications } = useVerificationRepo();
|
|
9334
9344
|
async function createUserInvite(req, res, next) {
|
|
@@ -9549,6 +9559,20 @@ function useVerificationController() {
|
|
|
9549
9559
|
next(error2);
|
|
9550
9560
|
}
|
|
9551
9561
|
}
|
|
9562
|
+
async function inviteOrg(req, res, next) {
|
|
9563
|
+
const value = req.body;
|
|
9564
|
+
const { error } = schemaVerificationOrgInvite.validate(value);
|
|
9565
|
+
if (error) {
|
|
9566
|
+
next(new BadRequestError44(error.message));
|
|
9567
|
+
}
|
|
9568
|
+
try {
|
|
9569
|
+
const message = await _inviteOrg(value);
|
|
9570
|
+
res.json({ message });
|
|
9571
|
+
return;
|
|
9572
|
+
} catch (error2) {
|
|
9573
|
+
next(error2);
|
|
9574
|
+
}
|
|
9575
|
+
}
|
|
9552
9576
|
return {
|
|
9553
9577
|
getVerifications,
|
|
9554
9578
|
createUserInvite,
|
|
@@ -9559,7 +9583,8 @@ function useVerificationController() {
|
|
|
9559
9583
|
signUp,
|
|
9560
9584
|
cancelInviteMember,
|
|
9561
9585
|
forgetPassword,
|
|
9562
|
-
orgSetupFee
|
|
9586
|
+
orgSetupFee,
|
|
9587
|
+
inviteOrg
|
|
9563
9588
|
};
|
|
9564
9589
|
}
|
|
9565
9590
|
|
|
@@ -9714,7 +9739,6 @@ function useOrgService() {
|
|
|
9714
9739
|
try {
|
|
9715
9740
|
session?.startTransaction();
|
|
9716
9741
|
const verification = await getById(id);
|
|
9717
|
-
await updateVerificationStatus(id, "complete", session);
|
|
9718
9742
|
if (!verification) {
|
|
9719
9743
|
throw new BadRequestError45("Verification not found.");
|
|
9720
9744
|
}
|
|
@@ -9727,6 +9751,10 @@ function useOrgService() {
|
|
|
9727
9751
|
if (!verification.metadata?.contact) {
|
|
9728
9752
|
throw new BadRequestError45("Contact is required.");
|
|
9729
9753
|
}
|
|
9754
|
+
if (verification.type !== "org-setup-fee") {
|
|
9755
|
+
throw new BadRequestError45("Invalid verification type.");
|
|
9756
|
+
}
|
|
9757
|
+
await updateVerificationStatus(id, "complete", session);
|
|
9730
9758
|
const org = await addOrg(
|
|
9731
9759
|
{
|
|
9732
9760
|
email: verification.email,
|
|
@@ -9828,9 +9856,125 @@ function useOrgService() {
|
|
|
9828
9856
|
await session?.endSession();
|
|
9829
9857
|
}
|
|
9830
9858
|
}
|
|
9859
|
+
async function addPilot(value) {
|
|
9860
|
+
const { error } = schemaOrgPilot.validate(value);
|
|
9861
|
+
if (error) {
|
|
9862
|
+
throw new BadRequestError45(error.message);
|
|
9863
|
+
}
|
|
9864
|
+
const session = useAtlas19.getClient()?.startSession();
|
|
9865
|
+
if (!session) {
|
|
9866
|
+
throw new BadRequestError45("Unable to start database session.");
|
|
9867
|
+
}
|
|
9868
|
+
try {
|
|
9869
|
+
session?.startTransaction();
|
|
9870
|
+
const verification = await getById(value.verificationCode);
|
|
9871
|
+
if (!verification) {
|
|
9872
|
+
throw new BadRequestError45("Verification not found.");
|
|
9873
|
+
}
|
|
9874
|
+
if (verification.type !== "org-invite") {
|
|
9875
|
+
throw new BadRequestError45("Invalid verification type.");
|
|
9876
|
+
}
|
|
9877
|
+
if (verification.metadata && !verification.metadata.pilot) {
|
|
9878
|
+
throw new BadRequestError45("Not a pilot invitation.");
|
|
9879
|
+
}
|
|
9880
|
+
await updateVerificationStatus(
|
|
9881
|
+
value.verificationCode,
|
|
9882
|
+
"complete",
|
|
9883
|
+
session
|
|
9884
|
+
);
|
|
9885
|
+
const org = await addOrg(
|
|
9886
|
+
{
|
|
9887
|
+
email: value.email,
|
|
9888
|
+
name: value.name,
|
|
9889
|
+
contact: value.contact,
|
|
9890
|
+
createdBy: value.createdBy
|
|
9891
|
+
},
|
|
9892
|
+
session
|
|
9893
|
+
);
|
|
9894
|
+
const plan = await getDefault();
|
|
9895
|
+
if (!plan) {
|
|
9896
|
+
throw new BadRequestError45(
|
|
9897
|
+
"Failed to create organization, plan not found."
|
|
9898
|
+
);
|
|
9899
|
+
}
|
|
9900
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
9901
|
+
const nextBillingDate = new Date(currentDate);
|
|
9902
|
+
nextBillingDate.setMonth(currentDate.getMonth() + 1);
|
|
9903
|
+
const createdBy = String(value.createdBy);
|
|
9904
|
+
const user = await getUserById(createdBy);
|
|
9905
|
+
if (!user) {
|
|
9906
|
+
throw new BadRequestError45("User is required to create org member.");
|
|
9907
|
+
}
|
|
9908
|
+
const allPermissions = await getAllPermission({
|
|
9909
|
+
app: "org",
|
|
9910
|
+
limit: 100
|
|
9911
|
+
});
|
|
9912
|
+
let permissions = [];
|
|
9913
|
+
if (allPermissions && allPermissions.items && allPermissions.items.length) {
|
|
9914
|
+
permissions = allPermissions.items.map((perm) => perm.key);
|
|
9915
|
+
}
|
|
9916
|
+
if (permissions.length === 0) {
|
|
9917
|
+
throw new Error("No permissions found for the organization type.");
|
|
9918
|
+
}
|
|
9919
|
+
const roleData = {
|
|
9920
|
+
org: String(org),
|
|
9921
|
+
name: "Owner",
|
|
9922
|
+
description: "Owner of the organization",
|
|
9923
|
+
permissions,
|
|
9924
|
+
createdBy,
|
|
9925
|
+
app: "org"
|
|
9926
|
+
};
|
|
9927
|
+
const role = await addRole(roleData, session);
|
|
9928
|
+
if (!role) {
|
|
9929
|
+
throw new BadRequestError45("Role is required to create org member.");
|
|
9930
|
+
}
|
|
9931
|
+
await addMember(
|
|
9932
|
+
{
|
|
9933
|
+
role: String(role),
|
|
9934
|
+
roleName: roleData.name,
|
|
9935
|
+
org: String(org),
|
|
9936
|
+
orgName: value.name,
|
|
9937
|
+
name: `${user.firstName} ${user.lastName}`,
|
|
9938
|
+
user: createdBy,
|
|
9939
|
+
app: "org"
|
|
9940
|
+
},
|
|
9941
|
+
session
|
|
9942
|
+
);
|
|
9943
|
+
const filePath = getDirectory(
|
|
9944
|
+
__dirname,
|
|
9945
|
+
"./public/handlebars/org-created"
|
|
9946
|
+
);
|
|
9947
|
+
const emailContent = compileHandlebar({
|
|
9948
|
+
context: {
|
|
9949
|
+
app: APP_ORG,
|
|
9950
|
+
organization_name: value.name
|
|
9951
|
+
},
|
|
9952
|
+
filePath
|
|
9953
|
+
});
|
|
9954
|
+
mailer.sendMail({
|
|
9955
|
+
to: verification.email,
|
|
9956
|
+
subject: "Welcome to GoWeekdays - Your Organization is Ready",
|
|
9957
|
+
html: emailContent,
|
|
9958
|
+
from: "GoWeekdays"
|
|
9959
|
+
}).catch((error2) => {
|
|
9960
|
+
logger24.log({
|
|
9961
|
+
level: "error",
|
|
9962
|
+
message: `Error sending user invite email: ${error2}`
|
|
9963
|
+
});
|
|
9964
|
+
});
|
|
9965
|
+
await session?.commitTransaction();
|
|
9966
|
+
return "Successfully created organization with verification.";
|
|
9967
|
+
} catch (error2) {
|
|
9968
|
+
await session?.abortTransaction();
|
|
9969
|
+
throw error2;
|
|
9970
|
+
} finally {
|
|
9971
|
+
await session?.endSession();
|
|
9972
|
+
}
|
|
9973
|
+
}
|
|
9831
9974
|
return {
|
|
9832
9975
|
add,
|
|
9833
|
-
addWithVerification
|
|
9976
|
+
addWithVerification,
|
|
9977
|
+
addPilot
|
|
9834
9978
|
};
|
|
9835
9979
|
}
|
|
9836
9980
|
|
|
@@ -9847,6 +9991,7 @@ function useOrgController() {
|
|
|
9847
9991
|
updateById: _updateById,
|
|
9848
9992
|
companySearch: _companySearch
|
|
9849
9993
|
} = useOrgRepo();
|
|
9994
|
+
const { addPilot: _addPilot } = useOrgService();
|
|
9850
9995
|
async function add(req, res, next) {
|
|
9851
9996
|
const value = req.body;
|
|
9852
9997
|
const { error } = schemaOrgAdd.validate(value);
|
|
@@ -9865,6 +10010,24 @@ function useOrgController() {
|
|
|
9865
10010
|
next(error2);
|
|
9866
10011
|
}
|
|
9867
10012
|
}
|
|
10013
|
+
async function addPilot(req, res, next) {
|
|
10014
|
+
const value = req.body;
|
|
10015
|
+
const { error } = schemaOrgPilot.validate(value);
|
|
10016
|
+
if (error) {
|
|
10017
|
+
next(new BadRequestError46(error.message));
|
|
10018
|
+
return;
|
|
10019
|
+
}
|
|
10020
|
+
try {
|
|
10021
|
+
const data = await _addPilot(value);
|
|
10022
|
+
res.json({
|
|
10023
|
+
message: "Organization created successfully.",
|
|
10024
|
+
data
|
|
10025
|
+
});
|
|
10026
|
+
return;
|
|
10027
|
+
} catch (error2) {
|
|
10028
|
+
next(error2);
|
|
10029
|
+
}
|
|
10030
|
+
}
|
|
9868
10031
|
async function getOrgsByUserId(req, res, next) {
|
|
9869
10032
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
9870
10033
|
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
@@ -10008,7 +10171,8 @@ function useOrgController() {
|
|
|
10008
10171
|
getAll,
|
|
10009
10172
|
getById,
|
|
10010
10173
|
updateById,
|
|
10011
|
-
companySearch
|
|
10174
|
+
companySearch,
|
|
10175
|
+
addPilot
|
|
10012
10176
|
};
|
|
10013
10177
|
}
|
|
10014
10178
|
|
|
@@ -10437,7 +10601,8 @@ function useUserController() {
|
|
|
10437
10601
|
const id = req.params.id || "";
|
|
10438
10602
|
const validation = Joi43.string().hex().validate(id);
|
|
10439
10603
|
if (validation.error) {
|
|
10440
|
-
|
|
10604
|
+
next(new BadRequestError48("Invalid user ID."));
|
|
10605
|
+
return;
|
|
10441
10606
|
}
|
|
10442
10607
|
try {
|
|
10443
10608
|
const user = await _getUserById(id);
|
|
@@ -11169,12 +11334,79 @@ function useVerificationService() {
|
|
|
11169
11334
|
paypalOrderLink: paypalOrderLink ? paypalOrderLink.href : ""
|
|
11170
11335
|
};
|
|
11171
11336
|
} catch (error) {
|
|
11337
|
+
logger26.log({
|
|
11338
|
+
level: "error",
|
|
11339
|
+
message: `Error processing organization setup fee: ${error}`
|
|
11340
|
+
});
|
|
11341
|
+
await session?.abortTransaction();
|
|
11172
11342
|
if (error instanceof AppError24) {
|
|
11173
11343
|
throw error;
|
|
11174
11344
|
}
|
|
11175
11345
|
throw new InternalServerError26(
|
|
11176
11346
|
"Failed to process organization setup fee."
|
|
11177
11347
|
);
|
|
11348
|
+
} finally {
|
|
11349
|
+
session?.endSession();
|
|
11350
|
+
}
|
|
11351
|
+
}
|
|
11352
|
+
async function inviteOrg(value) {
|
|
11353
|
+
const { error } = schemaVerificationOrgInvite.validate(value);
|
|
11354
|
+
if (error) {
|
|
11355
|
+
throw new BadRequestError49(error.message);
|
|
11356
|
+
}
|
|
11357
|
+
const session = useAtlas21.getClient()?.startSession();
|
|
11358
|
+
if (!session) {
|
|
11359
|
+
throw new BadRequestError49("Unable to start database session.");
|
|
11360
|
+
}
|
|
11361
|
+
try {
|
|
11362
|
+
session.startTransaction();
|
|
11363
|
+
const orgExistingByEmail = await getOrgByEmail(value.email);
|
|
11364
|
+
if (orgExistingByEmail) {
|
|
11365
|
+
throw new BadRequestError49(`Email ${value.email} is already taken.`);
|
|
11366
|
+
}
|
|
11367
|
+
const verificationId = await add(
|
|
11368
|
+
{
|
|
11369
|
+
type: "org-invite",
|
|
11370
|
+
email: value.email,
|
|
11371
|
+
metadata: {
|
|
11372
|
+
pilot: value.pilot
|
|
11373
|
+
}
|
|
11374
|
+
},
|
|
11375
|
+
session
|
|
11376
|
+
);
|
|
11377
|
+
const filePath = getDirectory2(
|
|
11378
|
+
__dirname,
|
|
11379
|
+
"./public/handlebars/org-invite"
|
|
11380
|
+
);
|
|
11381
|
+
const emailContent = compileHandlebar2({
|
|
11382
|
+
context: {
|
|
11383
|
+
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
11384
|
+
link: `${APP_ORG}/organizations/create?invite=${verificationId}`
|
|
11385
|
+
},
|
|
11386
|
+
filePath
|
|
11387
|
+
});
|
|
11388
|
+
await mailer.sendMail({
|
|
11389
|
+
to: value.email,
|
|
11390
|
+
subject: value.pilot ? "Pilot Organization Invitation" : "Organization Invitation",
|
|
11391
|
+
html: emailContent,
|
|
11392
|
+
from: "GoWeekdays"
|
|
11393
|
+
});
|
|
11394
|
+
await session?.commitTransaction();
|
|
11395
|
+
return "Successfully created organization invite.";
|
|
11396
|
+
} catch (error2) {
|
|
11397
|
+
logger26.log({
|
|
11398
|
+
level: "error",
|
|
11399
|
+
message: `Error inviting organization: ${error2}`
|
|
11400
|
+
});
|
|
11401
|
+
await session?.abortTransaction();
|
|
11402
|
+
if (error2 instanceof AppError24) {
|
|
11403
|
+
throw error2;
|
|
11404
|
+
}
|
|
11405
|
+
throw new InternalServerError26(
|
|
11406
|
+
"Failed to process organization setup fee."
|
|
11407
|
+
);
|
|
11408
|
+
} finally {
|
|
11409
|
+
session?.endSession();
|
|
11178
11410
|
}
|
|
11179
11411
|
}
|
|
11180
11412
|
return {
|
|
@@ -11189,7 +11421,8 @@ function useVerificationService() {
|
|
|
11189
11421
|
inviteMember,
|
|
11190
11422
|
cancelInviteMember,
|
|
11191
11423
|
forgetPassword,
|
|
11192
|
-
orgSetupFee
|
|
11424
|
+
orgSetupFee,
|
|
11425
|
+
inviteOrg
|
|
11193
11426
|
};
|
|
11194
11427
|
}
|
|
11195
11428
|
|
|
@@ -13749,6 +13982,7 @@ export {
|
|
|
13749
13982
|
schemaMemberStatus,
|
|
13750
13983
|
schemaOrg,
|
|
13751
13984
|
schemaOrgAdd,
|
|
13985
|
+
schemaOrgPilot,
|
|
13752
13986
|
schemaOrgUpdate,
|
|
13753
13987
|
schemaPermission,
|
|
13754
13988
|
schemaPermissionGroup,
|
|
@@ -13768,6 +14002,7 @@ export {
|
|
|
13768
14002
|
schemaUpdateOptions,
|
|
13769
14003
|
schemaUser,
|
|
13770
14004
|
schemaVerification,
|
|
14005
|
+
schemaVerificationOrgInvite,
|
|
13771
14006
|
transactionSchema,
|
|
13772
14007
|
useAppController,
|
|
13773
14008
|
useAppRepo,
|