@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @goweekdays/core
|
|
2
2
|
|
|
3
|
+
## 2.11.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c764e95: Add pilot org invite flow and email template
|
|
8
|
+
|
|
9
|
+
## 2.11.15
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- dfa139d: Remove section comments from subscription.service.ts
|
|
14
|
+
|
|
3
15
|
## 2.11.14
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -374,6 +374,7 @@ type TOrg = {
|
|
|
374
374
|
deletedAt?: string | Date;
|
|
375
375
|
};
|
|
376
376
|
declare const schemaOrg: Joi.ObjectSchema<any>;
|
|
377
|
+
declare const schemaOrgPilot: Joi.ObjectSchema<any>;
|
|
377
378
|
declare const schemaOrgAdd: Joi.ObjectSchema<any>;
|
|
378
379
|
declare const schemaOrgUpdate: Joi.ObjectSchema<any>;
|
|
379
380
|
declare function modelOrg(value: TOrg): TOrg;
|
|
@@ -410,6 +411,13 @@ declare function useOrgService(): {
|
|
|
410
411
|
paypalOrderLink: any;
|
|
411
412
|
}>;
|
|
412
413
|
addWithVerification: (id: string) => Promise<string>;
|
|
414
|
+
addPilot: (value: {
|
|
415
|
+
email: string;
|
|
416
|
+
name: string;
|
|
417
|
+
contact: string;
|
|
418
|
+
createdBy: string;
|
|
419
|
+
verificationCode: string;
|
|
420
|
+
}) => Promise<string>;
|
|
413
421
|
};
|
|
414
422
|
|
|
415
423
|
declare function useOrgController(): {
|
|
@@ -420,6 +428,7 @@ declare function useOrgController(): {
|
|
|
420
428
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
421
429
|
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
422
430
|
companySearch: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
431
|
+
addPilot: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
423
432
|
};
|
|
424
433
|
|
|
425
434
|
type TPromo = {
|
|
@@ -722,6 +731,7 @@ type TVerificationMetadata = {
|
|
|
722
731
|
seats?: number;
|
|
723
732
|
createdBy?: string | ObjectId;
|
|
724
733
|
amount?: number;
|
|
734
|
+
pilot?: boolean;
|
|
725
735
|
};
|
|
726
736
|
type TVerification = {
|
|
727
737
|
_id?: ObjectId;
|
|
@@ -734,6 +744,7 @@ type TVerification = {
|
|
|
734
744
|
expireAt?: string | Date;
|
|
735
745
|
};
|
|
736
746
|
declare const schemaInviteMember: Joi.ObjectSchema<any>;
|
|
747
|
+
declare const schemaVerificationOrgInvite: Joi.ObjectSchema<any>;
|
|
737
748
|
declare const schemaVerification: Joi.ObjectSchema<any>;
|
|
738
749
|
declare function modelVerification(value: TVerification): TVerification;
|
|
739
750
|
|
|
@@ -798,6 +809,10 @@ declare function useVerificationService(): {
|
|
|
798
809
|
orgSetupFee: (value: TOrg) => Promise<{
|
|
799
810
|
paypalOrderLink: any;
|
|
800
811
|
}>;
|
|
812
|
+
inviteOrg: (value: {
|
|
813
|
+
email: string;
|
|
814
|
+
pilot?: boolean;
|
|
815
|
+
}) => Promise<string>;
|
|
801
816
|
};
|
|
802
817
|
|
|
803
818
|
declare function useVerificationController(): {
|
|
@@ -811,6 +826,7 @@ declare function useVerificationController(): {
|
|
|
811
826
|
cancelInviteMember: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
812
827
|
forgetPassword: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
813
828
|
orgSetupFee: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
829
|
+
inviteOrg: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
814
830
|
};
|
|
815
831
|
|
|
816
832
|
type TPlan = {
|
|
@@ -1298,4 +1314,4 @@ declare const XENDIT_BASE_URL: string;
|
|
|
1298
1314
|
declare const DOMAIN: string;
|
|
1299
1315
|
declare const APP_ORG: string;
|
|
1300
1316
|
|
|
1301
|
-
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, PaypalWebhookHeaders, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscribe, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobPost, schemaJobPostUpdate, schemaLedgerBill, schemaLedgerBillingSummary, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscribe, schemaSubscription, schemaSubscriptionCompute, schemaSubscriptionPromoCode, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaypalService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoController, usePromoRepo, usePromoUsageRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
|
1317
|
+
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, APP_ORG, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MBuilding, MBuildingUnit, MFile, MONGO_DB, MONGO_URI, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PAYPAL_WEBHOOK_ID, PORT, PaypalWebhookHeaders, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TApp, TBuilding, TBuildingUnit, TCounter, TFile, TJobPost, TLedgerBill, TMember, TOrg, TPermission, TPermissionGroup, TPlan, TPromo, TRole, TSubscribe, TSubscription, TSubscriptionTransaction, TUser, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, currencies, isDev, ledgerBillStatuses, ledgerBillTypes, modelApp, modelJobPost, modelLedgerBill, modelMember, modelOrg, modelPermission, modelPermissionGroup, modelPlan, modelPromo, modelRole, modelSubscription, modelSubscriptionTransaction, modelUser, modelVerification, schemaApp, schemaAppUpdate, schemaBuilding, schemaBuildingUnit, schemaInviteMember, schemaJobPost, schemaJobPostUpdate, schemaLedgerBill, schemaLedgerBillingSummary, schemaMember, schemaMemberRole, schemaMemberStatus, schemaOrg, schemaOrgAdd, schemaOrgPilot, schemaOrgUpdate, schemaPermission, schemaPermissionGroup, schemaPermissionGroupUpdate, schemaPermissionUpdate, schemaPlan, schemaPromo, schemaRole, schemaRoleUpdate, schemaSubscribe, schemaSubscription, schemaSubscriptionCompute, schemaSubscriptionPromoCode, schemaSubscriptionSeats, schemaSubscriptionTransaction, schemaSubscriptionUpdate, schemaUpdateOptions, schemaUser, schemaVerification, schemaVerificationOrgInvite, transactionSchema, useAppController, useAppRepo, useAppService, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGitHubService, useJobPostController, useJobPostRepo, useJobPostService, useLedgerBillingController, useLedgerBillingRepo, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePaypalService, usePermissionController, usePermissionGroupController, usePermissionGroupRepo, usePermissionGroupService, usePermissionRepo, usePermissionService, usePlanController, usePlanRepo, usePlanService, usePromoController, usePromoRepo, usePromoUsageRepo, useRoleController, useRoleRepo, useRoleService, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useSubscriptionTransactionController, useSubscriptionTransactionRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
|
package/dist/index.js
CHANGED
|
@@ -102,6 +102,7 @@ __export(src_exports, {
|
|
|
102
102
|
schemaMemberStatus: () => schemaMemberStatus,
|
|
103
103
|
schemaOrg: () => schemaOrg,
|
|
104
104
|
schemaOrgAdd: () => schemaOrgAdd,
|
|
105
|
+
schemaOrgPilot: () => schemaOrgPilot,
|
|
105
106
|
schemaOrgUpdate: () => schemaOrgUpdate,
|
|
106
107
|
schemaPermission: () => schemaPermission,
|
|
107
108
|
schemaPermissionGroup: () => schemaPermissionGroup,
|
|
@@ -121,6 +122,7 @@ __export(src_exports, {
|
|
|
121
122
|
schemaUpdateOptions: () => schemaUpdateOptions,
|
|
122
123
|
schemaUser: () => schemaUser,
|
|
123
124
|
schemaVerification: () => schemaVerification,
|
|
125
|
+
schemaVerificationOrgInvite: () => schemaVerificationOrgInvite,
|
|
124
126
|
transactionSchema: () => transactionSchema,
|
|
125
127
|
useAppController: () => useAppController,
|
|
126
128
|
useAppRepo: () => useAppRepo,
|
|
@@ -674,6 +676,10 @@ var schemaInviteMember = import_joi2.default.object({
|
|
|
674
676
|
app: import_joi2.default.string().required(),
|
|
675
677
|
org: import_joi2.default.string().hex().optional().allow("", null)
|
|
676
678
|
});
|
|
679
|
+
var schemaVerificationOrgInvite = import_joi2.default.object({
|
|
680
|
+
email: import_joi2.default.string().email().required(),
|
|
681
|
+
pilot: import_joi2.default.boolean().optional()
|
|
682
|
+
});
|
|
677
683
|
var schemaVerification = import_joi2.default.object({
|
|
678
684
|
type: import_joi2.default.string().required(),
|
|
679
685
|
email: import_joi2.default.string().email().required(),
|
|
@@ -688,7 +694,8 @@ var schemaVerification = import_joi2.default.object({
|
|
|
688
694
|
contact: import_joi2.default.string().optional().allow("", null),
|
|
689
695
|
seats: import_joi2.default.number().optional().allow("", null),
|
|
690
696
|
createdBy: import_joi2.default.string().optional().allow("", null),
|
|
691
|
-
amount: import_joi2.default.number().optional().allow("", null)
|
|
697
|
+
amount: import_joi2.default.number().optional().allow("", null),
|
|
698
|
+
pilot: import_joi2.default.boolean().optional().allow("", null)
|
|
692
699
|
}).optional(),
|
|
693
700
|
expireAt: import_joi2.default.date().optional().allow("", null)
|
|
694
701
|
});
|
|
@@ -4492,13 +4499,17 @@ var schema = {
|
|
|
4492
4499
|
name: import_joi15.default.string().max(255).required(),
|
|
4493
4500
|
description: import_joi15.default.string().max(1024).optional().allow("", null),
|
|
4494
4501
|
email: import_joi15.default.string().email().max(255).required(),
|
|
4495
|
-
contact: import_joi15.default.string().max(50).optional().allow("", null)
|
|
4496
|
-
promoCode: import_joi15.default.string().max(50).optional().allow("", null)
|
|
4502
|
+
contact: import_joi15.default.string().max(50).optional().allow("", null)
|
|
4497
4503
|
};
|
|
4498
4504
|
var schemaOrg = import_joi15.default.object({
|
|
4499
4505
|
...schema,
|
|
4500
4506
|
createdBy: import_joi15.default.string().hex().required()
|
|
4501
4507
|
});
|
|
4508
|
+
var schemaOrgPilot = import_joi15.default.object({
|
|
4509
|
+
...schema,
|
|
4510
|
+
createdBy: import_joi15.default.string().hex().required(),
|
|
4511
|
+
verificationCode: import_joi15.default.string().hex().required()
|
|
4512
|
+
});
|
|
4502
4513
|
var schemaOrgAdd = import_joi15.default.object({
|
|
4503
4514
|
...schema,
|
|
4504
4515
|
createdBy: import_joi15.default.string().hex().required()
|
|
@@ -9305,7 +9316,8 @@ function useVerificationController() {
|
|
|
9305
9316
|
signUp: _signUp,
|
|
9306
9317
|
cancelInviteMember: _cancelInviteMember,
|
|
9307
9318
|
forgetPassword: _forgetPassword,
|
|
9308
|
-
orgSetupFee: _orgSetupFee
|
|
9319
|
+
orgSetupFee: _orgSetupFee,
|
|
9320
|
+
inviteOrg: _inviteOrg
|
|
9309
9321
|
} = useVerificationService();
|
|
9310
9322
|
const { getVerifications: _getVerifications } = useVerificationRepo();
|
|
9311
9323
|
async function createUserInvite(req, res, next) {
|
|
@@ -9526,6 +9538,20 @@ function useVerificationController() {
|
|
|
9526
9538
|
next(error2);
|
|
9527
9539
|
}
|
|
9528
9540
|
}
|
|
9541
|
+
async function inviteOrg(req, res, next) {
|
|
9542
|
+
const value = req.body;
|
|
9543
|
+
const { error } = schemaVerificationOrgInvite.validate(value);
|
|
9544
|
+
if (error) {
|
|
9545
|
+
next(new import_utils48.BadRequestError(error.message));
|
|
9546
|
+
}
|
|
9547
|
+
try {
|
|
9548
|
+
const message = await _inviteOrg(value);
|
|
9549
|
+
res.json({ message });
|
|
9550
|
+
return;
|
|
9551
|
+
} catch (error2) {
|
|
9552
|
+
next(error2);
|
|
9553
|
+
}
|
|
9554
|
+
}
|
|
9529
9555
|
return {
|
|
9530
9556
|
getVerifications,
|
|
9531
9557
|
createUserInvite,
|
|
@@ -9536,7 +9562,8 @@ function useVerificationController() {
|
|
|
9536
9562
|
signUp,
|
|
9537
9563
|
cancelInviteMember,
|
|
9538
9564
|
forgetPassword,
|
|
9539
|
-
orgSetupFee
|
|
9565
|
+
orgSetupFee,
|
|
9566
|
+
inviteOrg
|
|
9540
9567
|
};
|
|
9541
9568
|
}
|
|
9542
9569
|
|
|
@@ -9691,7 +9718,6 @@ function useOrgService() {
|
|
|
9691
9718
|
try {
|
|
9692
9719
|
session?.startTransaction();
|
|
9693
9720
|
const verification = await getById(id);
|
|
9694
|
-
await updateVerificationStatus(id, "complete", session);
|
|
9695
9721
|
if (!verification) {
|
|
9696
9722
|
throw new import_utils49.BadRequestError("Verification not found.");
|
|
9697
9723
|
}
|
|
@@ -9704,6 +9730,10 @@ function useOrgService() {
|
|
|
9704
9730
|
if (!verification.metadata?.contact) {
|
|
9705
9731
|
throw new import_utils49.BadRequestError("Contact is required.");
|
|
9706
9732
|
}
|
|
9733
|
+
if (verification.type !== "org-setup-fee") {
|
|
9734
|
+
throw new import_utils49.BadRequestError("Invalid verification type.");
|
|
9735
|
+
}
|
|
9736
|
+
await updateVerificationStatus(id, "complete", session);
|
|
9707
9737
|
const org = await addOrg(
|
|
9708
9738
|
{
|
|
9709
9739
|
email: verification.email,
|
|
@@ -9805,9 +9835,125 @@ function useOrgService() {
|
|
|
9805
9835
|
await session?.endSession();
|
|
9806
9836
|
}
|
|
9807
9837
|
}
|
|
9838
|
+
async function addPilot(value) {
|
|
9839
|
+
const { error } = schemaOrgPilot.validate(value);
|
|
9840
|
+
if (error) {
|
|
9841
|
+
throw new import_utils49.BadRequestError(error.message);
|
|
9842
|
+
}
|
|
9843
|
+
const session = import_utils49.useAtlas.getClient()?.startSession();
|
|
9844
|
+
if (!session) {
|
|
9845
|
+
throw new import_utils49.BadRequestError("Unable to start database session.");
|
|
9846
|
+
}
|
|
9847
|
+
try {
|
|
9848
|
+
session?.startTransaction();
|
|
9849
|
+
const verification = await getById(value.verificationCode);
|
|
9850
|
+
if (!verification) {
|
|
9851
|
+
throw new import_utils49.BadRequestError("Verification not found.");
|
|
9852
|
+
}
|
|
9853
|
+
if (verification.type !== "org-invite") {
|
|
9854
|
+
throw new import_utils49.BadRequestError("Invalid verification type.");
|
|
9855
|
+
}
|
|
9856
|
+
if (verification.metadata && !verification.metadata.pilot) {
|
|
9857
|
+
throw new import_utils49.BadRequestError("Not a pilot invitation.");
|
|
9858
|
+
}
|
|
9859
|
+
await updateVerificationStatus(
|
|
9860
|
+
value.verificationCode,
|
|
9861
|
+
"complete",
|
|
9862
|
+
session
|
|
9863
|
+
);
|
|
9864
|
+
const org = await addOrg(
|
|
9865
|
+
{
|
|
9866
|
+
email: value.email,
|
|
9867
|
+
name: value.name,
|
|
9868
|
+
contact: value.contact,
|
|
9869
|
+
createdBy: value.createdBy
|
|
9870
|
+
},
|
|
9871
|
+
session
|
|
9872
|
+
);
|
|
9873
|
+
const plan = await getDefault();
|
|
9874
|
+
if (!plan) {
|
|
9875
|
+
throw new import_utils49.BadRequestError(
|
|
9876
|
+
"Failed to create organization, plan not found."
|
|
9877
|
+
);
|
|
9878
|
+
}
|
|
9879
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
9880
|
+
const nextBillingDate = new Date(currentDate);
|
|
9881
|
+
nextBillingDate.setMonth(currentDate.getMonth() + 1);
|
|
9882
|
+
const createdBy = String(value.createdBy);
|
|
9883
|
+
const user = await getUserById(createdBy);
|
|
9884
|
+
if (!user) {
|
|
9885
|
+
throw new import_utils49.BadRequestError("User is required to create org member.");
|
|
9886
|
+
}
|
|
9887
|
+
const allPermissions = await getAllPermission({
|
|
9888
|
+
app: "org",
|
|
9889
|
+
limit: 100
|
|
9890
|
+
});
|
|
9891
|
+
let permissions = [];
|
|
9892
|
+
if (allPermissions && allPermissions.items && allPermissions.items.length) {
|
|
9893
|
+
permissions = allPermissions.items.map((perm) => perm.key);
|
|
9894
|
+
}
|
|
9895
|
+
if (permissions.length === 0) {
|
|
9896
|
+
throw new Error("No permissions found for the organization type.");
|
|
9897
|
+
}
|
|
9898
|
+
const roleData = {
|
|
9899
|
+
org: String(org),
|
|
9900
|
+
name: "Owner",
|
|
9901
|
+
description: "Owner of the organization",
|
|
9902
|
+
permissions,
|
|
9903
|
+
createdBy,
|
|
9904
|
+
app: "org"
|
|
9905
|
+
};
|
|
9906
|
+
const role = await addRole(roleData, session);
|
|
9907
|
+
if (!role) {
|
|
9908
|
+
throw new import_utils49.BadRequestError("Role is required to create org member.");
|
|
9909
|
+
}
|
|
9910
|
+
await addMember(
|
|
9911
|
+
{
|
|
9912
|
+
role: String(role),
|
|
9913
|
+
roleName: roleData.name,
|
|
9914
|
+
org: String(org),
|
|
9915
|
+
orgName: value.name,
|
|
9916
|
+
name: `${user.firstName} ${user.lastName}`,
|
|
9917
|
+
user: createdBy,
|
|
9918
|
+
app: "org"
|
|
9919
|
+
},
|
|
9920
|
+
session
|
|
9921
|
+
);
|
|
9922
|
+
const filePath = (0, import_utils49.getDirectory)(
|
|
9923
|
+
__dirname,
|
|
9924
|
+
"./public/handlebars/org-created"
|
|
9925
|
+
);
|
|
9926
|
+
const emailContent = (0, import_utils49.compileHandlebar)({
|
|
9927
|
+
context: {
|
|
9928
|
+
app: APP_ORG,
|
|
9929
|
+
organization_name: value.name
|
|
9930
|
+
},
|
|
9931
|
+
filePath
|
|
9932
|
+
});
|
|
9933
|
+
mailer.sendMail({
|
|
9934
|
+
to: verification.email,
|
|
9935
|
+
subject: "Welcome to GoWeekdays - Your Organization is Ready",
|
|
9936
|
+
html: emailContent,
|
|
9937
|
+
from: "GoWeekdays"
|
|
9938
|
+
}).catch((error2) => {
|
|
9939
|
+
import_utils49.logger.log({
|
|
9940
|
+
level: "error",
|
|
9941
|
+
message: `Error sending user invite email: ${error2}`
|
|
9942
|
+
});
|
|
9943
|
+
});
|
|
9944
|
+
await session?.commitTransaction();
|
|
9945
|
+
return "Successfully created organization with verification.";
|
|
9946
|
+
} catch (error2) {
|
|
9947
|
+
await session?.abortTransaction();
|
|
9948
|
+
throw error2;
|
|
9949
|
+
} finally {
|
|
9950
|
+
await session?.endSession();
|
|
9951
|
+
}
|
|
9952
|
+
}
|
|
9808
9953
|
return {
|
|
9809
9954
|
add,
|
|
9810
|
-
addWithVerification
|
|
9955
|
+
addWithVerification,
|
|
9956
|
+
addPilot
|
|
9811
9957
|
};
|
|
9812
9958
|
}
|
|
9813
9959
|
|
|
@@ -9824,6 +9970,7 @@ function useOrgController() {
|
|
|
9824
9970
|
updateById: _updateById,
|
|
9825
9971
|
companySearch: _companySearch
|
|
9826
9972
|
} = useOrgRepo();
|
|
9973
|
+
const { addPilot: _addPilot } = useOrgService();
|
|
9827
9974
|
async function add(req, res, next) {
|
|
9828
9975
|
const value = req.body;
|
|
9829
9976
|
const { error } = schemaOrgAdd.validate(value);
|
|
@@ -9842,6 +9989,24 @@ function useOrgController() {
|
|
|
9842
9989
|
next(error2);
|
|
9843
9990
|
}
|
|
9844
9991
|
}
|
|
9992
|
+
async function addPilot(req, res, next) {
|
|
9993
|
+
const value = req.body;
|
|
9994
|
+
const { error } = schemaOrgPilot.validate(value);
|
|
9995
|
+
if (error) {
|
|
9996
|
+
next(new import_utils50.BadRequestError(error.message));
|
|
9997
|
+
return;
|
|
9998
|
+
}
|
|
9999
|
+
try {
|
|
10000
|
+
const data = await _addPilot(value);
|
|
10001
|
+
res.json({
|
|
10002
|
+
message: "Organization created successfully.",
|
|
10003
|
+
data
|
|
10004
|
+
});
|
|
10005
|
+
return;
|
|
10006
|
+
} catch (error2) {
|
|
10007
|
+
next(error2);
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
9845
10010
|
async function getOrgsByUserId(req, res, next) {
|
|
9846
10011
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
9847
10012
|
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
@@ -9985,7 +10150,8 @@ function useOrgController() {
|
|
|
9985
10150
|
getAll,
|
|
9986
10151
|
getById,
|
|
9987
10152
|
updateById,
|
|
9988
|
-
companySearch
|
|
10153
|
+
companySearch,
|
|
10154
|
+
addPilot
|
|
9989
10155
|
};
|
|
9990
10156
|
}
|
|
9991
10157
|
|
|
@@ -10410,7 +10576,8 @@ function useUserController() {
|
|
|
10410
10576
|
const id = req.params.id || "";
|
|
10411
10577
|
const validation = import_joi43.default.string().hex().validate(id);
|
|
10412
10578
|
if (validation.error) {
|
|
10413
|
-
|
|
10579
|
+
next(new import_utils52.BadRequestError("Invalid user ID."));
|
|
10580
|
+
return;
|
|
10414
10581
|
}
|
|
10415
10582
|
try {
|
|
10416
10583
|
const user = await _getUserById(id);
|
|
@@ -11142,12 +11309,79 @@ function useVerificationService() {
|
|
|
11142
11309
|
paypalOrderLink: paypalOrderLink ? paypalOrderLink.href : ""
|
|
11143
11310
|
};
|
|
11144
11311
|
} catch (error) {
|
|
11312
|
+
import_utils53.logger.log({
|
|
11313
|
+
level: "error",
|
|
11314
|
+
message: `Error processing organization setup fee: ${error}`
|
|
11315
|
+
});
|
|
11316
|
+
await session?.abortTransaction();
|
|
11145
11317
|
if (error instanceof import_utils53.AppError) {
|
|
11146
11318
|
throw error;
|
|
11147
11319
|
}
|
|
11148
11320
|
throw new import_utils53.InternalServerError(
|
|
11149
11321
|
"Failed to process organization setup fee."
|
|
11150
11322
|
);
|
|
11323
|
+
} finally {
|
|
11324
|
+
session?.endSession();
|
|
11325
|
+
}
|
|
11326
|
+
}
|
|
11327
|
+
async function inviteOrg(value) {
|
|
11328
|
+
const { error } = schemaVerificationOrgInvite.validate(value);
|
|
11329
|
+
if (error) {
|
|
11330
|
+
throw new import_utils53.BadRequestError(error.message);
|
|
11331
|
+
}
|
|
11332
|
+
const session = import_utils53.useAtlas.getClient()?.startSession();
|
|
11333
|
+
if (!session) {
|
|
11334
|
+
throw new import_utils53.BadRequestError("Unable to start database session.");
|
|
11335
|
+
}
|
|
11336
|
+
try {
|
|
11337
|
+
session.startTransaction();
|
|
11338
|
+
const orgExistingByEmail = await getOrgByEmail(value.email);
|
|
11339
|
+
if (orgExistingByEmail) {
|
|
11340
|
+
throw new import_utils53.BadRequestError(`Email ${value.email} is already taken.`);
|
|
11341
|
+
}
|
|
11342
|
+
const verificationId = await add(
|
|
11343
|
+
{
|
|
11344
|
+
type: "org-invite",
|
|
11345
|
+
email: value.email,
|
|
11346
|
+
metadata: {
|
|
11347
|
+
pilot: value.pilot
|
|
11348
|
+
}
|
|
11349
|
+
},
|
|
11350
|
+
session
|
|
11351
|
+
);
|
|
11352
|
+
const filePath = (0, import_utils53.getDirectory)(
|
|
11353
|
+
__dirname,
|
|
11354
|
+
"./public/handlebars/org-invite"
|
|
11355
|
+
);
|
|
11356
|
+
const emailContent = (0, import_utils53.compileHandlebar)({
|
|
11357
|
+
context: {
|
|
11358
|
+
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
11359
|
+
link: `${APP_ORG}/organizations/create?invite=${verificationId}`
|
|
11360
|
+
},
|
|
11361
|
+
filePath
|
|
11362
|
+
});
|
|
11363
|
+
await mailer.sendMail({
|
|
11364
|
+
to: value.email,
|
|
11365
|
+
subject: value.pilot ? "Pilot Organization Invitation" : "Organization Invitation",
|
|
11366
|
+
html: emailContent,
|
|
11367
|
+
from: "GoWeekdays"
|
|
11368
|
+
});
|
|
11369
|
+
await session?.commitTransaction();
|
|
11370
|
+
return "Successfully created organization invite.";
|
|
11371
|
+
} catch (error2) {
|
|
11372
|
+
import_utils53.logger.log({
|
|
11373
|
+
level: "error",
|
|
11374
|
+
message: `Error inviting organization: ${error2}`
|
|
11375
|
+
});
|
|
11376
|
+
await session?.abortTransaction();
|
|
11377
|
+
if (error2 instanceof import_utils53.AppError) {
|
|
11378
|
+
throw error2;
|
|
11379
|
+
}
|
|
11380
|
+
throw new import_utils53.InternalServerError(
|
|
11381
|
+
"Failed to process organization setup fee."
|
|
11382
|
+
);
|
|
11383
|
+
} finally {
|
|
11384
|
+
session?.endSession();
|
|
11151
11385
|
}
|
|
11152
11386
|
}
|
|
11153
11387
|
return {
|
|
@@ -11162,7 +11396,8 @@ function useVerificationService() {
|
|
|
11162
11396
|
inviteMember,
|
|
11163
11397
|
cancelInviteMember,
|
|
11164
11398
|
forgetPassword,
|
|
11165
|
-
orgSetupFee
|
|
11399
|
+
orgSetupFee,
|
|
11400
|
+
inviteOrg
|
|
11166
11401
|
};
|
|
11167
11402
|
}
|
|
11168
11403
|
|
|
@@ -13678,6 +13913,7 @@ function useJobPostController() {
|
|
|
13678
13913
|
schemaMemberStatus,
|
|
13679
13914
|
schemaOrg,
|
|
13680
13915
|
schemaOrgAdd,
|
|
13916
|
+
schemaOrgPilot,
|
|
13681
13917
|
schemaOrgUpdate,
|
|
13682
13918
|
schemaPermission,
|
|
13683
13919
|
schemaPermissionGroup,
|
|
@@ -13697,6 +13933,7 @@ function useJobPostController() {
|
|
|
13697
13933
|
schemaUpdateOptions,
|
|
13698
13934
|
schemaUser,
|
|
13699
13935
|
schemaVerification,
|
|
13936
|
+
schemaVerificationOrgInvite,
|
|
13700
13937
|
transactionSchema,
|
|
13701
13938
|
useAppController,
|
|
13702
13939
|
useAppRepo,
|