Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/common/paddle/recruiter/processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import {
} from '../../plus/subscription';
import { logger } from '../../../logger';
import { OpportunityJob } from '../../../entity/opportunities/OpportunityJob';
import { recruiterPaddleCustomDataSchema } from './types';
import {
recruiterPaddleCustomDataSchema,
recruiterPaddlePricingCustomDataSchema,
} from './types';
import {
ensureOpportunityPermissions,
OpportunityPermissions,
} from '../../opportunity/accessControl';
import { updateRecruiterSubscriptionFlags } from '../../utils';
import {
updateFlagsStatement,
updateRecruiterSubscriptionFlags,
} from '../../utils';
import { OpportunityState } from '@dailydotdev/schema';
import { Organization } from '../../../entity/Organization';

Expand Down Expand Up @@ -84,6 +90,24 @@ export const createOpportunitySubscription = async ({
permission: OpportunityPermissions.Edit,
});

if (event.data?.items?.length > 1) {
throw new Error(
'Multiple recruiter subscription items not supported on creation, check payment manually',
);
}

const price = event.data?.items?.[0]?.price;

if (!price) {
throw new Error(
'Price information missing from recruiter subscription data',
);
}

const priceCustomData = recruiterPaddlePricingCustomDataSchema.parse(
price.customData,
);

await con.transaction(async (entityManager) => {
await entityManager.getRepository(Organization).update(
{
Expand Down Expand Up @@ -114,6 +138,10 @@ export const createOpportunitySubscription = async ({
},
{
state: OpportunityState.IN_REVIEW,
flags: updateFlagsStatement<OpportunityJob>({
batchSize: priceCustomData.batch_size,
plan: price.id,
}),
},
);
});
Expand Down
4 changes: 4 additions & 0 deletions src/common/paddle/recruiter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export const recruiterPaddleCustomDataSchema = z.object({
user_id: z.string(),
opportunity_id: z.uuid(),
});

export const recruiterPaddlePricingCustomDataSchema = z.object({
batch_size: z.coerce.number().nonnegative().max(10_000),
});
Loading