diff --git a/src/door-lock/dtos/add.online-temp.dto.ts b/src/door-lock/dtos/add.online-temp.dto.ts index bb84068..269aabc 100644 --- a/src/door-lock/dtos/add.online-temp.dto.ts +++ b/src/door-lock/dtos/add.online-temp.dto.ts @@ -6,6 +6,7 @@ import { ValidateNested, IsEnum, Length, + IsOptional, } from 'class-validator'; import { Type } from 'class-transformer'; import { WorkingDays } from '@app/common/constants/working-days'; @@ -79,6 +80,7 @@ export class AddDoorLockOnlineDto { }) @IsArray() @ValidateNested({ each: true }) + @IsOptional() @Type(() => ScheduleDto) public scheduleList: ScheduleDto[]; } diff --git a/src/door-lock/services/door.lock.service.ts b/src/door-lock/services/door.lock.service.ts index d60c4bd..09cd80f 100644 --- a/src/door-lock/services/door.lock.service.ts +++ b/src/door-lock/services/door.lock.service.ts @@ -168,18 +168,24 @@ export class DoorLockService { if (passwords.result.length > 0) { const passwordFiltered = passwords.result - .filter((item) => item.schedule_list && item.schedule_list.length > 0) + .filter((item) => item.type === 1) .map((password: any) => { - password.schedule_list = password.schedule_list.map((schedule) => { - schedule.working_day = this.getDaysFromWorkingDayValue( - schedule.working_day, + if (password.schedule_list?.length > 0) { + password.schedule_list = password.schedule_list.map( + (schedule) => { + schedule.working_day = this.getDaysFromWorkingDayValue( + schedule.working_day, + ); + schedule.effective_time = this.minutesToTime( + schedule.effective_time, + ); + schedule.invalid_time = this.minutesToTime( + schedule.invalid_time, + ); + return schedule; + }, ); - schedule.effective_time = this.minutesToTime( - schedule.effective_time, - ); - schedule.invalid_time = this.minutesToTime(schedule.invalid_time); - return schedule; - }); + } return password; }); @@ -343,7 +349,7 @@ export class DoorLockService { addDeviceObj, passwordData.deviceTuyaUuid, type, - isOnline, + addDeviceObj.scheduleList ? isOnline : false, ); if (!createPass.success) {