prisma migration + back auth/me/likes + front API add and get methods for liked song

This commit is contained in:
danis
2023-08-30 13:06:25 +02:00
parent a3676fabf8
commit c81f8df61c
9 changed files with 998 additions and 7339 deletions
+873 -7337
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `likedSongs` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "likedSongs" JSONB NOT NULL DEFAULT '{}'::jsonb;
+1
View File
@@ -21,6 +21,7 @@ model User {
SongHistory SongHistory[]
searchHistory SearchHistory[]
settings UserSettings?
likedSongs Json?
}
model UserSettings {
+17
View File
@@ -18,6 +18,7 @@ import {
HttpStatus,
ParseFilePipeBuilder,
Response,
Param,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { JwtAuthGuard } from './jwt-auth.guard';
@@ -199,4 +200,20 @@ export class AuthController {
if (!result) throw new NotFoundException();
return result;
}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOkResponse({ description: 'Successfully added liked song'})
@ApiUnauthorizedResponse({ description: 'Invalid token' })
@Post('me/likes:id')
addLikedSong(
@Request() req: any,
@Body() data: any,
) {
return this.usersService.addLikedSong(
req.user.id,
data.songId,
);
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { Controller, Get, Param, NotFoundException, Response } from '@nestjs/common';
import { Controller, Get, Post, Param, NotFoundException, Response } from '@nestjs/common';
import { UsersService } from './users.service';
import { ApiNotFoundResponse, ApiTags } from '@nestjs/swagger';
import { User } from 'src/models/user';
+17
View File
@@ -99,4 +99,21 @@ export class UsersService {
resp.headers.set(k, v);
resp.body!.pipe(res);
}
async addLikedSong(
where: Prisma.UserWhereUniqueInput,
songId: number,
) {
return this.prisma.user.update({
where,
data: {
likedSongs: {
merde: {
songId: songId,
time: Date()
}
}
}
})
}
}