Skip to content

Commit

Permalink
chore: Tidy up unused variables, etc (calcom#14289)
Browse files Browse the repository at this point in the history
  • Loading branch information
exception authored Apr 2, 2024
1 parent 2aada9a commit cdf0593
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 40 deletions.
2 changes: 1 addition & 1 deletion apps/api/v2/src/app.logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions apps/api/v2/src/ee/gcal/gcal.controller.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 2 additions & 4 deletions apps/api/v2/src/ee/gcal/gcal.controller.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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`;
Expand Down
4 changes: 2 additions & 2 deletions apps/api/v2/src/ee/gcal/gcal.module.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 {}
9 changes: 1 addition & 8 deletions apps/api/v2/src/ee/provider/provider.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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,
Controller,
Get,
HttpCode,
HttpStatus,
Logger,
NotFoundException,
Param,
UnauthorizedException,
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions apps/api/v2/src/filters/trpc-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class TRPCExceptionFilter implements ExceptionFilter {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest();

let statusCode = 500;
switch (exception.code) {
case "UNAUTHORIZED":
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions apps/api/v2/src/filters/zod-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export class ZodExceptionFilter implements ExceptionFilter {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
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(),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/src/lib/atoms/decorators/for-atom.decorator.ts
Original file line number Diff line number Diff line change
@@ -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";
});
8 changes: 4 additions & 4 deletions apps/api/v2/src/modules/apps/services/gcal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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" };
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/src/modules/prisma/prisma-read.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/src/modules/prisma/prisma-write.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down

0 comments on commit cdf0593

Please sign in to comment.