diff --git a/apps/api/v2/src/app.logger.middleware.ts b/apps/api/v2/src/app.logger.middleware.ts index 80ce4cef3e3f26..e69a0282f99d86 100644 --- a/apps/api/v2/src/app.logger.middleware.ts +++ b/apps/api/v2/src/app.logger.middleware.ts @@ -8,7 +8,7 @@ export class AppLoggerMiddleware implements NestMiddleware { private logger = new Logger("HTTP"); use(request: Request, response: Response, next: NextFunction): void { - const { ip, method, protocol, originalUrl, path: url } = request; + const { ip, method, originalUrl } = request; const userAgent = request.get("user-agent") || ""; response.on("close", () => { diff --git a/apps/api/v2/src/ee/bookings/inputs/create-reccuring-booking.input.ts b/apps/api/v2/src/ee/bookings/inputs/create-reccuring-booking.input.ts index 1d36e5d6fe0d46..3c7478b39be383 100644 --- a/apps/api/v2/src/ee/bookings/inputs/create-reccuring-booking.input.ts +++ b/apps/api/v2/src/ee/bookings/inputs/create-reccuring-booking.input.ts @@ -1,5 +1,5 @@ import { CreateBookingInput } from "@/ee/bookings/inputs/create-booking.input"; -import { IsBoolean, IsNumber, IsString, IsOptional, IsArray } from "class-validator"; +import { IsBoolean, IsNumber, IsOptional } from "class-validator"; import type { AppsStatus } from "@calcom/platform-libraries"; diff --git a/apps/api/v2/src/ee/calendars/controllers/calendars.controller.ts b/apps/api/v2/src/ee/calendars/controllers/calendars.controller.ts index 829cfa944c3388..2aef7d2c057ba4 100644 --- a/apps/api/v2/src/ee/calendars/controllers/calendars.controller.ts +++ b/apps/api/v2/src/ee/calendars/controllers/calendars.controller.ts @@ -2,7 +2,7 @@ import { CalendarsService } from "@/ee/calendars/services/calendars.service"; import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator"; import { AccessTokenGuard } from "@/modules/auth/guards/access-token/access-token.guard"; import { UserWithProfile } from "@/modules/users/users.repository"; -import { Controller, Get, Logger, UseGuards, Query } from "@nestjs/common"; +import { Controller, Get, UseGuards, Query } from "@nestjs/common"; import { SUCCESS_STATUS } from "@calcom/platform-constants"; import { ConnectedDestinationCalendars } from "@calcom/platform-libraries"; @@ -16,8 +16,6 @@ import { EventBusyDate } from "@calcom/types/Calendar"; }) @UseGuards(AccessTokenGuard) export class CalendarsController { - private readonly logger = new Logger("ee overlay calendars controller"); - constructor(private readonly calendarsService: CalendarsService) {} @Get("/busy-times") diff --git a/apps/api/v2/src/ee/event-types/services/event-types.service.ts b/apps/api/v2/src/ee/event-types/services/event-types.service.ts index 9edee1a43fe174..12ce0ad7fde112 100644 --- a/apps/api/v2/src/ee/event-types/services/event-types.service.ts +++ b/apps/api/v2/src/ee/event-types/services/event-types.service.ts @@ -101,11 +101,7 @@ export class EventTypesService { } async createUserDefaultEventTypes(userId: number) { - const thirtyMinutes = DEFAULT_EVENT_TYPES.thirtyMinutes; - const thirtyMinutesVideo = DEFAULT_EVENT_TYPES.thirtyMinutesVideo; - - const sixtyMinutes = DEFAULT_EVENT_TYPES.sixtyMinutes; - const sixtyMinutesVideo = DEFAULT_EVENT_TYPES.sixtyMinutesVideo; + const { sixtyMinutes, sixtyMinutesVideo, thirtyMinutes, thirtyMinutesVideo } = DEFAULT_EVENT_TYPES; const defaultEventTypes = await Promise.all([ this.eventTypesRepository.createUserEventType(userId, thirtyMinutes), diff --git a/apps/api/v2/src/ee/gcal/gcal.controller.e2e-spec.ts b/apps/api/v2/src/ee/gcal/gcal.controller.e2e-spec.ts index 598acb52329f66..08bab9f6675dd7 100644 --- a/apps/api/v2/src/ee/gcal/gcal.controller.e2e-spec.ts +++ b/apps/api/v2/src/ee/gcal/gcal.controller.e2e-spec.ts @@ -32,6 +32,7 @@ describe("Platform Gcal Endpoints", () => { let gcalCredentials: Credential; let accessTokenSecret: string; let refreshTokenSecret: string; + beforeAll(async () => { const moduleRef = await Test.createTestingModule({ providers: [PrismaExceptionFilter, HttpExceptionFilter], diff --git a/apps/api/v2/src/ee/gcal/gcal.controller.ts b/apps/api/v2/src/ee/gcal/gcal.controller.ts index 0108db5f6fc70b..6a8d5228060b9c 100644 --- a/apps/api/v2/src/ee/gcal/gcal.controller.ts +++ b/apps/api/v2/src/ee/gcal/gcal.controller.ts @@ -1,5 +1,4 @@ -import { AppsRepository } from "@/modules/apps/apps.repository"; -import { GcalService } from "@/modules/apps/services/gcal.service"; +import { GCalService } from "@/modules/apps/services/gcal.service"; import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator"; import { Permissions } from "@/modules/auth/decorators/permissions/permissions.decorator"; import { AccessTokenGuard } from "@/modules/auth/guards/access-token/access-token.guard"; @@ -47,12 +46,11 @@ export class GcalController { private readonly logger = new Logger("Platform Gcal Provider"); constructor( - private readonly appRepository: AppsRepository, private readonly credentialRepository: CredentialsRepository, private readonly tokensRepository: TokensRepository, private readonly selectedCalendarsRepository: SelectedCalendarsRepository, private readonly config: ConfigService, - private readonly gcalService: GcalService + private readonly gcalService: GCalService ) {} private redirectUri = `${this.config.get("api.url")}/ee/gcal/oauth/save`; diff --git a/apps/api/v2/src/ee/gcal/gcal.module.ts b/apps/api/v2/src/ee/gcal/gcal.module.ts index 238fb90ca29c7d..0ee9370d47d74b 100644 --- a/apps/api/v2/src/ee/gcal/gcal.module.ts +++ b/apps/api/v2/src/ee/gcal/gcal.module.ts @@ -1,6 +1,6 @@ import { GcalController } from "@/ee/gcal/gcal.controller"; import { AppsRepository } from "@/modules/apps/apps.repository"; -import { GcalService } from "@/modules/apps/services/gcal.service"; +import { GCalService } from "@/modules/apps/services/gcal.service"; import { CredentialsRepository } from "@/modules/credentials/credentials.repository"; import { OAuthClientModule } from "@/modules/oauth-clients/oauth-client.module"; import { PrismaModule } from "@/modules/prisma/prisma.module"; @@ -11,7 +11,7 @@ import { ConfigService } from "@nestjs/config"; @Module({ imports: [PrismaModule, TokensModule, OAuthClientModule], - providers: [AppsRepository, ConfigService, CredentialsRepository, SelectedCalendarsRepository, GcalService], + providers: [AppsRepository, ConfigService, CredentialsRepository, SelectedCalendarsRepository, GCalService], controllers: [GcalController], }) export class GcalModule {} diff --git a/apps/api/v2/src/ee/provider/provider.controller.ts b/apps/api/v2/src/ee/provider/provider.controller.ts index 41e6e8240b67cc..3a0667571e9615 100644 --- a/apps/api/v2/src/ee/provider/provider.controller.ts +++ b/apps/api/v2/src/ee/provider/provider.controller.ts @@ -1,7 +1,6 @@ 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 { TokensRepository } from "@/modules/tokens/tokens.repository"; import { UserWithProfile } from "@/modules/users/users.repository"; import { BadRequestException, @@ -9,7 +8,6 @@ import { Get, HttpCode, HttpStatus, - Logger, NotFoundException, Param, UnauthorizedException, @@ -24,12 +22,7 @@ import { ApiResponse } from "@calcom/platform-types"; version: "2", }) export class CalProviderController { - private readonly logger = new Logger("Platform Provider Controller"); - - constructor( - private readonly tokensRepository: TokensRepository, - private readonly oauthClientRepository: OAuthClientRepository - ) {} + constructor(private readonly oauthClientRepository: OAuthClientRepository) {} @Get("/:clientId") @HttpCode(HttpStatus.OK) diff --git a/apps/api/v2/src/filters/trpc-exception.filter.ts b/apps/api/v2/src/filters/trpc-exception.filter.ts index d0beba8197b015..4d9ae8710e13e3 100644 --- a/apps/api/v2/src/filters/trpc-exception.filter.ts +++ b/apps/api/v2/src/filters/trpc-exception.filter.ts @@ -12,6 +12,7 @@ export class TRPCExceptionFilter implements ExceptionFilter { const ctx = host.switchToHttp(); const response = ctx.getResponse(); const request = ctx.getRequest(); + let statusCode = 500; switch (exception.code) { case "UNAUTHORIZED": @@ -38,10 +39,12 @@ export class TRPCExceptionFilter implements ExceptionFilter { statusCode = 500; break; } + this.logger.error(`TRPC Exception Filter: ${exception?.message}`, { exception, request, }); + response.status(statusCode).json({ status: ERROR_STATUS, timestamp: new Date().toISOString(), diff --git a/apps/api/v2/src/filters/zod-exception.filter.ts b/apps/api/v2/src/filters/zod-exception.filter.ts index a64437376a68e7..62a12941351870 100644 --- a/apps/api/v2/src/filters/zod-exception.filter.ts +++ b/apps/api/v2/src/filters/zod-exception.filter.ts @@ -13,10 +13,12 @@ export class ZodExceptionFilter implements ExceptionFilter { const ctx = host.switchToHttp(); const response = ctx.getResponse(); const request = ctx.getRequest(); + this.logger.error(`ZodError: ${error.message}`, { error, request, }); + response.status(HttpStatus.BAD_REQUEST).json({ status: ERROR_STATUS, timestamp: new Date().toISOString(), diff --git a/apps/api/v2/src/lib/atoms/decorators/for-atom.decorator.ts b/apps/api/v2/src/lib/atoms/decorators/for-atom.decorator.ts index d07bff7f35d324..bbcadf9d2a5e71 100644 --- a/apps/api/v2/src/lib/atoms/decorators/for-atom.decorator.ts +++ b/apps/api/v2/src/lib/atoms/decorators/for-atom.decorator.ts @@ -1,6 +1,6 @@ import { createParamDecorator, ExecutionContext } from "@nestjs/common"; -export const ForAtom = createParamDecorator((data: unknown, ctx: ExecutionContext) => { +export const ForAtom = createParamDecorator((_data: unknown, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest(); return request.query.for === "atom"; }); diff --git a/apps/api/v2/src/modules/apps/services/gcal.service.ts b/apps/api/v2/src/modules/apps/services/gcal.service.ts index 45b3406363091c..fa835f8ea6c816 100644 --- a/apps/api/v2/src/modules/apps/services/gcal.service.ts +++ b/apps/api/v2/src/modules/apps/services/gcal.service.ts @@ -4,9 +4,11 @@ import { google } from "googleapis"; import { z } from "zod"; @Injectable() -export class GcalService { +export class GCalService { private logger = new Logger("GcalService"); + private gcalResponseSchema = z.object({ client_id: z.string(), client_secret: z.string() }); + constructor(private readonly appsRepository: AppsRepository) {} async getOAuthClient(redirectUri: string) { @@ -17,9 +19,7 @@ export class GcalService { throw new NotFoundException(); } - const { client_id, client_secret } = z - .object({ client_id: z.string(), client_secret: z.string() }) - .parse(app.keys); + const { client_id, client_secret } = this.gcalResponseSchema.parse(app.keys); const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirectUri); return oAuth2Client; diff --git a/apps/api/v2/src/modules/auth/guards/organization-roles/organization-roles.guard.ts b/apps/api/v2/src/modules/auth/guards/organization-roles/organization-roles.guard.ts index b410927cb1d674..c55702be8816e1 100644 --- a/apps/api/v2/src/modules/auth/guards/organization-roles/organization-roles.guard.ts +++ b/apps/api/v2/src/modules/auth/guards/organization-roles/organization-roles.guard.ts @@ -38,7 +38,7 @@ export class OrganizationRolesGuard implements CanActivate { async isPlatform(organizationId: number) { const isPlatform = await this.organizationsService.isPlatform(organizationId); if (!isPlatform) { - throw new ForbiddenException("Organization is not a platform."); + throw new ForbiddenException("Organization is not a platform (SHP)."); } } diff --git a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts index 88a140d862d61f..f465c195803029 100644 --- a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts +++ b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts @@ -27,6 +27,7 @@ export class OAuthClientUsersService { const username = generateShortHash(body.email, oAuthClientId); user = await this.userRepository.create(body, username, oAuthClientId, isPlatformManaged); } else { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [_, emailDomain] = body.email.split("@"); user = ( await createNewUsersConnectToOrgIfExists({ diff --git a/apps/api/v2/src/modules/oauth-clients/services/oauth-flow.service.ts b/apps/api/v2/src/modules/oauth-clients/services/oauth-flow.service.ts index a26e2bb7190cbf..24490dbfb7b207 100644 --- a/apps/api/v2/src/modules/oauth-clients/services/oauth-flow.service.ts +++ b/apps/api/v2/src/modules/oauth-clients/services/oauth-flow.service.ts @@ -1,20 +1,18 @@ import { TokenExpiredException } from "@/modules/auth/guards/access-token/token-expired.exception"; import { OAuthClientRepository } from "@/modules/oauth-clients/oauth-client.repository"; import { TokensRepository } from "@/modules/tokens/tokens.repository"; -import { BadRequestException, Injectable, Logger, UnauthorizedException } from "@nestjs/common"; +import { BadRequestException, Injectable, UnauthorizedException } from "@nestjs/common"; import { INVALID_ACCESS_TOKEN } from "@calcom/platform-constants"; @Injectable() export class OAuthFlowService { - private logger = new Logger("OAuthFlowService"); - constructor( private readonly tokensRepository: TokensRepository, - private readonly oAuthClientRepository: OAuthClientRepository - ) //private readonly redisService: RedisIOService - {} + private readonly oAuthClientRepository: OAuthClientRepository //private readonly redisService: RedisIOService + ) {} + // eslint-disable-next-line @typescript-eslint/no-unused-vars async propagateAccessToken(accessToken: string) { // this.logger.log("Propagating access token to redis", accessToken); // TODO propagate @@ -48,6 +46,7 @@ export class OAuthFlowService { return true; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars private async readFromCache(secret: string) { return { status: "CACHE_MISS" }; } diff --git a/apps/api/v2/src/modules/prisma/prisma-read.service.ts b/apps/api/v2/src/modules/prisma/prisma-read.service.ts index 2fbe34f7f44bdd..7913e805388ba7 100644 --- a/apps/api/v2/src/modules/prisma/prisma-read.service.ts +++ b/apps/api/v2/src/modules/prisma/prisma-read.service.ts @@ -7,7 +7,7 @@ import { PrismaClient } from "@prisma/client"; export class PrismaReadService implements OnModuleInit { public prisma: PrismaClient; - constructor(private readonly configService: ConfigService) { + constructor(readonly configService: ConfigService) { const dbUrl = configService.get("db.readUrl", { infer: true }); this.prisma = new PrismaClient({ diff --git a/apps/api/v2/src/modules/prisma/prisma-write.service.ts b/apps/api/v2/src/modules/prisma/prisma-write.service.ts index abcc23273ce5c5..0b8fc2198c6d5d 100644 --- a/apps/api/v2/src/modules/prisma/prisma-write.service.ts +++ b/apps/api/v2/src/modules/prisma/prisma-write.service.ts @@ -7,7 +7,7 @@ import { PrismaClient } from "@prisma/client"; export class PrismaWriteService implements OnModuleInit { public prisma: PrismaClient; - constructor(private readonly configService: ConfigService) { + constructor(readonly configService: ConfigService) { const dbUrl = configService.get("db.writeUrl", { infer: true }); this.prisma = new PrismaClient({ diff --git a/apps/api/v2/src/modules/selected-calendars/selected-calendars.repository.ts b/apps/api/v2/src/modules/selected-calendars/selected-calendars.repository.ts index a0a220e48d2742..dd9fd3aef1923c 100644 --- a/apps/api/v2/src/modules/selected-calendars/selected-calendars.repository.ts +++ b/apps/api/v2/src/modules/selected-calendars/selected-calendars.repository.ts @@ -1,10 +1,9 @@ -import { PrismaReadService } from "@/modules/prisma/prisma-read.service"; import { PrismaWriteService } from "@/modules/prisma/prisma-write.service"; import { Injectable } from "@nestjs/common"; @Injectable() export class SelectedCalendarsRepository { - constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {} + constructor(private readonly dbWrite: PrismaWriteService) {} createSelectedCalendar(externalId: string, credentialId: number, userId: number, integration: string) { return this.dbWrite.prisma.selectedCalendar.create({