coupon module
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user