Files
cal.diy/apps/api/v2/src/ee/provider/provider.controller.ts
T
Lauris Skraucis 8382ebc057 refactor: v2 docs (#14446)
* refactor: group endpoints by tags

* refactor: remove swagger header

* feat: managed users docs

* feat: gcal docs

* feat: provider docs

* feat: managed users docs

* fix: event-types locations docs

* refactor: schedules remove forAtom logic - return just for atoms

* feat: schedules docs

* feat: schedules docs

* fix: me tests

* fix: schedules tests

* feat: me docs

* feat: calendar busy times docs

* feat: calendar connected and destination calendars docs

* feat: some docs for bookings endpoints

* fix: add OAuth id when updating user email + disallow updating username

* fix: creating user with same e-mail results in 500

* fix: me e2e tests

* fix: event-types e2e tests

* fix: oauth-client-users e2e tests

* fix: some bookings e2e

* revert: re-add name for create update user

* fix: schedule create isDefault required

* lock file from main

* lock file from main

* comment broken bookings tests

* fix: connected calendars output type

* fix: connected calendars output type
2024-04-10 12:08:41 +03:00

65 lines
1.8 KiB
TypeScript

import { ProviderVerifyAccessTokenOutput } from "@/ee/provider/outputs/verify-access-token.output";
import { ProviderVerifyClientOutput } from "@/ee/provider/outputs/verify-client.output";
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
import { AccessTokenGuard } from "@/modules/auth/guards/access-token/access-token.guard";
import { OAuthClientRepository } from "@/modules/oauth-clients/oauth-client.repository";
import { UserWithProfile } from "@/modules/users/users.repository";
import {
BadRequestException,
Controller,
Get,
HttpCode,
HttpStatus,
NotFoundException,
Param,
UnauthorizedException,
UseGuards,
} from "@nestjs/common";
import { ApiTags as DocsTags } from "@nestjs/swagger";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
@Controller({
path: "ee/provider",
version: "2",
})
@DocsTags("Cal provider")
export class CalProviderController {
constructor(private readonly oauthClientRepository: OAuthClientRepository) {}
@Get("/:clientId")
@HttpCode(HttpStatus.OK)
async verifyClientId(@Param("clientId") clientId: string): Promise<ProviderVerifyClientOutput> {
if (!clientId) {
throw new NotFoundException();
}
const oAuthClient = await this.oauthClientRepository.getOAuthClient(clientId);
if (!oAuthClient) throw new UnauthorizedException();
return {
status: SUCCESS_STATUS,
};
}
@Get("/:clientId/access-token")
@HttpCode(HttpStatus.OK)
@UseGuards(AccessTokenGuard)
async verifyAccessToken(
@Param("clientId") clientId: string,
@GetUser() user: UserWithProfile
): Promise<ProviderVerifyAccessTokenOutput> {
if (!clientId) {
throw new BadRequestException();
}
if (!user) {
throw new UnauthorizedException();
}
return {
status: SUCCESS_STATUS,
};
}
}