File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed
app/(ee)/api/cron/partners/ban Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -131,14 +131,7 @@ export const POST = withCron(async ({ rawBody }) => {
131131 recordLink ( links , { deleted : true } ) ,
132132
133133 // Queue discount code deletions
134- deleteDiscountCodes (
135- links
136- . map ( ( link ) => link . discountCode )
137- . filter (
138- ( discountCode ) : discountCode is NonNullable < typeof discountCode > =>
139- discountCode !== null ,
140- ) ,
141- ) ,
134+ deleteDiscountCodes ( links . map ( ( link ) => link . discountCode ) ) ,
142135 ] ) ;
143136
144137 const affectedProgramEnrollments = await prisma . programEnrollment . findMany ( {
Original file line number Diff line number Diff line change @@ -7,17 +7,22 @@ const queue = qstash.queue({
77 queueName : "delete-discount-code" ,
88} ) ;
99
10+ type DiscountCodePayload = Pick < DiscountCode , "id" | "code" | "programId" > ;
11+
1012type DeleteDiscountCodesParams =
11- | Pick < DiscountCode , "id" | "code" | "programId" >
12- | Pick < DiscountCode , "id" | "code" | "programId" > [ ] ;
13+ | DiscountCodePayload
14+ | ( DiscountCodePayload | null | undefined ) [ ] ;
1315
1416// Triggered in the following cases:
1517// 1. When a discount is deleted
1618// 2. When a link is deleted that has a discount code associated with it
1719// 3. When partners are banned / deactivated
1820// 4. When a partner is moved to a different group
1921export async function deleteDiscountCodes ( input : DeleteDiscountCodesParams ) {
20- const discountCodes = Array . isArray ( input ) ? input : [ input ] ;
22+ const raw = Array . isArray ( input ) ? input : [ input ] ;
23+ const discountCodes = raw . filter (
24+ ( dc ) : dc is NonNullable < typeof dc > => dc != null ,
25+ ) ;
2126
2227 if ( discountCodes . length === 0 ) {
2328 return ;
You can’t perform that action at this time.
0 commit comments