fix schedule

This commit is contained in:
2025-11-15 12:01:57 +03:30
parent e521e56f3e
commit 008351acd2
3 changed files with 22 additions and 12 deletions
@@ -1,11 +1,14 @@
import { IsString, IsNumber, IsBoolean, IsOptional, Min, Max } from 'class-validator';
import { IsNumber, IsBoolean, IsOptional, IsString, Min, Max } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
export class CreateScheduleDto {
@ApiProperty({ example: '2024-01-15', description: 'تاریخ برای برنامه' })
@IsString()
date!: string;
@ApiProperty({ example: 1, description: 'روز هفته (۰=یکشنبه، ۶=شنبه)' })
@IsNumber()
@Min(0)
@Max(6)
@Type(() => Number)
weekDay!: number;
@ApiProperty({ example: 900, description: 'زمان باز شدن (دقیقه از نیمه شب)' })
@IsNumber()
@@ -26,5 +29,8 @@ export class CreateScheduleDto {
@IsBoolean()
@Type(() => Boolean)
isActive?: boolean;
@ApiProperty({ example: 'rest-ulid-123', description: 'شناسه رستوران' })
@IsString()
restId!: string;
}
@@ -1,10 +1,11 @@
import { Entity, Property } from '@mikro-orm/core';
import { Entity, Property, Unique } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
@Entity({ tableName: 'schedules' })
@Unique({ properties: ['restId', 'weekDay'] })
export class Schedule extends BaseEntity {
@Property({ type: 'date' })
date!: Date;
@Property({ type: 'int' })
weekDay!: number;
@Property({ type: 'int' })
openTime!: number;
@@ -17,11 +17,11 @@ export class ScheduleService {
async create(createScheduleDto: CreateScheduleDto): Promise<Schedule> {
const data: RequiredEntityData<Schedule> = {
date: new Date(createScheduleDto.date),
weekDay: createScheduleDto.weekDay,
openTime: createScheduleDto.openTime,
closeTime: createScheduleDto.closeTime,
isActive: createScheduleDto.isActive ?? true,
restId: '01KA35CFFN0F6VA04DF0W6KCE3',
restId: createScheduleDto.restId,
};
const schedule = this.scheduleRepository.create(data);
@@ -49,8 +49,8 @@ export class ScheduleService {
}
const updateData: Partial<Schedule> = {};
if (updateScheduleDto.date) {
updateData.date = new Date(updateScheduleDto.date);
if (updateScheduleDto.weekDay !== undefined) {
updateData.weekDay = updateScheduleDto.weekDay;
}
if (updateScheduleDto.openTime !== undefined) {
updateData.openTime = updateScheduleDto.openTime;
@@ -61,6 +61,9 @@ export class ScheduleService {
if (updateScheduleDto.isActive !== undefined) {
updateData.isActive = updateScheduleDto.isActive;
}
if (updateScheduleDto.restId) {
updateData.restId = updateScheduleDto.restId;
}
this.em.assign(schedule, updateData);
await this.em.persistAndFlush(schedule);