This reverts commit c25c835b76.
This commit is contained in:
1 parent
98235d00c8
commit
5ee3744015
55 files changed
+1211
-1393
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { AvailabilitiesService } from "@/modules/availabilities/availabilities.service";
|
||||
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
providers: [AvailabilitiesService],
|
||||
exports: [AvailabilitiesService],
|
||||
})
|
||||
export class AvailabilitiesModule {}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { CreateAvailabilityInput } from "@/modules/availabilities/inputs/create-availability.input";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AvailabilitiesService {
|
||||
getDefaultAvailabilityInput(): CreateAvailabilityInput {
|
||||
const startTime = new Date(new Date().setUTCHours(9, 0, 0, 0));
|
||||
const endTime = new Date(new Date().setUTCHours(17, 0, 0, 0));
|
||||
|
||||
return {
|
||||
days: [1, 2, 3, 4, 5],
|
||||
startTime,
|
||||
endTime,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Transform, TransformFnParams } from "class-transformer";
|
||||
import { IsArray, IsDate, IsNumber } from "class-validator";
|
||||
|
||||
export class CreateAvailabilityInput {
|
||||
@IsArray()
|
||||
@IsNumber({}, { each: true })
|
||||
@ApiProperty({ example: [1, 2] })
|
||||
days!: number[];
|
||||
|
||||
@IsDate()
|
||||
@Transform(({ value, key }: TransformFnParams) => transformStringToDate(value, key))
|
||||
startTime!: Date;
|
||||
|
||||
@IsDate()
|
||||
@Transform(({ value, key }: TransformFnParams) => transformStringToDate(value, key))
|
||||
endTime!: Date;
|
||||
}
|
||||
|
||||
function transformStringToDate(value: string, key: string): Date {
|
||||
// note(Lauris): incoming value is ISO8061 e.g. 2025-0412T13:17:56.324Z
|
||||
const dateTimeParts = value.split("T");
|
||||
|
||||
const timePart = dateTimeParts[1].split(".")[0]; // Removes milliseconds
|
||||
const parts = timePart.split(":");
|
||||
|
||||
if (parts.length !== 3) {
|
||||
throw new BadRequestException(
|
||||
`Invalid time format. Expected format(ISO8061): 2025-0412T13:17:56.324Z. Received: ${value}`
|
||||
);
|
||||
}
|
||||
const [hours, minutes, seconds] = parts.map(Number);
|
||||
|
||||
if (hours < 0 || hours > 23) {
|
||||
throw new BadRequestException(`Invalid ${key} hours. Expected value between 0 and 23`);
|
||||
}
|
||||
|
||||
if (minutes < 0 || minutes > 59) {
|
||||
throw new BadRequestException(`Invalid ${key} minutes. Expected value between 0 and 59`);
|
||||
}
|
||||
|
||||
if (seconds < 0 || seconds > 59) {
|
||||
throw new BadRequestException(`Invalid ${key} seconds. Expected value between 0 and 59`);
|
||||
}
|
||||
|
||||
return new Date(new Date().setUTCHours(hours, minutes, seconds, 0));
|
||||
}
|
||||
+1
@@ -21,6 +21,7 @@ import {
|
||||
HttpStatus,
|
||||
Param,
|
||||
Patch,
|
||||
BadRequestException,
|
||||
Delete,
|
||||
Query,
|
||||
NotFoundException,
|
||||
|
||||
@@ -173,14 +173,6 @@ export class UsersRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getUserScheduleDefaultId(userId: number) {
|
||||
const user = await this.findById(userId);
|
||||
|
||||
if (!user?.defaultScheduleId) return null;
|
||||
|
||||
return user?.defaultScheduleId;
|
||||
}
|
||||
}
|
||||
|
||||
function capitalizeTimezone(timezone: string) {
|
||||
|
||||
Reference in new issue
Block a user