Format code with prettier

This commit is contained in:
2023-12-04 13:27:41 +01:00
parent 3becdcff46
commit 14e241db37
75 changed files with 441 additions and 442 deletions

View File

@@ -12,23 +12,23 @@ import {
Query,
Req,
UseGuards,
} from '@nestjs/common';
import { ApiOkResponsePlaginated, Plage } from 'src/models/plage';
import { CreateAlbumDto } from './dto/create-album.dto';
import { AlbumService } from './album.service';
import { Request } from 'express';
import { Prisma, Album } from '@prisma/client';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { FilterQuery } from 'src/utils/filter.pipe';
import { Album as _Album } from 'src/_gen/prisma-class/album';
import { IncludeMap, mapInclude } from 'src/utils/include';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
} from "@nestjs/common";
import { ApiOkResponsePlaginated, Plage } from "src/models/plage";
import { CreateAlbumDto } from "./dto/create-album.dto";
import { AlbumService } from "./album.service";
import { Request } from "express";
import { Prisma, Album } from "@prisma/client";
import { ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger";
import { FilterQuery } from "src/utils/filter.pipe";
import { Album as _Album } from "src/_gen/prisma-class/album";
import { IncludeMap, mapInclude } from "src/utils/include";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
@Controller('album')
@ApiTags('album')
@Controller("album")
@ApiTags("album")
@UseGuards(JwtAuthGuard)
export class AlbumController {
static filterableFields: string[] = ['+id', 'name', '+artistId'];
static filterableFields: string[] = ["+id", "name", "+artistId"];
static includableFields: IncludeMap<Prisma.AlbumInclude> = {
artist: true,
Song: true,
@@ -38,7 +38,7 @@ export class AlbumController {
@Post()
@ApiOperation({
description: 'Register a new album, should not be used by frontend',
description: "Register a new album, should not be used by frontend",
})
async create(@Body() createAlbumDto: CreateAlbumDto) {
try {
@@ -55,26 +55,26 @@ export class AlbumController {
}
}
@Delete(':id')
@ApiOperation({ description: 'Delete an album by id' })
async remove(@Param('id', ParseIntPipe) id: number) {
@Delete(":id")
@ApiOperation({ description: "Delete an album by id" })
async remove(@Param("id", ParseIntPipe) id: number) {
try {
return await this.albumService.deleteAlbum({ id });
} catch {
throw new NotFoundException('Invalid ID');
throw new NotFoundException("Invalid ID");
}
}
@Get()
@ApiOkResponsePlaginated(_Album)
@ApiOperation({ description: 'Get all albums paginated' })
@ApiOperation({ description: "Get all albums paginated" })
async findAll(
@Req() req: Request,
@FilterQuery(AlbumController.filterableFields)
where: Prisma.AlbumWhereInput,
@Query('include') include: string,
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
@Query("include") include: string,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Plage<Album>> {
const ret = await this.albumService.albums({
skip,
@@ -85,20 +85,20 @@ export class AlbumController {
return new Plage(ret, req);
}
@Get(':id')
@ApiOperation({ description: 'Get an album by id' })
@Get(":id")
@ApiOperation({ description: "Get an album by id" })
@ApiOkResponse({ type: _Album })
async findOne(
@Req() req: Request,
@Query('include') include: string,
@Param('id', ParseIntPipe) id: number,
@Query("include") include: string,
@Param("id", ParseIntPipe) id: number,
) {
const res = await this.albumService.album(
{ id },
mapInclude(include, req, AlbumController.includableFields),
);
if (res === null) throw new NotFoundException('Album not found');
if (res === null) throw new NotFoundException("Album not found");
return res;
}
}

View File

@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { AlbumController } from './album.controller';
import { AlbumService } from './album.service';
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/prisma/prisma.module";
import { AlbumController } from "./album.controller";
import { AlbumService } from "./album.service";
@Module({
imports: [PrismaModule],

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Prisma, Album } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Prisma, Album } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class AlbumService {

View File

@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
export class CreateAlbumDto {
@IsNotEmpty()

View File

@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Test, TestingModule } from "@nestjs/testing";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
describe('AppController', () => {
describe("AppController", () => {
let appController: AppController;
beforeEach(async () => {
@@ -14,9 +14,9 @@ describe('AppController', () => {
appController = app.get<AppController>(AppController);
});
describe('root', () => {
describe("root", () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
expect(appController.getHello()).toBe("Hello World!");
});
});
});

View File

@@ -1,6 +1,6 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { ApiOkResponse } from '@nestjs/swagger';
import { Controller, Get } from "@nestjs/common";
import { AppService } from "./app.service";
import { ApiOkResponse } from "@nestjs/swagger";
@Controller()
export class AppController {
@@ -8,7 +8,7 @@ export class AppController {
@Get()
@ApiOkResponse({
description: 'Return a hello world message, used as a health route',
description: "Return a hello world message, used as a health route",
})
getHello(): string {
return this.appService.getHello();

View File

@@ -1,20 +1,20 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PrismaService } from './prisma/prisma.service';
import { UsersModule } from './users/users.module';
import { PrismaModule } from './prisma/prisma.module';
import { AuthModule } from './auth/auth.module';
import { SongModule } from './song/song.module';
import { LessonModule } from './lesson/lesson.module';
import { SettingsModule } from './settings/settings.module';
import { ArtistService } from './artist/artist.service';
import { GenreModule } from './genre/genre.module';
import { ArtistModule } from './artist/artist.module';
import { AlbumModule } from './album/album.module';
import { SearchModule } from './search/search.module';
import { HistoryModule } from './history/history.module';
import { MailerModule } from '@nestjs-modules/mailer';
import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { PrismaService } from "./prisma/prisma.service";
import { UsersModule } from "./users/users.module";
import { PrismaModule } from "./prisma/prisma.module";
import { AuthModule } from "./auth/auth.module";
import { SongModule } from "./song/song.module";
import { LessonModule } from "./lesson/lesson.module";
import { SettingsModule } from "./settings/settings.module";
import { ArtistService } from "./artist/artist.service";
import { GenreModule } from "./genre/genre.module";
import { ArtistModule } from "./artist/artist.module";
import { AlbumModule } from "./album/album.module";
import { SearchModule } from "./search/search.module";
import { HistoryModule } from "./history/history.module";
import { MailerModule } from "@nestjs-modules/mailer";
@Module({
imports: [

View File

@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { Injectable } from "@nestjs/common";
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return "Hello World!";
}
}

View File

@@ -14,30 +14,30 @@ import {
Req,
StreamableFile,
UseGuards,
} from '@nestjs/common';
import { ApiOkResponsePlaginated, Plage } from 'src/models/plage';
import { CreateArtistDto } from './dto/create-artist.dto';
import { Request } from 'express';
import { ArtistService } from './artist.service';
import { Prisma, Artist } from '@prisma/client';
} from "@nestjs/common";
import { ApiOkResponsePlaginated, Plage } from "src/models/plage";
import { CreateArtistDto } from "./dto/create-artist.dto";
import { Request } from "express";
import { ArtistService } from "./artist.service";
import { Prisma, Artist } from "@prisma/client";
import {
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';
import { createReadStream, existsSync } from 'fs';
import { FilterQuery } from 'src/utils/filter.pipe';
import { Artist as _Artist } from 'src/_gen/prisma-class/artist';
import { IncludeMap, mapInclude } from 'src/utils/include';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { Public } from 'src/auth/public';
} from "@nestjs/swagger";
import { createReadStream, existsSync } from "fs";
import { FilterQuery } from "src/utils/filter.pipe";
import { Artist as _Artist } from "src/_gen/prisma-class/artist";
import { IncludeMap, mapInclude } from "src/utils/include";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
import { Public } from "src/auth/public";
@Controller('artist')
@ApiTags('artist')
@Controller("artist")
@ApiTags("artist")
@UseGuards(JwtAuthGuard)
export class ArtistController {
static filterableFields = ['+id', 'name'];
static filterableFields = ["+id", "name"];
static includableFields: IncludeMap<Prisma.ArtistInclude> = {
Song: true,
Album: true,
@@ -47,7 +47,7 @@ export class ArtistController {
@Post()
@ApiOperation({
description: 'Register a new artist, should not be used by frontend',
description: "Register a new artist, should not be used by frontend",
})
async create(@Body() dto: CreateArtistDto) {
try {
@@ -57,26 +57,26 @@ export class ArtistController {
}
}
@Delete(':id')
@ApiOperation({ description: 'Delete an artist by id' })
async remove(@Param('id', ParseIntPipe) id: number) {
@Delete(":id")
@ApiOperation({ description: "Delete an artist by id" })
async remove(@Param("id", ParseIntPipe) id: number) {
try {
return await this.service.delete({ id });
} catch {
throw new NotFoundException('Invalid ID');
throw new NotFoundException("Invalid ID");
}
}
@Get(':id/illustration')
@Get(":id/illustration")
@ApiOperation({ description: "Get an artist's illustration" })
@ApiNotFoundResponse({ description: 'Artist or illustration not found' })
@ApiNotFoundResponse({ description: "Artist or illustration not found" })
@Public()
async getIllustration(@Param('id', ParseIntPipe) id: number) {
async getIllustration(@Param("id", ParseIntPipe) id: number) {
const artist = await this.service.get({ id });
if (!artist) throw new NotFoundException('Artist not found');
if (!artist) throw new NotFoundException("Artist not found");
const path = `/assets/artists/${artist.name}/illustration.png`;
if (!existsSync(path))
throw new NotFoundException('Illustration not found');
throw new NotFoundException("Illustration not found");
try {
const file = createReadStream(path);
@@ -87,15 +87,15 @@ export class ArtistController {
}
@Get()
@ApiOperation({ description: 'Get all artists paginated' })
@ApiOperation({ description: "Get all artists paginated" })
@ApiOkResponsePlaginated(_Artist)
async findAll(
@Req() req: Request,
@FilterQuery(ArtistController.filterableFields)
where: Prisma.ArtistWhereInput,
@Query('include') include: string,
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
@Query("include") include: string,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Plage<Artist>> {
const ret = await this.service.list({
skip,
@@ -106,20 +106,20 @@ export class ArtistController {
return new Plage(ret, req);
}
@Get(':id')
@ApiOperation({ description: 'Get an artist by id' })
@Get(":id")
@ApiOperation({ description: "Get an artist by id" })
@ApiOkResponse({ type: _Artist })
async findOne(
@Req() req: Request,
@Query('include') include: string,
@Param('id', ParseIntPipe) id: number,
@Query("include") include: string,
@Param("id", ParseIntPipe) id: number,
) {
const res = await this.service.get(
{ id },
mapInclude(include, req, ArtistController.includableFields),
);
if (res === null) throw new NotFoundException('Artist not found');
if (res === null) throw new NotFoundException("Artist not found");
return res;
}
}

View File

@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { ArtistController } from './artist.controller';
import { ArtistService } from './artist.service';
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/prisma/prisma.module";
import { ArtistController } from "./artist.controller";
import { ArtistService } from "./artist.service";
@Module({
imports: [PrismaModule],

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Prisma, Artist } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Prisma, Artist } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class ArtistService {

View File

@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
export class CreateArtistDto {
@IsNotEmpty()

View File

@@ -58,12 +58,12 @@ export class AuthController {
private authService: AuthService,
private usersService: UsersService,
private settingsService: SettingsService,
) { }
) {}
@Get("login/google")
@UseGuards(AuthGuard("google"))
@ApiOperation({ description: "Redirect to google login page" })
googleLogin() { }
googleLogin() {}
@Get("logged/google")
@ApiOperation({

View File

@@ -1,15 +1,15 @@
import { Module } from '@nestjs/common';
import { UsersModule } from 'src/users/users.module';
import { AuthService } from './auth.service';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from './auth.controller';
import { LocalStrategy } from './local.strategy';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule } from '@nestjs/config';
import { ConfigService } from '@nestjs/config';
import { JwtStrategy } from './jwt.strategy';
import { SettingsModule } from 'src/settings/settings.module';
import { GoogleStrategy } from './google.strategy';
import { Module } from "@nestjs/common";
import { UsersModule } from "src/users/users.module";
import { AuthService } from "./auth.service";
import { PassportModule } from "@nestjs/passport";
import { AuthController } from "./auth.controller";
import { LocalStrategy } from "./local.strategy";
import { JwtModule } from "@nestjs/jwt";
import { ConfigModule } from "@nestjs/config";
import { ConfigService } from "@nestjs/config";
import { JwtStrategy } from "./jwt.strategy";
import { SettingsModule } from "src/settings/settings.module";
import { GoogleStrategy } from "./google.strategy";
@Module({
imports: [
@@ -20,8 +20,8 @@ import { GoogleStrategy } from './google.strategy';
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
secret: configService.get('JWT_SECRET'),
signOptions: { expiresIn: '365d' },
secret: configService.get("JWT_SECRET"),
signOptions: { expiresIn: "365d" },
}),
inject: [ConfigService],
}),

View File

@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { UsersService } from '../users/users.service';
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcryptjs';
import PayloadInterface from './interface/payload.interface';
import { User } from 'src/models/user';
import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from "@nestjs/common";
import { UsersService } from "../users/users.service";
import { JwtService } from "@nestjs/jwt";
import * as bcrypt from "bcryptjs";
import PayloadInterface from "./interface/payload.interface";
import { User } from "src/models/user";
import { MailerService } from "@nestjs-modules/mailer";
@Injectable()
export class AuthService {
constructor(
@@ -36,37 +36,37 @@ export class AuthService {
}
async sendVerifyMail(user: User) {
if (process.env.IGNORE_MAILS === 'true') return;
if (process.env.IGNORE_MAILS === "true") return;
if (user.email == null) return;
console.log('Sending verification mail to', user.email);
console.log("Sending verification mail to", user.email);
const token = await this.jwtService.signAsync(
{
userId: user.id,
},
{ expiresIn: '10h' },
{ expiresIn: "10h" },
);
await this.emailService.sendMail({
to: user.email,
from: 'chromacase@octohub.app',
subject: 'Mail verification for Chromacase',
from: "chromacase@octohub.app",
subject: "Mail verification for Chromacase",
html: `To verify your mail, please click on this <a href="${process.env.PUBLIC_URL}/verify?token=${token}">link</a>.`,
});
}
async sendPasswordResetMail(user: User) {
if (process.env.IGNORE_MAILS === 'true') return;
if (process.env.IGNORE_MAILS === "true") return;
if (user.email == null) return;
console.log('Sending password reset mail to', user.email);
console.log("Sending password reset mail to", user.email);
const token = await this.jwtService.signAsync(
{
userId: user.id,
},
{ expiresIn: '10h' },
{ expiresIn: "10h" },
);
await this.emailService.sendMail({
to: user.email,
from: 'chromacase@octohub.app',
subject: 'Password reset for Chromacase',
from: "chromacase@octohub.app",
subject: "Password reset for Chromacase",
html: `To reset your password, please click on this <a href="${process.env.PUBLIC_URL}/password_reset?token=${token}">link</a>.`,
});
}
@@ -76,7 +76,7 @@ export class AuthService {
try {
verified = await this.jwtService.verifyAsync(token);
} catch (e) {
console.log('Password reset token failure', e);
console.log("Password reset token failure", e);
return false;
}
console.log(verified);
@@ -91,7 +91,7 @@ export class AuthService {
try {
await this.jwtService.verifyAsync(token);
} catch (e) {
console.log('Verify mail token failure', e);
console.log("Verify mail token failure", e);
return false;
}
await this.userService.updateUser({

View File

@@ -1,11 +1,11 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
@Injectable()
export class Constants {
constructor(private configService: ConfigService) {}
getSecret = () => {
return this.configService.get('JWT_SECRET');
return this.configService.get("JWT_SECRET");
};
}

View File

@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
export class LoginDto {
@ApiProperty()

View File

@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
export class PasswordResetDto {
@ApiProperty()

View File

@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
export class Profile {
@ApiProperty()

View File

@@ -1,5 +1,5 @@
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
export class RegisterDto {
@ApiProperty()

View File

@@ -1,7 +1,7 @@
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
import { Injectable } from '@nestjs/common';
import { User } from '@prisma/client';
import { PassportStrategy } from "@nestjs/passport";
import { Strategy, VerifyCallback } from "passport-google-oauth20";
import { Injectable } from "@nestjs/common";
import { User } from "@prisma/client";
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy) {
@@ -10,7 +10,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
scope: ['email', 'profile'],
scope: ["email", "profile"],
});
}

View File

@@ -1,10 +1,10 @@
import { ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { IS_PUBLIC_KEY } from './public';
import { ExecutionContext, Injectable } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { AuthGuard } from "@nestjs/passport";
import { IS_PUBLIC_KEY } from "./public";
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
export class JwtAuthGuard extends AuthGuard("jwt") {
constructor(private reflector: Reflector) {
super();
}

View File

@@ -1,7 +1,7 @@
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ExtractJwt, Strategy } from "passport-jwt";
import { PassportStrategy } from "@nestjs/passport";
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
@@ -9,7 +9,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get('JWT_SECRET'),
secretOrKey: configService.get("JWT_SECRET"),
});
}

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Injectable } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
@Injectable()
export class LocalAuthGuard extends AuthGuard('local') {}
export class LocalAuthGuard extends AuthGuard("local") {}

View File

@@ -1,8 +1,8 @@
import { Strategy } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthService } from './auth.service';
import PayloadInterface from './interface/payload.interface';
import { Strategy } from "passport-local";
import { PassportStrategy } from "@nestjs/passport";
import { Injectable, UnauthorizedException } from "@nestjs/common";
import { AuthService } from "./auth.service";
import PayloadInterface from "./interface/payload.interface";
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class JwtToken {
@ApiProperty()

View File

@@ -1,4 +1,4 @@
import { SetMetadata } from '@nestjs/common';
import { SetMetadata } from "@nestjs/common";
export const IS_PUBLIC_KEY = 'isPublic';
export const IS_PUBLIC_KEY = "isPublic";
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

View File

@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
export class CreateGenreDto {
@IsNotEmpty()

View File

@@ -14,25 +14,25 @@ import {
Req,
StreamableFile,
UseGuards,
} from '@nestjs/common';
import { ApiOkResponsePlaginated, Plage } from 'src/models/plage';
import { CreateGenreDto } from './dto/create-genre.dto';
import { Request } from 'express';
import { GenreService } from './genre.service';
import { Prisma, Genre } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { createReadStream, existsSync } from 'fs';
import { FilterQuery } from 'src/utils/filter.pipe';
import { Genre as _Genre } from 'src/_gen/prisma-class/genre';
import { IncludeMap, mapInclude } from 'src/utils/include';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { Public } from 'src/auth/public';
} from "@nestjs/common";
import { ApiOkResponsePlaginated, Plage } from "src/models/plage";
import { CreateGenreDto } from "./dto/create-genre.dto";
import { Request } from "express";
import { GenreService } from "./genre.service";
import { Prisma, Genre } from "@prisma/client";
import { ApiTags } from "@nestjs/swagger";
import { createReadStream, existsSync } from "fs";
import { FilterQuery } from "src/utils/filter.pipe";
import { Genre as _Genre } from "src/_gen/prisma-class/genre";
import { IncludeMap, mapInclude } from "src/utils/include";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
import { Public } from "src/auth/public";
@Controller('genre')
@ApiTags('genre')
@Controller("genre")
@ApiTags("genre")
@UseGuards(JwtAuthGuard)
export class GenreController {
static filterableFields: string[] = ['+id', 'name'];
static filterableFields: string[] = ["+id", "name"];
static includableFields: IncludeMap<Prisma.GenreInclude> = {
Song: true,
};
@@ -48,23 +48,23 @@ export class GenreController {
}
}
@Delete(':id')
async remove(@Param('id', ParseIntPipe) id: number) {
@Delete(":id")
async remove(@Param("id", ParseIntPipe) id: number) {
try {
return await this.service.delete({ id });
} catch {
throw new NotFoundException('Invalid ID');
throw new NotFoundException("Invalid ID");
}
}
@Get(':id/illustration')
@Get(":id/illustration")
@Public()
async getIllustration(@Param('id', ParseIntPipe) id: number) {
async getIllustration(@Param("id", ParseIntPipe) id: number) {
const genre = await this.service.get({ id });
if (!genre) throw new NotFoundException('Genre not found');
if (!genre) throw new NotFoundException("Genre not found");
const path = `/assets/genres/${genre.name}/illustration.png`;
if (!existsSync(path))
throw new NotFoundException('Illustration not found');
throw new NotFoundException("Illustration not found");
try {
const file = createReadStream(path);
@@ -80,9 +80,9 @@ export class GenreController {
@Req() req: Request,
@FilterQuery(GenreController.filterableFields)
where: Prisma.GenreWhereInput,
@Query('include') include: string,
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
@Query("include") include: string,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Plage<Genre>> {
const ret = await this.service.list({
skip,
@@ -93,18 +93,18 @@ export class GenreController {
return new Plage(ret, req);
}
@Get(':id')
@Get(":id")
async findOne(
@Req() req: Request,
@Query('include') include: string,
@Param('id', ParseIntPipe) id: number,
@Query("include") include: string,
@Param("id", ParseIntPipe) id: number,
) {
const res = await this.service.get(
{ id },
mapInclude(include, req, GenreController.includableFields),
);
if (res === null) throw new NotFoundException('Genre not found');
if (res === null) throw new NotFoundException("Genre not found");
return res;
}
}

View File

@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { GenreController } from './genre.controller';
import { GenreService } from './genre.service';
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/prisma/prisma.module";
import { GenreController } from "./genre.controller";
import { GenreService } from "./genre.service";
@Module({
imports: [PrismaModule],

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Prisma, Genre } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Prisma, Genre } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class GenreService {

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()

View File

@@ -30,7 +30,7 @@ import { mapInclude } from "src/utils/include";
@Controller("history")
@ApiTags("history")
export class HistoryController {
constructor(private readonly historyService: HistoryService) { }
constructor(private readonly historyService: HistoryService) {}
@Get()
@HttpCode(200)

View File

@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { HistoryService } from './history.service';
import { HistoryController } from './history.controller';
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/prisma/prisma.module";
import { HistoryService } from "./history.service";
import { HistoryController } from "./history.controller";
@Module({
imports: [PrismaModule],

View File

@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { HistoryService } from './history.service';
import { Test, TestingModule } from "@nestjs/testing";
import { HistoryService } from "./history.service";
describe('HistoryService', () => {
describe("HistoryService", () => {
let service: HistoryService;
beforeEach(async () => {
@@ -12,7 +12,7 @@ describe('HistoryService', () => {
service = module.get<HistoryService>(HistoryService);
});
it('should be defined', () => {
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View File

@@ -6,7 +6,7 @@ import { SongHistoryDto } from "./dto/SongHistoryDto";
@Injectable()
export class HistoryService {
constructor(private prisma: PrismaService) { }
constructor(private prisma: PrismaService) {}
async createSongHistoryRecord({
songID,

View File

@@ -12,16 +12,16 @@ import {
Delete,
NotFoundException,
UseGuards,
} from '@nestjs/common';
import { ApiOkResponsePlaginated, Plage } from 'src/models/plage';
import { LessonService } from './lesson.service';
import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';
import { Prisma, Skill } from '@prisma/client';
import { FilterQuery } from 'src/utils/filter.pipe';
import { Lesson as _Lesson } from 'src/_gen/prisma-class/lesson';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { IncludeMap, mapInclude } from 'src/utils/include';
import { Request } from 'express';
} from "@nestjs/common";
import { ApiOkResponsePlaginated, Plage } from "src/models/plage";
import { LessonService } from "./lesson.service";
import { ApiOperation, ApiProperty, ApiTags } from "@nestjs/swagger";
import { Prisma, Skill } from "@prisma/client";
import { FilterQuery } from "src/utils/filter.pipe";
import { Lesson as _Lesson } from "src/_gen/prisma-class/lesson";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
import { IncludeMap, mapInclude } from "src/utils/include";
import { Request } from "express";
export class Lesson {
@ApiProperty()
@@ -36,15 +36,15 @@ export class Lesson {
mainSkill: Skill;
}
@ApiTags('lessons')
@Controller('lesson')
@ApiTags("lessons")
@Controller("lesson")
@UseGuards(JwtAuthGuard)
export class LessonController {
static filterableFields: string[] = [
'+id',
'name',
'+requiredLevel',
'mainSkill',
"+id",
"name",
"+requiredLevel",
"mainSkill",
];
static includableFields: IncludeMap<Prisma.LessonInclude> = {
LessonHistory: true,
@@ -53,7 +53,7 @@ export class LessonController {
constructor(private lessonService: LessonService) {}
@ApiOperation({
summary: 'Get all lessons',
summary: "Get all lessons",
})
@Get()
@ApiOkResponsePlaginated(_Lesson)
@@ -61,9 +61,9 @@ export class LessonController {
@Req() request: Request,
@FilterQuery(LessonController.filterableFields)
where: Prisma.LessonWhereInput,
@Query('include') include: string,
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
@Query("include") include: string,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Plage<Lesson>> {
const ret = await this.lessonService.getAll({
skip,
@@ -75,13 +75,13 @@ export class LessonController {
}
@ApiOperation({
summary: 'Get a particular lessons',
summary: "Get a particular lessons",
})
@Get(':id')
@Get(":id")
async get(
@Req() req: Request,
@Query('include') include: string,
@Param('id', ParseIntPipe) id: number,
@Query("include") include: string,
@Param("id", ParseIntPipe) id: number,
): Promise<Lesson> {
const ret = await this.lessonService.get(
id,
@@ -92,7 +92,7 @@ export class LessonController {
}
@ApiOperation({
summary: 'Create a lessons',
summary: "Create a lessons",
})
@Post()
async post(@Body() lesson: Lesson): Promise<Lesson> {
@@ -105,10 +105,10 @@ export class LessonController {
}
@ApiOperation({
summary: 'Delete a lessons',
summary: "Delete a lessons",
})
@Delete(':id')
async delete(@Param('id', ParseIntPipe) id: number): Promise<Lesson> {
@Delete(":id")
async delete(@Param("id", ParseIntPipe) id: number): Promise<Lesson> {
try {
return await this.lessonService.delete(id);
} catch {

View File

@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { LessonController } from './lesson.controller';
import { LessonService } from './lesson.service';
import { Module } from "@nestjs/common";
import { PrismaModule } from "src/prisma/prisma.module";
import { LessonController } from "./lesson.controller";
import { LessonService } from "./lesson.service";
@Module({
imports: [PrismaModule],

View File

@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { LessonService } from './lesson.service';
import { Test, TestingModule } from "@nestjs/testing";
import { LessonService } from "./lesson.service";
describe('LessonService', () => {
describe("LessonService", () => {
let service: LessonService;
beforeEach(async () => {
@@ -12,7 +12,7 @@ describe('LessonService', () => {
service = module.get<LessonService>(LessonService);
});
it('should be defined', () => {
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Lesson, Prisma } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Lesson, Prisma } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class LessonService {

View File

@@ -1,17 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
ValidationPipe,
} from '@nestjs/common';
import { RequestLogger, RequestLoggerOptions } from 'json-logger-service';
import { tap } from 'rxjs';
import { PrismaModel } from './_gen/prisma-class';
import { PrismaService } from './prisma/prisma.service';
} from "@nestjs/common";
import { RequestLogger, RequestLoggerOptions } from "json-logger-service";
import { tap } from "rxjs";
import { PrismaModel } from "./_gen/prisma-class";
import { PrismaService } from "./prisma/prisma.service";
@Injectable()
export class AspectLogger implements NestInterceptor {
@@ -27,8 +27,8 @@ 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(
@@ -48,20 +48,20 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
RequestLogger.buildExpressRequestLogger({
doNotLogPaths: ['/health'],
doNotLogPaths: ["/health"],
} as RequestLoggerOptions),
);
app.enableShutdownHooks();
const config = new DocumentBuilder()
.setTitle('Chromacase')
.setDescription('The chromacase API')
.setVersion('1.0')
.setTitle("Chromacase")
.setDescription("The chromacase API")
.setVersion("1.0")
.build();
const document = SwaggerModule.createDocument(app, config, {
extraModels: [...PrismaModel.extraModels],
});
SwaggerModule.setup('api', app, document);
SwaggerModule.setup("api", app, document);
app.useGlobalPipes(new ValidationPipe());
app.enableCors();

View File

@@ -2,25 +2,25 @@
* Thanks to https://github.com/Arthi-chaud/Meelo/blob/master/src/pagination/models/paginated-response.ts
*/
import { Type, applyDecorators } from '@nestjs/common';
import { Type, applyDecorators } from "@nestjs/common";
import {
ApiExtraModels,
ApiOkResponse,
ApiProperty,
getSchemaPath,
} from '@nestjs/swagger';
} from "@nestjs/swagger";
export class PlageMetadata {
@ApiProperty()
this: string;
@ApiProperty({
type: 'string',
type: "string",
nullable: true,
description: "null if there is no next page, couldn't set it in swagger",
})
next: string | null;
@ApiProperty({
type: 'string',
type: "string",
nullable: true,
description:
"null if there is no previous page, couldn't set it in swagger",
@@ -35,9 +35,9 @@ export class Plage<T extends object> {
constructor(data: T[], request: Request | any) {
this.data = data;
let take = Number(request.query['take'] ?? 20).valueOf();
let take = Number(request.query["take"] ?? 20).valueOf();
if (take == 0) take = 20;
let skipped: number = Number(request.query['skip'] ?? 0).valueOf();
let skipped: number = Number(request.query["skip"] ?? 0).valueOf();
if (skipped % take) {
skipped += take - (skipped % take);
}
@@ -81,7 +81,7 @@ export const ApiOkResponsePlaginated = <DataDto extends Type<unknown>>(
{
properties: {
data: {
type: 'array',
type: "array",
items: { $ref: getSchemaPath(dataDto) },
},
},

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class Setting {
@ApiProperty()

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class User {
@ApiProperty()

View File

@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
import { Module } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
@Module({
providers: [PrismaService],

View File

@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from './prisma.service';
import { Test, TestingModule } from "@nestjs/testing";
import { PrismaService } from "./prisma.service";
describe('PrismaService', () => {
describe("PrismaService", () => {
let service: PrismaService;
beforeEach(async () => {
@@ -12,7 +12,7 @@ describe('PrismaService', () => {
service = module.get<PrismaService>(PrismaService);
});
it('should be defined', () => {
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View File

@@ -1,5 +1,5 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { Injectable, OnModuleInit } from "@nestjs/common";
import { PrismaClient } from "@prisma/client";
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class SearchSongDto {
@ApiProperty()

View File

@@ -7,38 +7,38 @@ import {
Query,
Request,
UseGuards,
} from '@nestjs/common';
} from "@nestjs/common";
import {
ApiOkResponse,
ApiOperation,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { Artist, Genre, Song } from '@prisma/client';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import { SearchService } from './search.service';
import { Song as _Song } from 'src/_gen/prisma-class/song';
import { Genre as _Genre } from 'src/_gen/prisma-class/genre';
import { Artist as _Artist } from 'src/_gen/prisma-class/artist';
import { mapInclude } from 'src/utils/include';
import { SongController } from 'src/song/song.controller';
import { GenreController } from 'src/genre/genre.controller';
import { ArtistController } from 'src/artist/artist.controller';
} from "@nestjs/swagger";
import { Artist, Genre, Song } from "@prisma/client";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
import { SearchService } from "./search.service";
import { Song as _Song } from "src/_gen/prisma-class/song";
import { Genre as _Genre } from "src/_gen/prisma-class/genre";
import { Artist as _Artist } from "src/_gen/prisma-class/artist";
import { mapInclude } from "src/utils/include";
import { SongController } from "src/song/song.controller";
import { GenreController } from "src/genre/genre.controller";
import { ArtistController } from "src/artist/artist.controller";
@ApiTags('search')
@Controller('search')
@ApiTags("search")
@Controller("search")
export class SearchController {
constructor(private readonly searchService: SearchService) {}
@Get('songs/:query')
@Get("songs/:query")
@ApiOkResponse({ type: _Song, isArray: true })
@ApiOperation({ description: 'Search a song' })
@ApiUnauthorizedResponse({ description: 'Invalid token' })
@ApiOperation({ description: "Search a song" })
@ApiUnauthorizedResponse({ description: "Invalid token" })
@UseGuards(JwtAuthGuard)
async searchSong(
@Request() req: any,
@Query('include') include: string,
@Param('query') query: string,
@Query("include") include: string,
@Param("query") query: string,
): Promise<Song[] | null> {
try {
const ret = await this.searchService.songByGuess(
@@ -53,15 +53,15 @@ export class SearchController {
}
}
@Get('genres/:query')
@Get("genres/:query")
@UseGuards(JwtAuthGuard)
@ApiUnauthorizedResponse({ description: 'Invalid token' })
@ApiUnauthorizedResponse({ description: "Invalid token" })
@ApiOkResponse({ type: _Genre, isArray: true })
@ApiOperation({ description: 'Search a genre' })
@ApiOperation({ description: "Search a genre" })
async searchGenre(
@Request() req: any,
@Query('include') include: string,
@Param('query') query: string,
@Query("include") include: string,
@Param("query") query: string,
): Promise<Genre[] | null> {
try {
const ret = await this.searchService.genreByGuess(
@@ -76,15 +76,15 @@ export class SearchController {
}
}
@Get('artists/:query')
@Get("artists/:query")
@UseGuards(JwtAuthGuard)
@ApiOkResponse({ type: _Artist, isArray: true })
@ApiUnauthorizedResponse({ description: 'Invalid token' })
@ApiOperation({ description: 'Search an artist' })
@ApiUnauthorizedResponse({ description: "Invalid token" })
@ApiOperation({ description: "Search an artist" })
async searchArtists(
@Request() req: any,
@Query('include') include: string,
@Param('query') query: string,
@Query("include") include: string,
@Param("query") query: string,
): Promise<Artist[] | null> {
try {
const ret = await this.searchService.artistByGuess(

View File

@@ -1,9 +1,9 @@
import { Module } from '@nestjs/common';
import { SearchService } from './search.service';
import { SearchController } from './search.controller';
import { HistoryModule } from 'src/history/history.module';
import { PrismaModule } from 'src/prisma/prisma.module';
import { SongService } from 'src/song/song.service';
import { Module } from "@nestjs/common";
import { SearchService } from "./search.service";
import { SearchController } from "./search.controller";
import { HistoryModule } from "src/history/history.module";
import { PrismaModule } from "src/prisma/prisma.module";
import { SongService } from "src/song/song.service";
@Module({
imports: [PrismaModule, HistoryModule],

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Artist, Prisma, Song, Genre } from '@prisma/client';
import { HistoryService } from 'src/history/history.service';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Artist, Prisma, Song, Genre } from "@prisma/client";
import { HistoryService } from "src/history/history.service";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class SearchService {
@@ -17,7 +17,7 @@ export class SearchService {
): Promise<Song[]> {
return this.prisma.song.findMany({
where: {
name: { contains: query, mode: 'insensitive' },
name: { contains: query, mode: "insensitive" },
},
include,
});
@@ -30,7 +30,7 @@ export class SearchService {
): Promise<Genre[]> {
return this.prisma.genre.findMany({
where: {
name: { contains: query, mode: 'insensitive' },
name: { contains: query, mode: "insensitive" },
},
include,
});
@@ -43,7 +43,7 @@ export class SearchService {
): Promise<Artist[]> {
return this.prisma.artist.findMany({
where: {
name: { contains: query, mode: 'insensitive' },
name: { contains: query, mode: "insensitive" },
},
include,
});

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class UpdateSettingDto {
@ApiProperty()

View File

@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { SettingsService } from './settings.service';
import { PrismaModule } from 'src/prisma/prisma.module';
import { Module } from "@nestjs/common";
import { SettingsService } from "./settings.service";
import { PrismaModule } from "src/prisma/prisma.module";
@Module({
imports: [PrismaModule],

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Prisma, UserSettings } from '@prisma/client';
import { PrismaService } from 'src/prisma/prisma.service';
import { Injectable } from "@nestjs/common";
import { Prisma, UserSettings } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@Injectable()
export class SettingsService {

View File

@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
export class CreateSongDto {
@IsNotEmpty()

View File

@@ -1,8 +1,8 @@
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 { 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";
@Module({
imports: [PrismaModule, HistoryModule],

View File

@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SongService } from './song.service';
import { Test, TestingModule } from "@nestjs/testing";
import { SongService } from "./song.service";
describe('SongService', () => {
describe("SongService", () => {
let service: SongService;
beforeEach(async () => {
@@ -12,7 +12,7 @@ describe('SongService', () => {
service = module.get<SongService>(SongService);
});
it('should be defined', () => {
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View File

@@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
export class CreateUserDto {
@ApiProperty()

View File

@@ -1,4 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateUserDto } from './create-user.dto';
import { PartialType } from "@nestjs/mapped-types";
import { CreateUserDto } from "./create-user.dto";
export class UpdateUserDto extends PartialType(CreateUserDto) {}

View File

@@ -5,13 +5,13 @@ import {
Param,
NotFoundException,
Response,
} from '@nestjs/common';
import { UsersService } from './users.service';
import { ApiNotFoundResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { User } from 'src/models/user';
} from "@nestjs/common";
import { UsersService } from "./users.service";
import { ApiNotFoundResponse, ApiOkResponse, ApiTags } from "@nestjs/swagger";
import { User } from "src/models/user";
@ApiTags('users')
@Controller('users')
@ApiTags("users")
@Controller("users")
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@@ -20,19 +20,19 @@ export class UsersController {
return this.usersService.users({});
}
@Get(':id')
@Get(":id")
@ApiNotFoundResponse()
async findOne(@Param('id') id: number): Promise<User> {
async findOne(@Param("id") id: number): Promise<User> {
const ret = await this.usersService.user({ id: +id });
if (!ret) throw new NotFoundException();
return ret;
}
@Get(':id/picture')
@Get(":id/picture")
@ApiOkResponse({
description: 'Return the profile picture of the requested user',
description: "Return the profile picture of the requested user",
})
async getPicture(@Response() res: any, @Param('id') id: number) {
async getPicture(@Response() res: any, @Param("id") id: number) {
return await this.usersService.getProfilePicture(+id, res);
}
}

View File

@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import { PrismaModule } from 'src/prisma/prisma.module';
import { SettingsService } from 'src/settings/settings.service';
import { Module } from "@nestjs/common";
import { UsersService } from "./users.service";
import { UsersController } from "./users.controller";
import { PrismaModule } from "src/prisma/prisma.module";
import { SettingsService } from "src/settings/settings.service";
@Module({
imports: [PrismaModule],

View File

@@ -12,7 +12,7 @@ import fetch from "node-fetch";
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) { }
constructor(private prisma: PrismaService) {}
async user(
userWhereUniqueInput: Prisma.UserWhereUniqueInput,

View File

@@ -3,7 +3,7 @@ import {
Injectable,
PipeTransform,
Query,
} from '@nestjs/common';
} from "@nestjs/common";
@Injectable()
export class FilterPipe implements PipeTransform {
@@ -12,13 +12,13 @@ export class FilterPipe implements PipeTransform {
transform(value: Record<string, string>) {
const filter = {};
for (const fieldIdentifier of this.fields) {
const field = fieldIdentifier.startsWith('+')
const field = fieldIdentifier.startsWith("+")
? fieldIdentifier.slice(1)
: fieldIdentifier;
if (value[field] === undefined) continue;
if (fieldIdentifier.startsWith('+')) {
if (fieldIdentifier.startsWith("+")) {
filter[field] = parseInt(value[field]);
if (isNaN(filter[field]))
throw new BadRequestException(

View File

@@ -1,5 +1,5 @@
import { Request } from 'express';
import { BadRequestException } from '@nestjs/common';
import { Request } from "express";
import { BadRequestException } from "@nestjs/common";
export type IncludeMap<IncludeType> = {
[key in keyof IncludeType]:
@@ -15,9 +15,9 @@ export function mapInclude<IncludeType>(
if (!include) return undefined;
const ret: IncludeType = {} as IncludeType;
for (const key of include.split(',')) {
for (const key of include.split(",")) {
const value =
typeof fields[key] === 'function'
typeof fields[key] === "function"
? fields[key]({ user: req.user })
: fields[key];
if (value !== false && value !== undefined) ret[key] = value;
@@ -25,7 +25,7 @@ export function mapInclude<IncludeType>(
throw new BadRequestException(
`Invalid include, ${key} is not valid. Valid includes are: ${Object.keys(
fields,
).join(', ')}.`,
).join(", ")}.`,
);
}
}

View File

@@ -1,9 +1,9 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import * as request from "supertest";
import { AppModule } from "./../src/app.module";
describe('AppController (e2e)', () => {
describe("AppController (e2e)", () => {
let app: INestApplication;
beforeEach(async () => {
@@ -15,10 +15,10 @@ describe('AppController (e2e)', () => {
await app.init();
});
it('/ (GET)', () => {
it("/ (GET)", () => {
return request(app.getHttpServer())
.get('/')
.get("/")
.expect(200)
.expect('Hello World!');
.expect("Hello World!");
});
});