fix: format

This commit is contained in:
GitBluub
2023-09-20 23:54:04 +02:00
parent 162fc9148f
commit 82403c811e
11 changed files with 107 additions and 75 deletions

View File

@@ -45,7 +45,7 @@ export class AuthController {
@Post('register')
async register(@Body() registerDto: RegisterDto): Promise<void> {
try {
const user = await this.usersService.createUser(registerDto)
const user = await this.usersService.createUser(registerDto);
await this.settingsService.createUserSetting(user.id);
} catch (e) {
console.error(e);
@@ -121,7 +121,8 @@ export class AuthController {
@Patch('me/settings')
udpateSettings(
@Request() req: any,
@Body() settingUserDto: UpdateSettingDto): Promise<Setting> {
@Body() settingUserDto: UpdateSettingDto,
): Promise<Setting> {
return this.settingsService.updateUserSettings({
where: { userId: +req.user.id },
data: settingUserDto,
@@ -134,7 +135,9 @@ export class AuthController {
@ApiUnauthorizedResponse({ description: 'Invalid token' })
@Get('me/settings')
async getSettings(@Request() req: any): Promise<Setting> {
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;
}

View File

@@ -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';
}

View File

@@ -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<string, number>
difficulties: Record<string, number>;
@ApiProperty()
info: Record<string, number>
info: Record<string, number>;
}

View File

@@ -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
@Body() record: SearchHistoryDto,
): Promise<void> {
await this.historyService.createSearchHistoryRecord(req.user.id, { query: record.query, type: record.type });
await this.historyService.createSearchHistoryRecord(req.user.id, {
query: record.query,
type: record.type,
});
}
}

View File

@@ -74,7 +74,7 @@ export class HistoryService {
async createSearchHistoryRecord(
userID: number,
{ query, type }: SearchHistoryDto
{ query, type }: SearchHistoryDto,
): Promise<SearchHistory> {
return this.prisma.searchHistory.create({
data: {

View File

@@ -2,7 +2,13 @@ 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 {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
ValidationPipe,
} from '@nestjs/common';
import { RequestLogger, RequestLoggerOptions } from 'json-logger-service';
import { tap } from 'rxjs';
@@ -20,25 +26,31 @@ export class AspectLogger implements NestInterceptor {
params,
query,
body,
"userId": user?.id ?? "not logged in",
"username": user?.username ?? "not logged in",
userId: user?.id ?? 'not logged in',
username: user?.username ?? 'not logged in',
};
return next.handle().pipe(
tap((data) =>
console.log(JSON.stringify({
console.log(
JSON.stringify({
...toPrint,
statusCode,
data
}))
)
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);

View File

@@ -25,7 +25,10 @@ export class SearchController {
@Get('songs/:query')
@UseGuards(JwtAuthGuard)
async searchSong(@Request() req: any, @Param('query') query: string): Promise<Song[] | null> {
async searchSong(
@Request() req: any,
@Param('query') query: string,
): Promise<Song[] | null> {
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<Genre[] | null> {
async searchGenre(
@Request() req: any,
@Param('query') query: string,
): Promise<Genre[] | null> {
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<Artist[] | null> {
async searchArtists(
@Request() req: any,
@Param('query') query: string,
): Promise<Artist[] | null> {
try {
const ret = await this.searchService.artistByGuess(query, req.user?.id);
if (!ret.length) throw new NotFoundException();

View File

@@ -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<Song[]> {
return this.prisma.song.findMany({

View File

@@ -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<UserSettings> {
async deleteUserSettings(
where: Prisma.UserSettingsWhereUniqueInput,
): Promise<UserSettings> {
return this.prisma.userSettings.delete({
where,
});