From 06bfc181c70f20d90db0b1dec031c04038a2d266 Mon Sep 17 00:00:00 2001 From: danis Date: Sun, 8 Oct 2023 21:53:58 +0200 Subject: [PATCH] commit score on end of play --- back/src/auth/auth.controller.ts | 2 +- back/src/users/users.service.ts | 14 ++++++++++++++ front/API.ts | 7 +++++++ front/views/PlayView.tsx | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/back/src/auth/auth.controller.ts b/back/src/auth/auth.controller.ts index f977f69..c6ca1dc 100644 --- a/back/src/auth/auth.controller.ts +++ b/back/src/auth/auth.controller.ts @@ -299,7 +299,7 @@ export class AuthController { @ApiBearerAuth() @ApiOkResponse({ description: 'Successfully added score'}) @ApiUnauthorizedResponse({ description: 'Invalid token' }) - @Get('me/score/:score') + @Patch('me/score/:score') addScore( @Request() req: any, @Param('id') score: number, diff --git a/back/src/users/users.service.ts b/back/src/users/users.service.ts index 53c876c..1391d53 100644 --- a/back/src/users/users.service.ts +++ b/back/src/users/users.service.ts @@ -130,4 +130,18 @@ export class UsersService { } ) } + + async addScore( + where: Prisma.UserWhereUniqueInput, + score: number, + ) { + return this.prisma.user.update({ + where, + data: { + score: { + increment: score, + }, + }, + }); + } } diff --git a/front/API.ts b/front/API.ts index 5dcf445..f15345d 100644 --- a/front/API.ts +++ b/front/API.ts @@ -697,4 +697,11 @@ export default class API { ), }; } + + public static async updateUserTotalScore(score: number): Promise { + await API.fetch({ + route: `/auth/me/score/${score}`, + method: 'PATCH', + }); + } } diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index 92c9fd2..9498e1f 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -145,6 +145,7 @@ const PlayView = ({ songId, type, route }: RouteProps) => { type: 'end', }) ); + API.updateUserTotalScore(score); }; const onMIDISuccess = (access: MIDIAccess) => {