normalize phone

This commit is contained in:
2025-12-06 22:42:26 +03:30
parent 3978065400
commit 01631c147a
9 changed files with 100 additions and 27 deletions
@@ -235,7 +235,7 @@ export class CouponService {
}
}
generateShortCode(length = 8) {
generateShortCode(restaurantSlug: string, length = 5) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const bytes = randomBytes(length);
let result = '';
@@ -243,12 +243,16 @@ export class CouponService {
for (let i = 0; i < bytes.length; i++) {
result += chars[bytes[i] % chars.length];
}
return result;
const prefix = restaurantSlug.slice(0, 2);
return prefix + '-' + result;
}
async generateCouponCode(restId: string): Promise<string> {
const code = this.generateShortCode(8);
const restaurant = await this.restRepository.findOne({ id: restId });
if (!restaurant) {
throw new NotFoundException(RestMessage.NOT_FOUND);
}
const code = this.generateShortCode(restaurant.slug);
const existing = await this.couponRepository.findOne({ code, restaurant: { id: restId } });
if (existing) return this.generateCouponCode(restId);