diff --git a/back/src/artist/artist.module.ts b/back/src/artist/artist.module.ts index ea15b8f..69a6335 100644 --- a/back/src/artist/artist.module.ts +++ b/back/src/artist/artist.module.ts @@ -2,7 +2,7 @@ import { Module } from "@nestjs/common"; import { PrismaModule } from "src/prisma/prisma.module"; import { ArtistController } from "./artist.controller"; import { ArtistService } from "./artist.service"; -import { SearchModule } from 'src/search/search.module'; +import { SearchModule } from "src/search/search.module"; @Module({ imports: [PrismaModule, SearchModule], diff --git a/back/src/artist/artist.service.ts b/back/src/artist/artist.service.ts index e8bb52c..40e253f 100644 --- a/back/src/artist/artist.service.ts +++ b/back/src/artist/artist.service.ts @@ -1,7 +1,7 @@ -import { Injectable } from '@nestjs/common'; -import { Prisma, Artist } from '@prisma/client'; -import { PrismaService } from 'src/prisma/prisma.service'; -import { MeiliService } from 'src/search/meilisearch.service'; +import { Injectable } from "@nestjs/common"; +import { Prisma, Artist } from "@prisma/client"; +import { PrismaService } from "src/prisma/prisma.service"; +import { MeiliService } from "src/search/meilisearch.service"; @Injectable() export class ArtistService { @@ -14,7 +14,7 @@ export class ArtistService { const ret = await this.prisma.artist.create({ data, }); - await this.search.index('artists').addDocuments([ret]); + await this.search.index("artists").addDocuments([ret]); return ret; } @@ -51,7 +51,7 @@ export class ArtistService { const ret = await this.prisma.artist.delete({ where, }); - await this.search.index('artists').deleteDocument(ret.id); - return ret + await this.search.index("artists").deleteDocument(ret.id); + return ret; } } diff --git a/back/src/auth/apikey-auth.guard.ts b/back/src/auth/apikey-auth.guard.ts index 936ddde..3ecf31e 100644 --- a/back/src/auth/apikey-auth.guard.ts +++ b/back/src/auth/apikey-auth.guard.ts @@ -2,4 +2,4 @@ import { Injectable } from "@nestjs/common"; import { AuthGuard } from "@nestjs/passport"; @Injectable() -export class ApiKeyAuthGuard extends AuthGuard('api-key') {} \ No newline at end of file +export class ApiKeyAuthGuard extends AuthGuard("api-key") {} diff --git a/back/src/auth/apikey.strategy.ts b/back/src/auth/apikey.strategy.ts index 6b06170..919774d 100644 --- a/back/src/auth/apikey.strategy.ts +++ b/back/src/auth/apikey.strategy.ts @@ -1,28 +1,31 @@ - -import { Injectable, UnauthorizedException } from '@nestjs/common'; -import { AuthService } from './auth.service'; -import { PassportStrategy } from '@nestjs/passport'; -import Strategy from 'passport-headerapikey'; -import { ConfigService } from '@nestjs/config'; - +import { Injectable, UnauthorizedException } from "@nestjs/common"; +import { AuthService } from "./auth.service"; +import { PassportStrategy } from "@nestjs/passport"; +import Strategy from "passport-headerapikey"; +import { ConfigService } from "@nestjs/config"; @Injectable() -export class HeaderApiKeyStrategy extends PassportStrategy(Strategy, 'api-key') { - constructor( - private readonly configService: ConfigService - ) { - super({ header: 'Authorization', prefix: 'API Key ' }, - true, - async (apiKey, done) => { - return this.validate(apiKey, done); - }); - } +export class HeaderApiKeyStrategy extends PassportStrategy( + Strategy, + "api-key", +) { + constructor(private readonly configService: ConfigService) { + super( + { header: "Authorization", prefix: "API Key " }, + true, + async (apiKey, done) => { + return this.validate(apiKey, done); + }, + ); + } - public validate = (apiKey: string, done: (error: Error, data) => {}) => { - if (this.configService.get('API_KEYS')?.split(',').includes(apiKey)) { - //@ts-expect-error - done(null, true); - } - done(new UnauthorizedException(), null); - } -} \ No newline at end of file + public validate = (apiKey: string, done: (error: Error, data) => {}) => { + if ( + this.configService.get("API_KEYS")?.split(",").includes(apiKey) + ) { + //@ts-expect-error + done(null, true); + } + done(new UnauthorizedException(), null); + }; +} diff --git a/back/src/auth/auth.service.ts b/back/src/auth/auth.service.ts index b65e526..05a3145 100644 --- a/back/src/auth/auth.service.ts +++ b/back/src/auth/auth.service.ts @@ -15,9 +15,8 @@ export class AuthService { validateApiKey(apikey: string): boolean { if (process.env.API_KEYS == null) return false; - const keys = process.env.API_KEYS.split(','); + const keys = process.env.API_KEYS.split(","); return keys.includes(apikey); - } async validateUser( diff --git a/back/src/models/user.ts b/back/src/models/user.ts index 68b70ff..f1cb446 100644 --- a/back/src/models/user.ts +++ b/back/src/models/user.ts @@ -11,6 +11,6 @@ export class User { isGuest: boolean; @ApiProperty() partyPlayed: number; - @ApiProperty() - totalScore: number; + @ApiProperty() + totalScore: number; } diff --git a/back/src/scores/scores.module.ts b/back/src/scores/scores.module.ts index 2ad0384..353b7d4 100644 --- a/back/src/scores/scores.module.ts +++ b/back/src/scores/scores.module.ts @@ -1,7 +1,7 @@ -import { Module } from '@nestjs/common'; -import { ScoresService } from './scores.service'; -import { ScoresController } from './scores.controller'; -import { PrismaModule } from 'src/prisma/prisma.module'; +import { Module } from "@nestjs/common"; +import { ScoresService } from "./scores.service"; +import { ScoresController } from "./scores.controller"; +import { PrismaModule } from "src/prisma/prisma.module"; @Module({ imports: [PrismaModule], diff --git a/back/src/scores/scores.service.ts b/back/src/scores/scores.service.ts index c48f229..8bdada7 100644 --- a/back/src/scores/scores.service.ts +++ b/back/src/scores/scores.service.ts @@ -1,19 +1,17 @@ -import { Injectable } from '@nestjs/common'; -import { User } from '@prisma/client'; -import { PrismaService } from 'src/prisma/prisma.service'; +import { Injectable } from "@nestjs/common"; +import { User } from "@prisma/client"; +import { PrismaService } from "src/prisma/prisma.service"; @Injectable() export class ScoresService { - constructor( - private prisma: PrismaService, - ) {} + constructor(private prisma: PrismaService) {} async topTwenty(): Promise { return this.prisma.user.findMany({ orderBy: { - totalScore: 'desc', + totalScore: "desc", }, take: 20, }); } -} \ No newline at end of file +} diff --git a/back/src/search/meilisearch.service.ts b/back/src/search/meilisearch.service.ts index 4d49dcb..09b4e75 100644 --- a/back/src/search/meilisearch.service.ts +++ b/back/src/search/meilisearch.service.ts @@ -1,29 +1,29 @@ -import { Injectable, OnModuleInit } from '@nestjs/common'; -import MeiliSearch, { DocumentOptions, Settings } from 'meilisearch'; +import { Injectable, OnModuleInit } from "@nestjs/common"; +import MeiliSearch, { DocumentOptions, Settings } from "meilisearch"; @Injectable() export class MeiliService extends MeiliSearch implements OnModuleInit { constructor() { super({ - host: process.env.MEILI_ADDR || 'http://meilisearch:7700', + host: process.env.MEILI_ADDR || "http://meilisearch:7700", apiKey: process.env.MEILI_MASTER_KEY, }); } async definedIndex(uid: string, opts: Settings) { - let task = await this.createIndex(uid, { primaryKey: 'id' }); + let task = await this.createIndex(uid, { primaryKey: "id" }); await this.waitForTask(task.taskUid); task = await this.index(uid).updateSettings(opts); await this.waitForTask(task.taskUid); } async onModuleInit() { - await this.definedIndex('songs', { - searchableAttributes: ['name', 'artist'], - filterableAttributes: ['artistId', 'genreId'], + await this.definedIndex("songs", { + searchableAttributes: ["name", "artist"], + filterableAttributes: ["artistId", "genreId"], }); - await this.definedIndex('artists', { - searchableAttributes: ['name'], + await this.definedIndex("artists", { + searchableAttributes: ["name"], }); } } diff --git a/back/src/search/search.controller.ts b/back/src/search/search.controller.ts index 563ec9e..5b51e25 100644 --- a/back/src/search/search.controller.ts +++ b/back/src/search/search.controller.ts @@ -39,12 +39,12 @@ export class SearchController { @ApiUnauthorizedResponse({ description: "Invalid token" }) async searchSong( @Request() req: any, - @Param('query') query: string, - @Query('artistId') artistId: number, - @Query('genreId') genreId: number, - @Query('include') include: string, - @Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number, - @Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number, + @Param("query") query: string, + @Query("artistId") artistId: number, + @Query("genreId") genreId: number, + @Query("include") include: string, + @Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number, + @Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number, ): Promise { return await this.searchService.searchSong( query, diff --git a/back/src/search/search.service.ts b/back/src/search/search.service.ts index 57fcabd..3da7e17 100644 --- a/back/src/search/search.service.ts +++ b/back/src/search/search.service.ts @@ -38,7 +38,7 @@ export class SearchService { filter: [ ...(artistId ? [`artistId = ${artistId}`] : []), ...(genreId ? [`genreId = ${genreId}`] : []), - ].join(' AND '), + ].join(" AND "), }) ).hits.map((x) => x.id); diff --git a/back/src/song/song.module.ts b/back/src/song/song.module.ts index 3c490b3..273550b 100644 --- a/back/src/song/song.module.ts +++ b/back/src/song/song.module.ts @@ -1,9 +1,9 @@ -import { Module } from '@nestjs/common'; -import { SongService } from './song.service'; -import { SongController } from './song.controller'; -import { PrismaModule } from 'src/prisma/prisma.module'; -import { HistoryModule } from 'src/history/history.module'; -import { SearchModule } from 'src/search/search.module'; +import { Module } from "@nestjs/common"; +import { SongService } from "./song.service"; +import { SongController } from "./song.controller"; +import { PrismaModule } from "src/prisma/prisma.module"; +import { HistoryModule } from "src/history/history.module"; +import { SearchModule } from "src/search/search.module"; @Module({ imports: [PrismaModule, HistoryModule, SearchModule], diff --git a/back/src/users/users.service.ts b/back/src/users/users.service.ts index 22021b4..b18b47a 100644 --- a/back/src/users/users.service.ts +++ b/back/src/users/users.service.ts @@ -118,17 +118,14 @@ export class UsersService { }); } - async addScore( - where: number, - score: number, - ) { + async addScore(where: number, score: number) { return this.prisma.user.update({ - where: { id: where }, - data: { - partyPlayed: { - increment: score, - }, + where: { id: where }, + data: { + partyPlayed: { + increment: score, }, - }); + }, + }); } }