Skip to content

Commit c7184fd

Browse files
authored
feat: save plan and batch size on recruiter sub creation (#3353)
1 parent 8f97e87 commit c7184fd

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/common/paddle/recruiter/processing.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import {
1212
} from '../../plus/subscription';
1313
import { logger } from '../../../logger';
1414
import { OpportunityJob } from '../../../entity/opportunities/OpportunityJob';
15-
import { recruiterPaddleCustomDataSchema } from './types';
15+
import {
16+
recruiterPaddleCustomDataSchema,
17+
recruiterPaddlePricingCustomDataSchema,
18+
} from './types';
1619
import {
1720
ensureOpportunityPermissions,
1821
OpportunityPermissions,
1922
} from '../../opportunity/accessControl';
20-
import { updateRecruiterSubscriptionFlags } from '../../utils';
23+
import {
24+
updateFlagsStatement,
25+
updateRecruiterSubscriptionFlags,
26+
} from '../../utils';
2127
import { OpportunityState } from '@dailydotdev/schema';
2228
import { Organization } from '../../../entity/Organization';
2329

@@ -84,6 +90,24 @@ export const createOpportunitySubscription = async ({
8490
permission: OpportunityPermissions.Edit,
8591
});
8692

93+
if (event.data?.items?.length > 1) {
94+
throw new Error(
95+
'Multiple recruiter subscription items not supported on creation, check payment manually',
96+
);
97+
}
98+
99+
const price = event.data?.items?.[0]?.price;
100+
101+
if (!price) {
102+
throw new Error(
103+
'Price information missing from recruiter subscription data',
104+
);
105+
}
106+
107+
const priceCustomData = recruiterPaddlePricingCustomDataSchema.parse(
108+
price.customData,
109+
);
110+
87111
await con.transaction(async (entityManager) => {
88112
await entityManager.getRepository(Organization).update(
89113
{
@@ -114,6 +138,10 @@ export const createOpportunitySubscription = async ({
114138
},
115139
{
116140
state: OpportunityState.IN_REVIEW,
141+
flags: updateFlagsStatement<OpportunityJob>({
142+
batchSize: priceCustomData.batch_size,
143+
plan: price.id,
144+
}),
117145
},
118146
);
119147
});

src/common/paddle/recruiter/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ export const recruiterPaddleCustomDataSchema = z.object({
44
user_id: z.string(),
55
opportunity_id: z.uuid(),
66
});
7+
8+
export const recruiterPaddlePricingCustomDataSchema = z.object({
9+
batch_size: z.coerce.number().nonnegative().max(10_000),
10+
});

0 commit comments

Comments
 (0)