Files
dmenu-api/src/modules/coupons/dto/create-coupon.dto.ts
T
2025-12-06 12:50:51 +03:30

79 lines
2.2 KiB
TypeScript

import { IsNotEmpty, IsString, IsEnum, IsNumber, IsOptional, IsBoolean, IsDateString, Min } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { CouponType } from '../entities/coupon.entity';
export class CreateCouponDto {
@IsNotEmpty()
@IsString()
@ApiProperty({ example: 'DISCOUNT10', description: 'Unique coupon code' })
code!: string;
@IsNotEmpty()
@IsString()
@ApiProperty({ example: '10% Off', description: 'Coupon name' })
name!: string;
@IsOptional()
@IsString()
@ApiPropertyOptional({ example: 'Get 10% off on your order', description: 'Coupon description' })
description?: string;
@IsNotEmpty()
@IsEnum(CouponType)
@ApiProperty({ enum: CouponType, example: CouponType.PERCENTAGE, description: 'Coupon type' })
type!: CouponType;
@IsNotEmpty()
@IsNumber()
@Min(0)
@Type(() => Number)
@ApiProperty({ example: 10, description: 'Discount value (amount or percentage)' })
value!: number;
@IsOptional()
@IsNumber()
@Min(0)
@Type(() => Number)
@ApiPropertyOptional({ example: 50000, description: 'Maximum discount amount (for percentage coupons)' })
maxDiscount?: number;
@IsOptional()
@IsNumber()
@Min(0)
@Type(() => Number)
@ApiPropertyOptional({ example: 100000, description: 'Minimum order amount to use coupon' })
minOrderAmount?: number;
@IsOptional()
@IsNumber()
@Min(1)
@Type(() => Number)
@ApiPropertyOptional({ example: 100, description: 'Maximum number of times coupon can be used' })
maxUses?: number;
@IsOptional()
@IsNumber()
@Min(1)
@Type(() => Number)
@ApiPropertyOptional({ example: 1, description: 'Maximum uses per user' })
maxUsesPerUser?: number;
@IsOptional()
@IsDateString()
@ApiPropertyOptional({ example: '2024-01-01T00:00:00Z', description: 'Coupon validity start date' })
startDate?: string;
@IsOptional()
@IsDateString()
@ApiPropertyOptional({ example: '2024-12-31T23:59:59Z', description: 'Coupon validity end date' })
endDate?: string;
@IsOptional()
@IsBoolean()
@Type(() => Boolean)
@ApiPropertyOptional({ example: true, description: 'Whether coupon is active' })
isActive?: boolean;
}