add & edit time rezerv
This commit is contained in:
@@ -11,7 +11,10 @@ import { deleteBusinessCascade } from '../../common/utils/business-cascade.util'
|
|||||||
import { resolveUniqueSlug, normalizeSlugInput } from '../../common/utils/slug.util';
|
import { resolveUniqueSlug, normalizeSlugInput } from '../../common/utils/slug.util';
|
||||||
import { BusinessImagesService } from './business-images.service';
|
import { BusinessImagesService } from './business-images.service';
|
||||||
import { BusinessCategoryEntity } from '../../entities/business-category.entity';
|
import { BusinessCategoryEntity } from '../../entities/business-category.entity';
|
||||||
import { parseHmToMinute } from '../../common/utils/booking-schedule.util';
|
import {
|
||||||
|
normalizeHmTimeInput,
|
||||||
|
parseHmToMinute,
|
||||||
|
} from '../../common/utils/booking-schedule.util';
|
||||||
import { BusinessAvailabilitySlotEntity } from '../../entities/business-availability-slot.entity';
|
import { BusinessAvailabilitySlotEntity } from '../../entities/business-availability-slot.entity';
|
||||||
import { BusinessEntity } from '../../entities/business.entity';
|
import { BusinessEntity } from '../../entities/business.entity';
|
||||||
import { UserEntity, UserRole } from '../../entities/user.entity';
|
import { UserEntity, UserRole } from '../../entities/user.entity';
|
||||||
@@ -176,8 +179,15 @@ export class BusinessesService {
|
|||||||
|
|
||||||
const entities: BusinessAvailabilitySlotEntity[] = [];
|
const entities: BusinessAvailabilitySlotEntity[] = [];
|
||||||
for (const slot of dto.slots) {
|
for (const slot of dto.slots) {
|
||||||
const startMinute = parseHmToMinute(slot.startTime);
|
const startTime = normalizeHmTimeInput(slot.startTime);
|
||||||
const endMinute = parseHmToMinute(slot.endTime);
|
const endTime = normalizeHmTimeInput(slot.endTime);
|
||||||
|
if (!startTime || !endTime) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'ساعت باید به صورت HH:mm باشد (مثلاً 09:00)',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const startMinute = parseHmToMinute(startTime);
|
||||||
|
const endMinute = parseHmToMinute(endTime);
|
||||||
if (endMinute <= startMinute) {
|
if (endMinute <= startMinute) {
|
||||||
throw new BadRequestException('endTime must be after startTime');
|
throw new BadRequestException('endTime must be after startTime');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Transform, Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
ArrayMaxSize,
|
ArrayMaxSize,
|
||||||
IsArray,
|
IsArray,
|
||||||
IsInt,
|
IsInt,
|
||||||
IsString,
|
IsString,
|
||||||
Matches,
|
|
||||||
Max,
|
Max,
|
||||||
Min,
|
Min,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { normalizeHmTimeInput } from '../../../common/utils/booking-schedule.util';
|
|
||||||
|
|
||||||
export class AvailabilitySlotDto {
|
export class AvailabilitySlotDto {
|
||||||
@ApiProperty({ description: '0=شنبه … 6=جمعه', minimum: 0, maximum: 6 })
|
@ApiProperty({ description: '0=شنبه … 6=جمعه', minimum: 0, maximum: 6 })
|
||||||
@@ -20,16 +18,12 @@ export class AvailabilitySlotDto {
|
|||||||
@Max(6)
|
@Max(6)
|
||||||
dayOfWeek!: number;
|
dayOfWeek!: number;
|
||||||
|
|
||||||
@ApiProperty({ example: '09:00' })
|
@ApiProperty({ example: '09:00', description: 'HH:mm 24h (9:00 also accepted)' })
|
||||||
@Transform(({ value }) => normalizeHmTimeInput(value) ?? value)
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@Matches(/^([01]\d|2[0-3]):[0-5]\d]$/)
|
|
||||||
startTime!: string;
|
startTime!: string;
|
||||||
|
|
||||||
@ApiProperty({ example: '17:00' })
|
@ApiProperty({ example: '17:00', description: 'HH:mm 24h (17:30 also accepted)' })
|
||||||
@Transform(({ value }) => normalizeHmTimeInput(value) ?? value)
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@Matches(/^([01]\d|2[0-3]):[0-5]\d]$/)
|
|
||||||
endTime!: string;
|
endTime!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user