refactor: platform timezone endpoint (#14250)
* refactor: platform timezone endpoint * fixup! refactor: platform timezone endpoint * fixup! fixup! refactor: platform timezone endpoint
This commit is contained in:
1 parent
26d64bd93f
commit
c854dd092c
8 files changed
+66
-37
No files matched your search
@@ -21,7 +21,6 @@ import {
|
||||
|
||||
import { SCHEDULE_READ, SCHEDULE_WRITE, SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { ScheduleWithAvailabilitiesForWeb } from "@calcom/platform-libraries";
|
||||
import type { CityTimezones } from "@calcom/platform-libraries";
|
||||
import { updateScheduleHandler } from "@calcom/platform-libraries";
|
||||
import type { UpdateScheduleOutputType } from "@calcom/platform-libraries";
|
||||
import { ApiSuccessResponse, ScheduleResponse, UpdateScheduleInput } from "@calcom/platform-types";
|
||||
@@ -73,16 +72,6 @@ export class SchedulesController {
|
||||
};
|
||||
}
|
||||
|
||||
@Get("/time-zones")
|
||||
async getTimeZones(): Promise<ApiResponse<CityTimezones>> {
|
||||
const timeZones = await this.schedulesService.getSchedulePossibleTimeZones();
|
||||
|
||||
return {
|
||||
status: SUCCESS_STATUS,
|
||||
data: timeZones,
|
||||
};
|
||||
}
|
||||
|
||||
@Get("/:scheduleId")
|
||||
@Permissions([SCHEDULE_READ])
|
||||
async getSchedule(
|
||||
|
||||
@@ -6,8 +6,6 @@ import { UsersRepository } from "@/modules/users/users.repository";
|
||||
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { Schedule } from "@prisma/client";
|
||||
|
||||
import { cityTimezonesHandler } from "@calcom/platform-libraries";
|
||||
|
||||
@Injectable()
|
||||
export class SchedulesService {
|
||||
constructor(
|
||||
@@ -96,8 +94,4 @@ export class SchedulesService {
|
||||
throw new ForbiddenException(`User with ID=${userId} does not own schedule with ID=${schedule.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getSchedulePossibleTimeZones() {
|
||||
return cityTimezonesHandler();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import { PlatformEndpointsModule } from "@/ee/platform-endpoints-module";
|
||||
import { EventsModule } from "@/modules/events/events.module";
|
||||
import { OAuthClientModule } from "@/modules/oauth-clients/oauth-client.module";
|
||||
import { TimezoneModule } from "@/modules/timezones/timezones.module";
|
||||
import type { MiddlewareConsumer, NestModule } from "@nestjs/common";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
@Module({
|
||||
imports: [EventsModule, OAuthClientModule, PlatformEndpointsModule],
|
||||
imports: [EventsModule, OAuthClientModule, PlatformEndpointsModule, TimezoneModule],
|
||||
})
|
||||
export class EndpointsModule implements NestModule {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { TimezonesService } from "@/modules/timezones/services/timezones.service";
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
|
||||
import { SUCCESS_STATUS } from "@calcom/platform-constants";
|
||||
import type { CityTimezones } from "@calcom/platform-libraries";
|
||||
import { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
@Controller({
|
||||
path: "timezones",
|
||||
version: "2",
|
||||
})
|
||||
export class TimezonesController {
|
||||
constructor(private readonly timezonesService: TimezonesService) {}
|
||||
|
||||
@Get("/")
|
||||
async getTimeZones(): Promise<ApiResponse<CityTimezones>> {
|
||||
const timeZones = await this.timezonesService.getCityTimeZones();
|
||||
|
||||
return {
|
||||
status: SUCCESS_STATUS,
|
||||
data: timeZones,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
import { cityTimezonesHandler } from "@calcom/platform-libraries";
|
||||
|
||||
@Injectable()
|
||||
export class TimezonesService {
|
||||
async getCityTimeZones() {
|
||||
return cityTimezonesHandler();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TimezonesController } from "@/modules/timezones/controllers/timezones.controller";
|
||||
import { TimezonesService } from "@/modules/timezones/services/timezones.service";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
providers: [TimezonesService],
|
||||
controllers: [TimezonesController],
|
||||
exports: [TimezonesService],
|
||||
})
|
||||
export class TimezoneModule {}
|
||||
@@ -807,24 +807,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v2/schedules/time-zones": {
|
||||
"get": {
|
||||
"operationId": "SchedulesController_getTimeZones",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v2/schedules/{scheduleId}": {
|
||||
"get": {
|
||||
"operationId": "SchedulesController_getSchedule",
|
||||
@@ -1240,6 +1222,24 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v2/timezones": {
|
||||
"get": {
|
||||
"operationId": "TimezonesController_getTimeZones",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
|
||||
@@ -7,7 +7,7 @@ import http from "../lib/http";
|
||||
const useGetCityTimezones = () => {
|
||||
const endpoint = new URL(BASE_URL);
|
||||
|
||||
endpoint.pathname = `api/${API_VERSION}/schedules/time-zones`;
|
||||
endpoint.pathname = `api/${API_VERSION}/timezones`;
|
||||
|
||||
const { isLoading, data } = useQuery({
|
||||
queryKey: ["city-timezones"],
|
||||
|
||||
Reference in new issue
Block a user