refactor: api v2 schedules (#14870)
* api: createSchedule refactor - still need to handle overrides * createSchedule: handle overrides * createSchedule: default schedule e2e test fix and pad hours:minutes * get default schedule, by id and all schedules * update schedule * refactor: update handler delete only if overrides or availabilities given * remove comment * refactor: move schedules inputs, outputs to platform-types + e2e tests refactor * refactor e2e * fix: overrides and test * fix managed user create * my brain is fried but refactor good * WIP: transform api schedule for atom * WIP: transform api schedule for atom * WIP: transform api schedule for atom * fix: re-export atom transformer from lib * fix: format schedule for api from atom * fix ts ignore * refactor: move schedule hooks into hooks/schedules * feat: useSchedules hook to get count of user schedules * tests: setup atom tests & test transformScheduleForAtom * rename transformers * test transformAtomScheduleForApi * reset scheduel update handler for trpc * fix: import path * refactor: transformers * swagger docs fix * get rid of unused availabilities module * get rid of eslint-disable-next-line in schedules repository * refactor: remove crypto from atoms vite rollupOptions * refactor: comment schedules repository update logic
This commit is contained in:
1 parent
ca05e701a8
commit
c25c835b76
55 files changed
+1391
-1209
No files matched your search
@@ -1,10 +0,0 @@
|
||||
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 {}
|
||||
@@ -1,16 +0,0 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
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,7 +21,6 @@ import {
|
||||
HttpStatus,
|
||||
Param,
|
||||
Patch,
|
||||
BadRequestException,
|
||||
Delete,
|
||||
Query,
|
||||
NotFoundException,
|
||||
|
||||
@@ -173,6 +173,14 @@ 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