prisma migration + back auth/me/likes + front API add and get methods for liked song
This commit is contained in:
Generated
+873
-7337
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;
|
||||
@@ -21,6 +21,7 @@ model User {
|
||||
SongHistory SongHistory[]
|
||||
searchHistory SearchHistory[]
|
||||
settings UserSettings?
|
||||
likedSongs Json?
|
||||
}
|
||||
|
||||
model UserSettings {
|
||||
|
||||
@@ -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,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';
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user