Skip to content

Commit

Permalink
affiliate: Make affiliateCode available only for active affiliates
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Oct 19, 2023
1 parent 39b7f7a commit ed56cfc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions apps/api/src/affiliate/affiliate.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,23 @@ export class AffiliateController {

if (!affiliate) throw new NotFoundException('Affiliate not found')

let affiliateCode: string | null = affiliate.affiliateCode

if (affiliate.status === newStatus) {
throw new ConflictException('Status is the same')
}

if (affiliate.status === 'pending' && newStatus === 'active') {
const affiliateCode = affiliateCodeGenerator(affiliate.id)
return await this.affiliateService.updateStatus(affiliateId, newStatus, affiliateCode)
if (
(affiliate.status === 'pending' || affiliate.status === 'cancelled') &&
newStatus === 'active'
) {
affiliateCode = affiliateCodeGenerator(affiliate.id)
}

return await this.affiliateService.updateStatus(affiliateId, newStatus, affiliate.affiliateCode)
if (affiliate.status === 'active' && newStatus !== 'active') {
affiliateCode = null
}
return await this.affiliateService.updateStatus(affiliateId, newStatus, affiliateCode)
}

@Get(':affiliateCode')
Expand Down

0 comments on commit ed56cfc

Please sign in to comment.