From ef97ea74b53b94e0cb0eb0ca66bbcc85f0ce490b Mon Sep 17 00:00:00 2001 From: Iqro-dev Date: Fri, 27 Dec 2024 18:58:04 +0100 Subject: [PATCH] refactor(controllers): remove cache --- .../history/router/history.controller.spec.ts | 8 +------- src/modules/history/router/history.controller.ts | 5 +---- src/modules/items/albums/albums.controller.spec.ts | 8 +------- src/modules/items/albums/albums.controller.ts | 3 --- .../items/artists/router/artists.controller.spec.ts | 8 +------- .../items/artists/router/artists.controller.ts | 3 --- src/modules/items/tracks/tracks.controller.spec.ts | 8 +------- src/modules/items/tracks/tracks.controller.ts | 3 --- .../reports/router/reports.controller.spec.ts | 8 +------- src/modules/reports/router/reports.controller.ts | 10 +--------- .../stats/router/stats-rigtch.controller.spec.ts | 8 +------- src/modules/stats/router/stats-rigtch.controller.ts | 10 +--------- .../stats/router/stats-spotify.controller.spec.ts | 8 +------- .../stats/router/stats-spotify.controller.ts | 10 +--------- .../controllers/users-profile.controller.spec.ts | 8 +------- .../users/controllers/users-profile.controller.ts | 13 +------------ .../users/controllers/users.controller.spec.ts | 8 +------- 17 files changed, 14 insertions(+), 115 deletions(-) diff --git a/src/modules/history/router/history.controller.spec.ts b/src/modules/history/router/history.controller.spec.ts index a109040f..a1147481 100644 --- a/src/modules/history/router/history.controller.spec.ts +++ b/src/modules/history/router/history.controller.spec.ts @@ -4,7 +4,6 @@ import { getQueueToken } from '@nestjs/bullmq' import { DeepMockProxy, mockDeep } from 'vitest-mock-extended' import { PaginateQuery } from 'nestjs-paginate' import { MockInstance } from 'vitest' -import { CacheInterceptor } from '@nestjs/cache-manager' import { HistoryQueueEvents } from '../history.queue-events' @@ -72,12 +71,7 @@ describe('HistoryController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() historyController = moduleRef.get(HistoryController) historyQueue = moduleRef.get(getQueueToken(HISTORY_QUEUE)) diff --git a/src/modules/history/router/history.controller.ts b/src/modules/history/router/history.controller.ts index 1c60b7d2..c75014b4 100644 --- a/src/modules/history/router/history.controller.ts +++ b/src/modules/history/router/history.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, UseGuards, UseInterceptors } from '@nestjs/common' +import { Controller, Get, UseGuards } from '@nestjs/common' import { ApiOperation, ApiTags } from '@nestjs/swagger' import { Queue } from 'bullmq' import { @@ -8,7 +8,6 @@ import { PaginatedSwaggerDocs, paginate, } from 'nestjs-paginate' -import { CacheInterceptor, CacheTTL } from '@nestjs/cache-manager' import { HistoryQueueEvents } from '../history.queue-events' import { InjectHistoryQueue } from '../decorators' @@ -31,8 +30,6 @@ export const historyTracksPaginateConfig: PaginateConfig = { @Controller('users/:id/history') @ApiTags('users/{id}/history') @UseGuards(ValidateUserIdGuard) -@UseInterceptors(CacheInterceptor) -@CacheTTL(30) @ApiAuth() export class HistoryController { constructor( diff --git a/src/modules/items/albums/albums.controller.spec.ts b/src/modules/items/albums/albums.controller.spec.ts index 96fcbe33..72897d5e 100644 --- a/src/modules/items/albums/albums.controller.spec.ts +++ b/src/modules/items/albums/albums.controller.spec.ts @@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing' import { NotFoundException } from '@nestjs/common' import { PaginateQuery } from 'nestjs-paginate' import { MockInstance } from 'vitest' -import { CacheInterceptor } from '@nestjs/cache-manager' import { AlbumsController } from './albums.controller' import { AlbumsRepository } from './albums.repository' @@ -29,12 +28,7 @@ describe('AlbumsController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() albumsController = moduleRef.get(AlbumsController) albumsRepository = moduleRef.get(AlbumsRepository) diff --git a/src/modules/items/albums/albums.controller.ts b/src/modules/items/albums/albums.controller.ts index df6e7fd5..1b8c6394 100644 --- a/src/modules/items/albums/albums.controller.ts +++ b/src/modules/items/albums/albums.controller.ts @@ -4,7 +4,6 @@ import { NotFoundException, Param, ParseUUIDPipe, - UseInterceptors, } from '@nestjs/common' import { ApiBadRequestResponse, @@ -21,7 +20,6 @@ import { PaginatedSwaggerDocs, paginate, } from 'nestjs-paginate' -import { CacheInterceptor } from '@nestjs/cache-manager' import { AlbumsRepository } from './albums.repository' import { AlbumBaseDocument, AlbumDocument } from './docs' @@ -44,7 +42,6 @@ export const albumsPaginateConfig: PaginateConfig = { } @Controller('albums') -@UseInterceptors(CacheInterceptor) @ApiTags('albums') export class AlbumsController { constructor(private readonly albumsRepository: AlbumsRepository) {} diff --git a/src/modules/items/artists/router/artists.controller.spec.ts b/src/modules/items/artists/router/artists.controller.spec.ts index 0b7f0b80..bd885e35 100644 --- a/src/modules/items/artists/router/artists.controller.spec.ts +++ b/src/modules/items/artists/router/artists.controller.spec.ts @@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing' import { NotFoundException } from '@nestjs/common' import { PaginateQuery } from 'nestjs-paginate' import { MockInstance } from 'vitest' -import { CacheInterceptor } from '@nestjs/cache-manager' import { ArtistsRepository } from '../artists.repository' @@ -54,12 +53,7 @@ describe('ArtistsController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() artistsController = moduleRef.get(ArtistsController) artistsRepository = moduleRef.get(ArtistsRepository) diff --git a/src/modules/items/artists/router/artists.controller.ts b/src/modules/items/artists/router/artists.controller.ts index 30fcf1a3..499b218d 100644 --- a/src/modules/items/artists/router/artists.controller.ts +++ b/src/modules/items/artists/router/artists.controller.ts @@ -5,7 +5,6 @@ import { Param, ParseUUIDPipe, Query, - UseInterceptors, } from '@nestjs/common' import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger' import { @@ -15,7 +14,6 @@ import { PaginatedSwaggerDocs, paginate, } from 'nestjs-paginate' -import { CacheInterceptor } from '@nestjs/cache-manager' import { ArtistsRepository } from '../artists.repository' import { Artist } from '../artist.entity' @@ -38,7 +36,6 @@ export const artistsPaginateConfig: PaginateConfig = { } @Controller('artists') -@UseInterceptors(CacheInterceptor) @ApiTags('artists') export class ArtistsController { constructor( diff --git a/src/modules/items/tracks/tracks.controller.spec.ts b/src/modules/items/tracks/tracks.controller.spec.ts index d092500f..3eeb519b 100644 --- a/src/modules/items/tracks/tracks.controller.spec.ts +++ b/src/modules/items/tracks/tracks.controller.spec.ts @@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing' import { NotFoundException } from '@nestjs/common' import { PaginateQuery } from 'nestjs-paginate' import { MockInstance } from 'vitest' -import { CacheInterceptor } from '@nestjs/cache-manager' import { TracksController } from './tracks.controller' import { TracksRepository } from './tracks.repository' @@ -30,12 +29,7 @@ describe('TracksController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() tracksController = moduleRef.get(TracksController) tracksRepository = moduleRef.get(TracksRepository) diff --git a/src/modules/items/tracks/tracks.controller.ts b/src/modules/items/tracks/tracks.controller.ts index 23067552..f4eea8e3 100644 --- a/src/modules/items/tracks/tracks.controller.ts +++ b/src/modules/items/tracks/tracks.controller.ts @@ -4,7 +4,6 @@ import { NotFoundException, Param, ParseUUIDPipe, - UseInterceptors, } from '@nestjs/common' import { ApiBadRequestResponse, @@ -21,7 +20,6 @@ import { PaginatedSwaggerDocs, paginate, } from 'nestjs-paginate' -import { CacheInterceptor } from '@nestjs/cache-manager' import { TracksRepository } from './tracks.repository' import { TrackBaseDocument, TrackDocument } from './docs' @@ -43,7 +41,6 @@ export const tracksPaginateConfig: PaginateConfig = { } @Controller('tracks') -@UseInterceptors(CacheInterceptor) @ApiTags('tracks') export class TracksController { constructor(private readonly tracksRepository: TracksRepository) {} diff --git a/src/modules/reports/router/reports.controller.spec.ts b/src/modules/reports/router/reports.controller.spec.ts index b35a27cf..d0c58a90 100644 --- a/src/modules/reports/router/reports.controller.spec.ts +++ b/src/modules/reports/router/reports.controller.spec.ts @@ -1,5 +1,4 @@ import { Test, type TestingModule } from '@nestjs/testing' -import { CacheInterceptor } from '@nestjs/cache-manager' import { ReportsService } from '../reports.service' @@ -43,12 +42,7 @@ describe('ReportsController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() reportsController = moduleRef.get(ReportsController) reportsService = moduleRef.get(ReportsService) diff --git a/src/modules/reports/router/reports.controller.ts b/src/modules/reports/router/reports.controller.ts index d26b93f2..b097b58b 100644 --- a/src/modules/reports/router/reports.controller.ts +++ b/src/modules/reports/router/reports.controller.ts @@ -1,11 +1,4 @@ -import { CacheInterceptor } from '@nestjs/cache-manager' -import { - Controller, - Get, - Query, - UseGuards, - UseInterceptors, -} from '@nestjs/common' +import { Controller, Get, Query, UseGuards } from '@nestjs/common' import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger' import { ReportsService } from '../reports.service' @@ -35,7 +28,6 @@ import { StatsMeasurement } from '@modules/stats/enums' @Controller('/users/:id/reports') @ApiTags('users/{id}/reports') @UseGuards(ValidateUserIdGuard, TimeRangeGuard) -@UseInterceptors(CacheInterceptor) @ApiAuth() @ApiUser() export class ReportsController { diff --git a/src/modules/stats/router/stats-rigtch.controller.spec.ts b/src/modules/stats/router/stats-rigtch.controller.spec.ts index ccee3555..69693446 100644 --- a/src/modules/stats/router/stats-rigtch.controller.spec.ts +++ b/src/modules/stats/router/stats-rigtch.controller.spec.ts @@ -1,6 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing' import { MockInstance } from 'vitest' -import { CacheInterceptor } from '@nestjs/cache-manager' import { StatsRigtchService } from '../stats-rigtch.service' import { StatsMeasurement } from '../enums' @@ -39,12 +38,7 @@ describe('StatsRigtchController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() statsRigtchController = moduleRef.get(StatsRigtchController) statsRigtchService = moduleRef.get(StatsRigtchService) diff --git a/src/modules/stats/router/stats-rigtch.controller.ts b/src/modules/stats/router/stats-rigtch.controller.ts index 5af5e7a4..dabd5505 100644 --- a/src/modules/stats/router/stats-rigtch.controller.ts +++ b/src/modules/stats/router/stats-rigtch.controller.ts @@ -1,11 +1,4 @@ -import { CacheInterceptor } from '@nestjs/cache-manager' -import { - Controller, - Get, - Query, - UseGuards, - UseInterceptors, -} from '@nestjs/common' +import { Controller, Get, Query, UseGuards } from '@nestjs/common' import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger' import { StatsMeasurement } from '../enums' @@ -30,7 +23,6 @@ import { ValidateUserIdGuard } from '@modules/users/guards' @Controller('/users/:id/stats/rigtch') @ApiTags('users/{id}/stats/rigtch') @UseGuards(ValidateUserIdGuard, TimeRangeGuard) -@UseInterceptors(CacheInterceptor) @ApiAuth() @ApiStatsRigtchQuery() @ApiUser() diff --git a/src/modules/stats/router/stats-spotify.controller.spec.ts b/src/modules/stats/router/stats-spotify.controller.spec.ts index 98ab9ac5..cc5658fb 100644 --- a/src/modules/stats/router/stats-spotify.controller.spec.ts +++ b/src/modules/stats/router/stats-spotify.controller.spec.ts @@ -1,4 +1,3 @@ -import { CacheInterceptor } from '@nestjs/cache-manager' import { Test, TestingModule } from '@nestjs/testing' import type { MockInstance } from 'vitest' @@ -61,12 +60,7 @@ describe('UsersProfileController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() statsSpotifyController = moduleRef.get(StatsSpotifyController) spotifyService = moduleRef.get(SpotifyService) diff --git a/src/modules/stats/router/stats-spotify.controller.ts b/src/modules/stats/router/stats-spotify.controller.ts index 2c65b5a5..9500134d 100644 --- a/src/modules/stats/router/stats-spotify.controller.ts +++ b/src/modules/stats/router/stats-spotify.controller.ts @@ -1,12 +1,5 @@ -import { - Controller, - Get, - Query, - UseGuards, - UseInterceptors, -} from '@nestjs/common' +import { Controller, Get, Query, UseGuards } from '@nestjs/common' import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger' -import { CacheInterceptor } from '@nestjs/cache-manager' import { AccessToken } from '@spotify/web-api-ts-sdk' import { ApiAuth, RequestToken } from '@common/decorators' @@ -25,7 +18,6 @@ import { TopItemQuery } from '@modules/users/dtos' @Controller('/users/:id/stats/spotify') @ApiTags('users/{id}/stats/spotify') @UseGuards(ValidateUserIdGuard, TokenGuard) -@UseInterceptors(CacheInterceptor) @ApiAuth() @ApiUser() export class StatsSpotifyController { diff --git a/src/modules/users/controllers/users-profile.controller.spec.ts b/src/modules/users/controllers/users-profile.controller.spec.ts index 9d10f22f..714f636a 100644 --- a/src/modules/users/controllers/users-profile.controller.spec.ts +++ b/src/modules/users/controllers/users-profile.controller.spec.ts @@ -1,4 +1,3 @@ -import { CacheInterceptor } from '@nestjs/cache-manager' import { Test, TestingModule } from '@nestjs/testing' import { MockInstance } from 'vitest' @@ -72,12 +71,7 @@ describe('UsersProfileController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() usersProfileController = moduleRef.get(UsersProfileController) spotifyService = moduleRef.get(SpotifyService) diff --git a/src/modules/users/controllers/users-profile.controller.ts b/src/modules/users/controllers/users-profile.controller.ts index 448baef5..e10f3f4d 100644 --- a/src/modules/users/controllers/users-profile.controller.ts +++ b/src/modules/users/controllers/users-profile.controller.ts @@ -1,13 +1,6 @@ -import { - Controller, - Get, - Query, - UseGuards, - UseInterceptors, -} from '@nestjs/common' +import { Controller, Get, Query, UseGuards } from '@nestjs/common' import { ApiOperation, ApiOkResponse, ApiTags } from '@nestjs/swagger' import { AccessToken } from '@spotify/web-api-ts-sdk' -import { CacheInterceptor } from '@nestjs/cache-manager' import { ApiItemQuery, ApiUser, RequestUser } from '../decorators' import { LastItemQuery, TopItemQuery } from '../dtos' @@ -66,7 +59,6 @@ export class UsersProfileController { } @Get('top/artists') - @UseInterceptors(CacheInterceptor) @ApiOperation({ summary: "Getting user's top artists (cached).", deprecated: true, @@ -101,7 +93,6 @@ export class UsersProfileController { } @Get('top/tracks') - @UseInterceptors(CacheInterceptor) @ApiOperation({ summary: "Getting user's top tracks (cached).", deprecated: true, @@ -136,7 +127,6 @@ export class UsersProfileController { } @Get('top/genres') - @UseInterceptors(CacheInterceptor) @ApiOperation({ summary: "Getting user's top genres (cached).", deprecated: true, @@ -159,7 +149,6 @@ export class UsersProfileController { } @Get('analysis') - @UseInterceptors(CacheInterceptor) @ApiOperation({ summary: "Getting user's analysis (cached).", deprecated: true, diff --git a/src/modules/users/controllers/users.controller.spec.ts b/src/modules/users/controllers/users.controller.spec.ts index bf28d468..36f54f9a 100644 --- a/src/modules/users/controllers/users.controller.spec.ts +++ b/src/modules/users/controllers/users.controller.spec.ts @@ -1,4 +1,3 @@ -import { CacheInterceptor } from '@nestjs/cache-manager' import { Test, TestingModule } from '@nestjs/testing' import { MockInstance } from 'vitest' @@ -67,12 +66,7 @@ describe('UsersController', () => { }, }, ], - }) - .overrideInterceptor(CacheInterceptor) - .useValue({ - intercept: vi.fn(), - }) - .compile() + }).compile() usersController = moduleRef.get(UsersController) usersRepository = moduleRef.get(UsersRepository)