From 82403c811e87fc3b4799d9429d84e8a03ba6e04a Mon Sep 17 00:00:00 2001 From: GitBluub Date: Wed, 20 Sep 2023 23:54:04 +0200 Subject: [PATCH] fix: format --- back/src/auth/auth.controller.ts | 21 ++++---- back/src/history/dto/SearchHistoryDto.ts | 4 +- back/src/history/dto/SongHistoryDto.ts | 8 +-- back/src/history/history.controller.ts | 17 +++--- back/src/history/history.service.spec.ts | 20 +++---- back/src/history/history.service.ts | 4 +- back/src/main.ts | 66 ++++++++++++++---------- back/src/search/search.controller.ts | 19 +++++-- back/src/search/search.service.ts | 5 +- back/src/settings/settings.module.ts | 6 +-- back/src/settings/settings.service.ts | 12 +++-- 11 files changed, 107 insertions(+), 75 deletions(-) diff --git a/back/src/auth/auth.controller.ts b/back/src/auth/auth.controller.ts index db904d8..0cb7970 100644 --- a/back/src/auth/auth.controller.ts +++ b/back/src/auth/auth.controller.ts @@ -45,9 +45,9 @@ export class AuthController { @Post('register') async register(@Body() registerDto: RegisterDto): Promise { try { - const user = await this.usersService.createUser(registerDto) + const user = await this.usersService.createUser(registerDto); await this.settingsService.createUserSetting(user.id); - } catch(e) { + } catch (e) { console.error(e); throw new BadRequestException(); } @@ -116,25 +116,28 @@ export class AuthController { @UseGuards(JwtAuthGuard) @ApiBearerAuth() - @ApiOkResponse({description: 'Successfully edited settings', type: Setting}) - @ApiUnauthorizedResponse({description: 'Invalid token'}) + @ApiOkResponse({ description: 'Successfully edited settings', type: Setting }) + @ApiUnauthorizedResponse({ description: 'Invalid token' }) @Patch('me/settings') udpateSettings( @Request() req: any, - @Body() settingUserDto: UpdateSettingDto): Promise { + @Body() settingUserDto: UpdateSettingDto, + ): Promise { return this.settingsService.updateUserSettings({ - where: { userId: +req.user.id}, + where: { userId: +req.user.id }, data: settingUserDto, }); } @UseGuards(JwtAuthGuard) @ApiBearerAuth() - @ApiOkResponse({description: 'Successfully edited settings', type: Setting}) - @ApiUnauthorizedResponse({description: 'Invalid token'}) + @ApiOkResponse({ description: 'Successfully edited settings', type: Setting }) + @ApiUnauthorizedResponse({ description: 'Invalid token' }) @Get('me/settings') async getSettings(@Request() req: any): Promise { - const result = await this.settingsService.getUserSetting({ userId: +req.user.id }); + const result = await this.settingsService.getUserSetting({ + userId: +req.user.id, + }); if (!result) throw new NotFoundException(); return result; } diff --git a/back/src/history/dto/SearchHistoryDto.ts b/back/src/history/dto/SearchHistoryDto.ts index 3ecbba6..1d2fb75 100644 --- a/back/src/history/dto/SearchHistoryDto.ts +++ b/back/src/history/dto/SearchHistoryDto.ts @@ -1,9 +1,9 @@ -import { ApiProperty } from "@nestjs/swagger"; +import { ApiProperty } from '@nestjs/swagger'; export class SearchHistoryDto { @ApiProperty() query: string; @ApiProperty() - type: "song" | "artist" | "album" | "genre"; + type: 'song' | 'artist' | 'album' | 'genre'; } diff --git a/back/src/history/dto/SongHistoryDto.ts b/back/src/history/dto/SongHistoryDto.ts index ff9ec68..b180a12 100644 --- a/back/src/history/dto/SongHistoryDto.ts +++ b/back/src/history/dto/SongHistoryDto.ts @@ -1,5 +1,5 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsNumber } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { IsNumber } from 'class-validator'; export class SongHistoryDto { @ApiProperty() @@ -15,8 +15,8 @@ export class SongHistoryDto { score: number; @ApiProperty() - difficulties: Record + difficulties: Record; @ApiProperty() - info: Record + info: Record; } diff --git a/back/src/history/history.controller.ts b/back/src/history/history.controller.ts index 53d809f..19cf596 100644 --- a/back/src/history/history.controller.ts +++ b/back/src/history/history.controller.ts @@ -20,7 +20,7 @@ import { SearchHistoryDto } from './dto/SearchHistoryDto'; @Controller('history') @ApiTags('history') export class HistoryController { - constructor(private readonly historyService: HistoryService) { } + constructor(private readonly historyService: HistoryService) {} @Get() @HttpCode(200) @@ -52,14 +52,17 @@ export class HistoryController { return this.historyService.createSongHistoryRecord(record); } - @Post("search") + @Post('search') @HttpCode(201) @UseGuards(JwtAuthGuard) - @ApiUnauthorizedResponse({description: "Invalid token"}) + @ApiUnauthorizedResponse({ description: 'Invalid token' }) async createSearchHistory( @Request() req: any, - @Body() record: SearchHistoryDto - ): Promise { - await this.historyService.createSearchHistoryRecord(req.user.id, { query: record.query, type: record.type }); - } + @Body() record: SearchHistoryDto, + ): Promise { + await this.historyService.createSearchHistoryRecord(req.user.id, { + query: record.query, + type: record.type, + }); + } } diff --git a/back/src/history/history.service.spec.ts b/back/src/history/history.service.spec.ts index b79a1c6..8a1f463 100644 --- a/back/src/history/history.service.spec.ts +++ b/back/src/history/history.service.spec.ts @@ -2,17 +2,17 @@ import { Test, TestingModule } from '@nestjs/testing'; import { HistoryService } from './history.service'; describe('HistoryService', () => { - let service: HistoryService; + let service: HistoryService; - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [HistoryService], - }).compile(); + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [HistoryService], + }).compile(); - service = module.get(HistoryService); - }); + service = module.get(HistoryService); + }); - it('should be defined', () => { - expect(service).toBeDefined(); - }); + it('should be defined', () => { + expect(service).toBeDefined(); + }); }); diff --git a/back/src/history/history.service.ts b/back/src/history/history.service.ts index 8d89435..fff3518 100644 --- a/back/src/history/history.service.ts +++ b/back/src/history/history.service.ts @@ -6,7 +6,7 @@ import { SongHistoryDto } from './dto/SongHistoryDto'; @Injectable() export class HistoryService { - constructor(private prisma: PrismaService) { } + constructor(private prisma: PrismaService) {} async createSongHistoryRecord({ songID, @@ -74,7 +74,7 @@ export class HistoryService { async createSearchHistoryRecord( userID: number, - { query, type }: SearchHistoryDto + { query, type }: SearchHistoryDto, ): Promise { return this.prisma.searchHistory.create({ data: { diff --git a/back/src/main.ts b/back/src/main.ts index 1ab533c..2d11fc7 100644 --- a/back/src/main.ts +++ b/back/src/main.ts @@ -2,43 +2,55 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { PrismaService } from './prisma/prisma.service'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; -import { CallHandler, ExecutionContext, Injectable, NestInterceptor, ValidationPipe } from '@nestjs/common'; -import {RequestLogger, RequestLoggerOptions} from 'json-logger-service'; +import { + CallHandler, + ExecutionContext, + Injectable, + NestInterceptor, + ValidationPipe, +} from '@nestjs/common'; +import { RequestLogger, RequestLoggerOptions } from 'json-logger-service'; import { tap } from 'rxjs'; @Injectable() export class AspectLogger implements NestInterceptor { - intercept(context: ExecutionContext, next: CallHandler) { - const req = context.switchToHttp().getRequest(); - const res = context.switchToHttp().getResponse(); - const { statusCode } = context.switchToHttp().getResponse(); - const { originalUrl, method, params, query, body, user} = req; + intercept(context: ExecutionContext, next: CallHandler) { + const req = context.switchToHttp().getRequest(); + const res = context.switchToHttp().getResponse(); + const { statusCode } = context.switchToHttp().getResponse(); + const { originalUrl, method, params, query, body, user } = req; - const toPrint = { - originalUrl, - method, - params, - query, - body, - "userId": user?.id ?? "not logged in", - "username": user?.username ?? "not logged in", - }; + const toPrint = { + originalUrl, + method, + params, + query, + body, + userId: user?.id ?? 'not logged in', + username: user?.username ?? 'not logged in', + }; - return next.handle().pipe( - tap((data) => - console.log(JSON.stringify({ - ...toPrint, - statusCode, - data - })) - ) - ); - } + return next.handle().pipe( + tap((data) => + console.log( + JSON.stringify({ + ...toPrint, + statusCode, + data, + }), + ), + ), + ); + } } async function bootstrap() { const app = await NestFactory.create(AppModule); - app.use(RequestLogger.buildExpressRequestLogger({ doNotLogPaths: ['/health'] } as RequestLoggerOptions)); + app.use( + RequestLogger.buildExpressRequestLogger({ + doNotLogPaths: ['/health'], + } as RequestLoggerOptions), + ); const prismaService = app.get(PrismaService); await prismaService.enableShutdownHooks(app); diff --git a/back/src/search/search.controller.ts b/back/src/search/search.controller.ts index 5a19871..e500c09 100644 --- a/back/src/search/search.controller.ts +++ b/back/src/search/search.controller.ts @@ -21,11 +21,14 @@ import { SearchService } from './search.service'; @ApiTags('search') @Controller('search') export class SearchController { - constructor(private readonly searchService: SearchService) { } + constructor(private readonly searchService: SearchService) {} @Get('songs/:query') @UseGuards(JwtAuthGuard) - async searchSong(@Request() req: any, @Param('query') query: string): Promise { + async searchSong( + @Request() req: any, + @Param('query') query: string, + ): Promise { try { const ret = await this.searchService.songByGuess(query, req.user?.id); if (!ret.length) throw new NotFoundException(); @@ -37,7 +40,10 @@ export class SearchController { @Get('genres/:query') @UseGuards(JwtAuthGuard) - async searchGenre(@Request() req: any, @Param('query') query: string): Promise { + async searchGenre( + @Request() req: any, + @Param('query') query: string, + ): Promise { try { const ret = await this.searchService.genreByGuess(query, req.user?.id); if (!ret.length) throw new NotFoundException(); @@ -49,7 +55,10 @@ export class SearchController { @Get('artists/:query') @UseGuards(JwtAuthGuard) - async searchArtists(@Request() req: any, @Param('query') query: string): Promise { + async searchArtists( + @Request() req: any, + @Param('query') query: string, + ): Promise { try { const ret = await this.searchService.artistByGuess(query, req.user?.id); if (!ret.length) throw new NotFoundException(); @@ -58,4 +67,4 @@ export class SearchController { throw new InternalServerErrorException(); } } -} \ No newline at end of file +} diff --git a/back/src/search/search.service.ts b/back/src/search/search.service.ts index 77d6fce..fd0ad5d 100644 --- a/back/src/search/search.service.ts +++ b/back/src/search/search.service.ts @@ -5,7 +5,10 @@ import { PrismaService } from 'src/prisma/prisma.service'; @Injectable() export class SearchService { - constructor(private prisma: PrismaService, private history: HistoryService) { } + constructor( + private prisma: PrismaService, + private history: HistoryService, + ) {} async songByGuess(query: string, userID: number): Promise { return this.prisma.song.findMany({ diff --git a/back/src/settings/settings.module.ts b/back/src/settings/settings.module.ts index bd3000f..54dd693 100644 --- a/back/src/settings/settings.module.ts +++ b/back/src/settings/settings.module.ts @@ -3,8 +3,8 @@ import { SettingsService } from './settings.service'; import { PrismaModule } from 'src/prisma/prisma.module'; @Module({ - imports: [PrismaModule], - providers: [SettingsService], - exports: [SettingsService], + imports: [PrismaModule], + providers: [SettingsService], + exports: [SettingsService], }) export class SettingsModule {} diff --git a/back/src/settings/settings.service.ts b/back/src/settings/settings.service.ts index cda9072..cf00f74 100644 --- a/back/src/settings/settings.service.ts +++ b/back/src/settings/settings.service.ts @@ -20,10 +20,10 @@ export class SettingsService { user: { connect: { id: userId, - } - } - } - }) + }, + }, + }, + }); } async updateUserSettings(params: { @@ -37,7 +37,9 @@ export class SettingsService { }); } - async deleteUserSettings(where: Prisma.UserSettingsWhereUniqueInput): Promise { + async deleteUserSettings( + where: Prisma.UserSettingsWhereUniqueInput, + ): Promise { return this.prisma.userSettings.delete({ where, });