Skip to content

Commit 65e136b

Browse files
authored
Init a free payment plan on super admin creation (#592)
1 parent 6725038 commit 65e136b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

apps/web/config/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ export default {
108108

109109
// mails
110110
minMailingAddressLength: 10,
111+
112+
// payment plan
113+
internalPaymentPlanName: "Internal Payment Plan",
111114
} as const;

apps/web/graphql/paymentplans/logic.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import constants from "@config/constants";
1313
import { checkPermission } from "@courselit/utils";
1414
import PaymentPlanModel from "@models/PaymentPlan";
1515
import { getPaymentMethodFromSettings } from "@/payments-new";
16+
import { Domain } from "@models/Domain";
1617
const { MembershipEntityType: membershipEntityType } = Constants;
1718
const { permissions } = constants;
1819

@@ -65,6 +66,7 @@ export async function getPlans({
6566
domain: ctx.subdomain._id,
6667
planId: { $in: planIds },
6768
archived: false,
69+
internal: false,
6870
}).lean();
6971
}
7072

@@ -258,3 +260,16 @@ export async function getInternalPaymentPlan(ctx: any) {
258260
internal: true,
259261
});
260262
}
263+
264+
export async function createInternalPaymentPlan(
265+
domain: Domain,
266+
userId: string,
267+
) {
268+
return await PaymentPlanModel.create({
269+
domain: domain._id,
270+
name: constants.internalPaymentPlanName,
271+
type: Constants.PaymentPlanType.FREE,
272+
internal: true,
273+
userId: userId,
274+
});
275+
}

apps/web/graphql/users/logic.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ import { addMailJob } from "@/services/queue";
3434
import { getPaymentMethodFromSettings } from "@/payments-new";
3535
import { checkForInvalidPermissions } from "@/lib/check-invalid-permissions";
3636
import { activateMembership } from "@/app/api/payment/helpers";
37-
import { getInternalPaymentPlan } from "../paymentplans/logic";
37+
import {
38+
createInternalPaymentPlan,
39+
getInternalPaymentPlan,
40+
} from "../paymentplans/logic";
3841
import {
3942
convertFiltersToDBConditions,
4043
InternalMembership,
@@ -374,6 +377,7 @@ export async function createUser({
374377
if (isNewUser) {
375378
if (superAdmin) {
376379
await initMandatoryPages(domain, createdUser);
380+
await createInternalPaymentPlan(domain, createdUser.userId);
377381
}
378382

379383
await recordActivity({

0 commit comments

Comments
 (0)