coupon module

This commit is contained in:
2025-12-06 12:50:51 +03:30
parent 7a5b181af2
commit 816cb639e7
15 changed files with 804 additions and 3 deletions
@@ -0,0 +1,53 @@
import { Entity, ManyToOne, Property, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
export enum CouponType {
PERCENTAGE = 'PERCENTAGE',
FIXED = 'FIXED',
}
@Entity({ tableName: 'coupons' })
export class Coupon extends BaseEntity {
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@Property({ unique: true })
code!: string;
@Property()
name!: string;
@Property({ type: 'text', nullable: true })
description?: string;
@Enum(() => CouponType)
type!: CouponType;
@Property({ type: 'decimal', precision: 10, scale: 2 })
value!: number; // Discount amount or percentage
@Property({ type: 'decimal', precision: 10, scale: 2, nullable: true })
maxDiscount?: number; // Maximum discount for percentage coupons
@Property({ type: 'decimal', precision: 10, scale: 2, nullable: true })
minOrderAmount?: number; // Minimum order amount to use coupon
@Property({ type: 'int', nullable: true })
maxUses?: number; // Maximum number of times coupon can be used
@Property({ type: 'int', default: 0 })
usedCount: number = 0; // Number of times coupon has been used
@Property({ type: 'int', nullable: true })
maxUsesPerUser?: number; // Maximum uses per user
@Property({ type: 'timestamptz', nullable: true })
startDate?: Date; // Coupon validity start date
@Property({ type: 'timestamptz', nullable: true })
endDate?: Date; // Coupon validity end date
@Property({ type: 'boolean', default: true })
isActive: boolean = true;
}