AddFirstBookingDiscount
This commit is contained in:
@@ -162,6 +162,38 @@ export class BusinessesService {
|
||||
}
|
||||
|
||||
Object.assign(business, payload);
|
||||
|
||||
if (business.promoDiscountEnabled) {
|
||||
if (
|
||||
!business.promoDiscountPercent ||
|
||||
business.promoDiscountPercent < 1 ||
|
||||
business.promoDiscountPercent > 100
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
'promoDiscountPercent must be between 1 and 100 when discount is enabled',
|
||||
);
|
||||
}
|
||||
const title = business.promoDiscountTitle?.trim();
|
||||
if (!title) {
|
||||
throw new BadRequestException(
|
||||
'promoDiscountTitle is required when discount is enabled',
|
||||
);
|
||||
}
|
||||
business.promoDiscountTitle = title;
|
||||
if (
|
||||
business.promoDiscountMode !== 'first_booking' &&
|
||||
business.promoDiscountMode !== 'always'
|
||||
) {
|
||||
business.promoDiscountMode = 'first_booking';
|
||||
}
|
||||
const code = business.promoDiscountCode?.trim();
|
||||
if (!code) {
|
||||
business.promoDiscountCode = `NEW${business.promoDiscountPercent}`;
|
||||
} else {
|
||||
business.promoDiscountCode = code.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
const saved = await this.repo.save(business);
|
||||
return this.ensureOwnerFromContactPhone(saved);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user