From be58e932a987906ec997b572e34b6eecca32ccf9 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 8 Oct 2023 18:47:18 +0200 Subject: [PATCH] Run prettier --- back/src/album/album.controller.ts | 12 +++--- back/src/app.controller.ts | 4 +- back/src/auth/auth.controller.ts | 59 ++++++++++++--------------- back/src/auth/auth.service.ts | 2 +- back/src/lesson/lesson.controller.ts | 2 +- back/src/models/plage.ts | 60 ++++++++++++++++++---------- back/src/search/search.controller.ts | 36 +++++++++++------ back/src/users/users.controller.ts | 13 +++++- back/src/users/users.service.ts | 42 ++++++------------- 9 files changed, 124 insertions(+), 106 deletions(-) diff --git a/back/src/album/album.controller.ts b/back/src/album/album.controller.ts index 3051381..0444082 100644 --- a/back/src/album/album.controller.ts +++ b/back/src/album/album.controller.ts @@ -30,7 +30,9 @@ export class AlbumController { constructor(private readonly albumService: AlbumService) {} @Post() - @ApiOperation({ description: "Register a new album, should not be used by frontend"}) + @ApiOperation({ + description: 'Register a new album, should not be used by frontend', + }) async create(@Body() createAlbumDto: CreateAlbumDto) { try { return await this.albumService.createAlbum({ @@ -47,7 +49,7 @@ export class AlbumController { } @Delete(':id') - @ApiOperation({ description: "Delete an album by id"}) + @ApiOperation({ description: 'Delete an album by id' }) async remove(@Param('id', ParseIntPipe) id: number) { try { return await this.albumService.deleteAlbum({ id }); @@ -58,7 +60,7 @@ export class AlbumController { @Get() @ApiOkResponsePlaginated(_Album) - @ApiOperation({ description: "Get all albums paginated"}) + @ApiOperation({ description: 'Get all albums paginated' }) async findAll( @Req() req: Request, @FilterQuery(AlbumController.filterableFields) @@ -75,8 +77,8 @@ export class AlbumController { } @Get(':id') - @ApiOperation({ description: "Get an album by id"}) - @ApiOkResponse({ type: _Album}) + @ApiOperation({ description: 'Get an album by id' }) + @ApiOkResponse({ type: _Album }) async findOne(@Param('id', ParseIntPipe) id: number) { const res = await this.albumService.album({ id }); diff --git a/back/src/app.controller.ts b/back/src/app.controller.ts index 93301d5..a3a5a89 100644 --- a/back/src/app.controller.ts +++ b/back/src/app.controller.ts @@ -7,7 +7,9 @@ export class AppController { constructor(private readonly appService: AppService) {} @Get() - @ApiOkResponse({ description: 'Return a hello world message, used as a health route' }) + @ApiOkResponse({ + description: 'Return a hello world message, used as a health route', + }) getHello(): string { return this.appService.getHello(); } diff --git a/back/src/auth/auth.controller.ts b/back/src/auth/auth.controller.ts index 94c37e0..e791d6a 100644 --- a/back/src/auth/auth.controller.ts +++ b/back/src/auth/auth.controller.ts @@ -63,11 +63,14 @@ export class AuthController { @Get('login/google') @UseGuards(AuthGuard('google')) - @ApiOperation({description: 'Redirect to google login page'}) + @ApiOperation({ description: 'Redirect to google login page' }) googleLogin() {} @Get('logged/google') - @ApiOperation({description: 'Redirect to the front page after connecting to the google account'}) + @ApiOperation({ + description: + 'Redirect to the front page after connecting to the google account', + }) @UseGuards(AuthGuard('google')) async googleLoginCallbakc(@Req() req: any) { let user = await this.usersService.user({ googleID: req.user.googleID }); @@ -79,9 +82,11 @@ export class AuthController { } @Post('register') - @ApiOperation({description: 'Register a new user'}) + @ApiOperation({ description: 'Register a new user' }) @ApiConflictResponse({ description: 'Username or email already taken' }) - @ApiOkResponse({ description: 'Successfully registered, email sent to verify' }) + @ApiOkResponse({ + description: 'Successfully registered, email sent to verify', + }) @ApiBadRequestResponse({ description: 'Invalid data or database error' }) async register(@Body() registerDto: RegisterDto): Promise { try { @@ -101,19 +106,21 @@ export class AuthController { @Put('verify') @HttpCode(200) @UseGuards(JwtAuthGuard) - @ApiOperation({description: 'Verify the email of the user'}) + @ApiOperation({ description: 'Verify the email of the user' }) @ApiOkResponse({ description: 'Successfully verified' }) @ApiBadRequestResponse({ description: 'Invalid or expired token' }) - async verify(@Request() req: any, @Query('token') token: string): Promise { - if (await this.authService.verifyMail(req.user.id, token)) - return; - throw new BadRequestException("Invalid token. Expired or invalid."); + async verify( + @Request() req: any, + @Query('token') token: string, + ): Promise { + if (await this.authService.verifyMail(req.user.id, token)) return; + throw new BadRequestException('Invalid token. Expired or invalid.'); } @Put('reverify') @UseGuards(JwtAuthGuard) @HttpCode(200) - @ApiOperation({description: 'Resend the verification email'}) + @ApiOperation({ description: 'Resend the verification email' }) async reverify(@Request() req: any): Promise { const user = await this.usersService.user({ id: req.user.id }); if (!user) throw new BadRequestException('Invalid user'); @@ -277,42 +284,28 @@ export class AuthController { @UseGuards(JwtAuthGuard) @ApiBearerAuth() - @ApiOkResponse({ description: 'Successfully added liked song'}) + @ApiOkResponse({ description: 'Successfully added liked song' }) @ApiUnauthorizedResponse({ description: 'Invalid token' }) @Post('me/likes/:id') - addLikedSong( - @Request() req: any, - @Param('id') songId: number - ) { - return this.usersService.addLikedSong( - +req.user.id, - +songId, - ); + addLikedSong(@Request() req: any, @Param('id') songId: number) { + return this.usersService.addLikedSong(+req.user.id, +songId); } @UseGuards(JwtAuthGuard) @ApiBearerAuth() - @ApiOkResponse({ description: 'Successfully removed liked song'}) + @ApiOkResponse({ description: 'Successfully removed liked song' }) @ApiUnauthorizedResponse({ description: 'Invalid token' }) @Delete('me/likes/:id') - removeLikedSong( - @Request() req: any, - @Param('id') songId: number, - ) { - return this.usersService.removeLikedSong( - +req.user.id, - +songId, - ); + removeLikedSong(@Request() req: any, @Param('id') songId: number) { + return this.usersService.removeLikedSong(+req.user.id, +songId); } @UseGuards(JwtAuthGuard) @ApiBearerAuth() - @ApiOkResponse({ description: 'Successfully retrieved liked song'}) + @ApiOkResponse({ description: 'Successfully retrieved liked song' }) @ApiUnauthorizedResponse({ description: 'Invalid token' }) @Get('me/likes') - getLikedSongs( - @Request() req: any, - ) { - return this.usersService.getLikedSongs(+req.user.id) + getLikedSongs(@Request() req: any) { + return this.usersService.getLikedSongs(+req.user.id); } } diff --git a/back/src/auth/auth.service.ts b/back/src/auth/auth.service.ts index 4989675..fd31dbc 100644 --- a/back/src/auth/auth.service.ts +++ b/back/src/auth/auth.service.ts @@ -79,7 +79,7 @@ export class AuthService { console.log('Password reset token failure', e); return false; } - console.log(verified) + console.log(verified); await this.userService.updateUser({ where: { id: verified.userId }, data: { password: new_password }, diff --git a/back/src/lesson/lesson.controller.ts b/back/src/lesson/lesson.controller.ts index 2f8531b..83098a5 100644 --- a/back/src/lesson/lesson.controller.ts +++ b/back/src/lesson/lesson.controller.ts @@ -18,7 +18,7 @@ import { LessonService } from './lesson.service'; import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger'; import { Prisma, Skill } from '@prisma/client'; import { FilterQuery } from 'src/utils/filter.pipe'; -import { Lesson as _Lesson} from 'src/_gen/prisma-class/lesson'; +import { Lesson as _Lesson } from 'src/_gen/prisma-class/lesson'; export class Lesson { @ApiProperty() diff --git a/back/src/models/plage.ts b/back/src/models/plage.ts index d93db5c..1e6823a 100644 --- a/back/src/models/plage.ts +++ b/back/src/models/plage.ts @@ -3,14 +3,28 @@ */ import { Type, applyDecorators } from '@nestjs/common'; -import { ApiExtraModels, ApiOkResponse, ApiProperty, getSchemaPath } from '@nestjs/swagger'; +import { + ApiExtraModels, + ApiOkResponse, + ApiProperty, + getSchemaPath, +} from '@nestjs/swagger'; export class PlageMetadata { @ApiProperty() this: string; - @ApiProperty({ type: "string", nullable: true, description: "null if there is no next page, couldn't set it in swagger"}) + @ApiProperty({ + type: 'string', + nullable: true, + description: "null if there is no next page, couldn't set it in swagger", + }) next: string | null; - @ApiProperty({ type: "string", nullable: true, description: "null if there is no previous page, couldn't set it in swagger" }) + @ApiProperty({ + type: 'string', + nullable: true, + description: + "null if there is no previous page, couldn't set it in swagger", + }) previous: string | null; } @@ -55,22 +69,24 @@ export class Plage { } } -export const ApiOkResponsePlaginated = >(dataDto: DataDto) => - applyDecorators( - ApiExtraModels(Plage, dataDto), - ApiOkResponse({ - schema: { - allOf: [ - { $ref: getSchemaPath(Plage) }, - { - properties: { - data: { - type: 'array', - items: { $ref: getSchemaPath(dataDto) }, - }, - }, - }, - ], - }, - }) - ) \ No newline at end of file +export const ApiOkResponsePlaginated = >( + dataDto: DataDto, +) => + applyDecorators( + ApiExtraModels(Plage, dataDto), + ApiOkResponse({ + schema: { + allOf: [ + { $ref: getSchemaPath(Plage) }, + { + properties: { + data: { + type: 'array', + items: { $ref: getSchemaPath(dataDto) }, + }, + }, + }, + ], + }, + }), + ); diff --git a/back/src/search/search.controller.ts b/back/src/search/search.controller.ts index 9c54632..ac5d0f4 100644 --- a/back/src/search/search.controller.ts +++ b/back/src/search/search.controller.ts @@ -12,7 +12,13 @@ import { Request, UseGuards, } from '@nestjs/common'; -import { ApiOkResponse, ApiOperation, ApiParam, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; +import { + ApiOkResponse, + ApiOperation, + ApiParam, + ApiTags, + ApiUnauthorizedResponse, +} from '@nestjs/swagger'; import { Artist, Genre, Song } from '@prisma/client'; import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'; import { SearchSongDto } from './dto/search-song.dto'; @@ -27,9 +33,9 @@ export class SearchController { constructor(private readonly searchService: SearchService) {} @Get('songs/:query') - @ApiOkResponse({ type: _Song, isArray: true}) - @ApiOperation({ description: "Search a song"}) - @ApiUnauthorizedResponse({ description: "Invalid token"}) + @ApiOkResponse({ type: _Song, isArray: true }) + @ApiOperation({ description: 'Search a song' }) + @ApiUnauthorizedResponse({ description: 'Invalid token' }) @UseGuards(JwtAuthGuard) async searchSong( @Request() req: any, @@ -46,10 +52,13 @@ export class SearchController { @Get('genres/:query') @UseGuards(JwtAuthGuard) - @ApiUnauthorizedResponse({ description: "Invalid token"}) - @ApiOkResponse({ type: _Genre, isArray: true}) - @ApiOperation({ description: "Search a genre"}) - async searchGenre(@Request() req: any, @Param('query') query: string): Promise { + @ApiUnauthorizedResponse({ description: 'Invalid token' }) + @ApiOkResponse({ type: _Genre, isArray: true }) + @ApiOperation({ description: 'Search a genre' }) + 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(); @@ -61,10 +70,13 @@ export class SearchController { @Get('artists/:query') @UseGuards(JwtAuthGuard) - @ApiOkResponse({ type: _Artist, isArray: true}) - @ApiUnauthorizedResponse({ description: "Invalid token"}) - @ApiOperation({ description: "Search an artist"}) - async searchArtists(@Request() req: any, @Param('query') query: string): Promise { + @ApiOkResponse({ type: _Artist, isArray: true }) + @ApiUnauthorizedResponse({ description: 'Invalid token' }) + @ApiOperation({ description: 'Search an artist' }) + 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(); diff --git a/back/src/users/users.controller.ts b/back/src/users/users.controller.ts index 65db03d..54347b9 100644 --- a/back/src/users/users.controller.ts +++ b/back/src/users/users.controller.ts @@ -1,4 +1,11 @@ -import { Controller, Get, Post, Param, NotFoundException, Response } from '@nestjs/common'; +import { + Controller, + Get, + Post, + Param, + NotFoundException, + Response, +} from '@nestjs/common'; import { UsersService } from './users.service'; import { ApiNotFoundResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { User } from 'src/models/user'; @@ -22,7 +29,9 @@ export class UsersController { } @Get(':id/picture') - @ApiOkResponse({description: 'Return the profile picture of the requested user'}) + @ApiOkResponse({ + description: 'Return the profile picture of the requested user', + }) async getPicture(@Response() res: any, @Param('id') id: number) { return await this.usersService.getProfilePicture(+id, res); } diff --git a/back/src/users/users.service.ts b/back/src/users/users.service.ts index fd8fdcf..f0267ab 100644 --- a/back/src/users/users.service.ts +++ b/back/src/users/users.service.ts @@ -12,9 +12,7 @@ import fetch from 'node-fetch'; @Injectable() export class UsersService { - constructor( - private prisma: PrismaService, - ) {} + constructor(private prisma: PrismaService) {} async user( userWhereUniqueInput: Prisma.UserWhereUniqueInput, @@ -101,35 +99,21 @@ export class UsersService { resp.body!.pipe(res); } - async addLikedSong( - userId: number, - songId: number, - ) { - return this.prisma.likedSongs.create( - { - data: { songId: songId, userId: userId } - } - ) + async addLikedSong(userId: number, songId: number) { + return this.prisma.likedSongs.create({ + data: { songId: songId, userId: userId }, + }); } - async getLikedSongs( - userId: number, - ) { - return this.prisma.likedSongs.findMany( - { - where: { userId: userId }, - } - ) + async getLikedSongs(userId: number) { + return this.prisma.likedSongs.findMany({ + where: { userId: userId }, + }); } - async removeLikedSong( - userId: number, - songId: number, - ) { - return this.prisma.likedSongs.deleteMany( - { - where: { userId: userId, songId: songId }, - } - ) + async removeLikedSong(userId: number, songId: number) { + return this.prisma.likedSongs.deleteMany({ + where: { userId: userId, songId: songId }, + }); } }