Normalize quote usage in imports

Standardized the quote style to double quotes across all TypeScript files for consistency. This includes ".ts" and ".dto" files.
This commit is contained in:
Mathis H (Avnyr) 2024-11-12 13:37:29 +01:00
parent 2fdc16e003
commit 8ea217fe9f
Signed by: Mathis
GPG Key ID: DD9E0666A747D126
52 changed files with 1475 additions and 1486 deletions

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,5 +1,5 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { Controller, Get } from "@nestjs/common";
import { AppService } from "./app.service";
@Controller()
export class AppController {
@ -7,6 +7,6 @@ export class AppController {
@Get()
getHello(): string {
return 'Hello';
return "Hello";
}
}

View File

@ -1,16 +1,16 @@
import { Module } from '@nestjs/common';
import { AppController } from '@/app.controller';
import { AppService } from '@/app.service';
import { ConfigModule } from '@nestjs/config';
import { AuthModule } from '@/auth/auth.module';
import { PrismaModule } from '@/prisma/prisma.module';
import { RoleModule } from '@/role/role.module';
import { PromoCodeModule } from '@/promoCode/promoCode.module';
import { CryptoModule } from '@/crypto/crypto.module';
import { TradeModule } from '@/trade/trade.module';
import { OfferModule } from '@/offer/offer.module';
import { UserModule } from '@/user/user.module';
import { ThrottlerModule } from '@nestjs/throttler';
import { AppController } from "@/app.controller";
import { AppService } from "@/app.service";
import { AuthModule } from "@/auth/auth.module";
import { CryptoModule } from "@/crypto/crypto.module";
import { OfferModule } from "@/offer/offer.module";
import { PrismaModule } from "@/prisma/prisma.module";
import { PromoCodeModule } from "@/promoCode/promoCode.module";
import { RoleModule } from "@/role/role.module";
import { TradeModule } from "@/trade/trade.module";
import { UserModule } from "@/user/user.module";
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { ThrottlerModule } from "@nestjs/throttler";
@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

@ -1,20 +1,20 @@
import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthLoginDto, AuthRegisterDto } from './dto';
import { ApiTags } from '@nestjs/swagger';
import { Body, Controller, HttpCode, HttpStatus, Post } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { AuthService } from "./auth.service";
import { AuthLoginDto, AuthRegisterDto } from "./dto";
@ApiTags('auth')
@Controller('auth')
@ApiTags("auth")
@Controller("auth")
export class AuthController {
constructor(private authService: AuthService) {}
@Post('sign-up')
@Post("sign-up")
signUp(@Body() dto: AuthRegisterDto) {
return this.authService.signup(dto);
}
@HttpCode(HttpStatus.OK)
@Post('sign-in')
@Post("sign-in")
signIn(@Body() dto: AuthLoginDto) {
return this.authService.signin(dto);
}

View File

@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { JwtStrategy } from './strategy';
import { Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { JwtStrategy } from "./strategy";
@Module({
imports: [JwtModule.register({})],

View File

@ -1,10 +1,10 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { AuthLoginDto, AuthRegisterDto } from './dto';
import * as argon from 'argon2';
import { Prisma, User } from '@prisma/client';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { ForbiddenException, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
import { Prisma, User } from "@prisma/client";
import * as argon from "argon2";
import { PrismaService } from "../prisma/prisma.service";
import { AuthLoginDto, AuthRegisterDto } from "./dto";
@Injectable()
export class AuthService {
@ -19,7 +19,7 @@ export class AuthService {
async signup(dto: AuthRegisterDto) {
const hash = await argon.hash(dto.password);
const promoCode = await this.getPromoCode(dto.promoCode);
const userRole = await this.getUserRole('user');
const userRole = await this.getUserRole("user");
const balance = this.calculateBalance(promoCode);
try {
@ -50,7 +50,12 @@ export class AuthService {
return balance;
}
private async createUser(dto: AuthRegisterDto, hash: string, roleId: string, balance: number) {
private async createUser(
dto: AuthRegisterDto,
hash: string,
roleId: string,
balance: number,
) {
return this.prisma.user.create({
data: {
firstName: dto.firstName,
@ -67,8 +72,8 @@ export class AuthService {
private handleSignupError(error: any) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2002') {
throw new ForbiddenException('Credentials taken');
if (error.code === "P2002") {
throw new ForbiddenException("Credentials taken");
}
}
throw error;
@ -83,10 +88,10 @@ export class AuthService {
},
});
if (!userDatas) throw new ForbiddenException('Credentials incorrect');
if (!userDatas) throw new ForbiddenException("Credentials incorrect");
const pwMatches = await argon.verify(userDatas.hash, dto.password);
if (!pwMatches) throw new ForbiddenException('Credentials incorrect');
if (!pwMatches) throw new ForbiddenException("Credentials incorrect");
return this.signToken(userDatas);
}
@ -94,9 +99,9 @@ export class AuthService {
async signToken(user: any): Promise<{ access_token: string; user: User }> {
const payload = { sub: user.id, email: user.email };
user.hash = null;
const secret = this.config.get('JWT_SECRET');
const secret = this.config.get("JWT_SECRET");
const token = await this.jwt.signAsync(payload, {
expiresIn: '30d',
expiresIn: "30d",
secret: secret,
});

View File

@ -1,4 +1,4 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { ExecutionContext, createParamDecorator } from "@nestjs/common";
export const GetUser = createParamDecorator(
(data: string | undefined, ctx: ExecutionContext) => {

View File

@ -1 +1 @@
export * from './get-user.decorator';
export * from "./get-user.decorator";

View File

@ -1,12 +1,12 @@
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import { IsEmail, IsNotEmpty, IsString } from "class-validator";
export class AuthLoginDto {
@IsEmail()
@IsNotEmpty()
@ApiProperty({ type: String, description: 'email' })
@ApiProperty({ type: String, description: "email" })
email: string;
@ApiProperty({ type: String, description: 'password' })
@ApiProperty({ type: String, description: "password" })
@IsString()
@IsNotEmpty()
password: string;

View File

@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import {
IsEmail,
IsInt,
@ -9,12 +9,12 @@ import {
MaxLength,
Min,
MinLength,
} from 'class-validator';
} from "class-validator";
export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'FirstName',
example: 'Thomas',
description: "FirstName",
example: "Thomas",
})
@MinLength(1)
@MaxLength(50)
@ -24,8 +24,8 @@ export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'Last Name',
example: 'Anderson',
description: "Last Name",
example: "Anderson",
})
@MinLength(1)
@MaxLength(50)
@ -35,8 +35,8 @@ export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'Pseudo',
example: 'Néo',
description: "Pseudo",
example: "Néo",
})
@MinLength(1)
@MaxLength(50)
@ -46,8 +46,8 @@ export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'email',
example: 'neo@matrix.fr',
description: "email",
example: "neo@matrix.fr",
})
@MaxLength(255)
@IsEmail()
@ -56,8 +56,8 @@ export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'password',
example: 'AAaa11&&&&',
description: "password",
example: "AAaa11&&&&",
})
@IsString()
@IsNotEmpty()
@ -65,8 +65,8 @@ export class AuthRegisterDto {
@ApiProperty({
type: String,
description: 'promoCode',
example: 'FILOU20',
description: "promoCode",
example: "FILOU20",
})
@IsOptional()
promoCode: string;

View File

@ -1,2 +1,2 @@
export * from './auth.register.dto';
export * from './auth.login.dto';
export * from "./auth.register.dto";
export * from "./auth.login.dto";

View File

@ -1 +1 @@
export * from './jwt.guard';
export * from "./jwt.guard";

View File

@ -1,6 +1,6 @@
import { AuthGuard } from '@nestjs/passport';
import { AuthGuard } from "@nestjs/passport";
export class JwtGuard extends AuthGuard('jwt') {
export class JwtGuard extends AuthGuard("jwt") {
constructor() {
super();
}

View File

@ -1 +1 @@
export * from './jwt.strategy';
export * from "./jwt.strategy";

View File

@ -1,18 +1,18 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PrismaService } from "@/prisma/prisma.service";
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { PassportStrategy } from "@nestjs/passport";
import { ExtractJwt, Strategy } from "passport-jwt";
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
export class JwtStrategy extends PassportStrategy(Strategy, "jwt") {
constructor(
config: ConfigService,
private prisma: PrismaService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: config.get('JWT_SECRET'),
secretOrKey: config.get("JWT_SECRET"),
});
}

View File

@ -9,37 +9,37 @@ import {
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { GetUser } from '../auth/decorator';
import { ApiTags } from '@nestjs/swagger';
import { User } from '@prisma/client';
import { CryptoService } from './crypto.service';
import { CryptoDto } from './dto';
import { JwtGuard } from 'src/auth/guard';
import { BuyCryptoDto } from './dto/buy.crypto.dto';
} from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { JwtGuard } from "src/auth/guard";
import { GetUser } from "../auth/decorator";
import { CryptoService } from "./crypto.service";
import { CryptoDto } from "./dto";
import { BuyCryptoDto } from "./dto/buy.crypto.dto";
@UseGuards(JwtGuard)
@ApiTags('crypto')
@Controller('crypto')
@ApiTags("crypto")
@Controller("crypto")
export class CryptoController {
constructor(private cryptoService: CryptoService) {}
@Get('/all')
@Get("/all")
getAllPromoCodes(@GetUser() user: User) {
return this.cryptoService.getCryptos(user.id);
}
@Get('/search/:name')
searchCrypto(@GetUser() user: User, @Param('name') cryptoName: string) {
@Get("/search/:name")
searchCrypto(@GetUser() user: User, @Param("name") cryptoName: string) {
return this.cryptoService.searchCryptos(user.id, cryptoName);
}
@Get('/history/:id')
CryptoHistory(@GetUser() user: User, @Param('id') cryptoId: string) {
@Get("/history/:id")
CryptoHistory(@GetUser() user: User, @Param("id") cryptoId: string) {
return this.cryptoService.getCryptoHistory(user.id, cryptoId);
}
@HttpCode(HttpStatus.CREATED)
@Post('/create')
@Post("/create")
createPromoCode(
@Body()
dto: CryptoDto,
@ -47,7 +47,7 @@ export class CryptoController {
) {
return this.cryptoService.createCrypto(user.id, dto);
}
@Post('/buy')
@Post("/buy")
buyCrypto(
@Body()
dto: BuyCryptoDto,
@ -56,9 +56,9 @@ export class CryptoController {
return this.cryptoService.buyCrypto(user.id, dto);
}
@HttpCode(HttpStatus.OK)
@Patch('/update/:id')
@Patch("/update/:id")
editCryptoById(
@Param('id') cryptoId: string,
@Param("id") cryptoId: string,
@Body() dto: CryptoDto,
@GetUser() user: User,
) {
@ -66,8 +66,8 @@ export class CryptoController {
}
@HttpCode(HttpStatus.NO_CONTENT)
@Delete('/delete/:id')
deleteOfferById(@Param('id') roleId: string, @GetUser() user: User) {
@Delete("/delete/:id")
deleteOfferById(@Param("id") roleId: string, @GetUser() user: User) {
return this.cryptoService.deleteCryptoById(user.id, roleId);
}
}

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { CryptoService } from './crypto.service';
import { CryptoController } from './crypto.controller';
import { Module } from "@nestjs/common";
import { CryptoController } from "./crypto.controller";
import { CryptoService } from "./crypto.service";
@Module({
providers: [CryptoService],

View File

@ -1,8 +1,8 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { checkUserHasAccount, checkUserIsAdmin } from 'src/utils/checkUser';
import { CryptoDto } from './dto';
import { BuyCryptoDto } from './dto/buy.crypto.dto';
import { ForbiddenException, Injectable } from "@nestjs/common";
import { checkUserHasAccount, checkUserIsAdmin } from "src/utils/checkUser";
import { PrismaService } from "../prisma/prisma.service";
import { CryptoDto } from "./dto";
import { BuyCryptoDto } from "./dto/buy.crypto.dto";
@Injectable()
export class CryptoService {
constructor(private prisma: PrismaService) {}
@ -12,7 +12,7 @@ export class CryptoService {
return this.prisma.crypto.findMany({
orderBy: {
name: 'asc',
name: "asc",
},
});
}
@ -23,11 +23,11 @@ export class CryptoService {
where: {
name: {
contains: cryptoName,
mode: 'insensitive',
mode: "insensitive",
},
},
orderBy: {
name: 'asc',
name: "asc",
},
});
}
@ -42,12 +42,12 @@ export class CryptoService {
},
orderBy: {
created_at: 'desc',
created_at: "desc",
},
take: 50,
});
}
throw new ForbiddenException('Crypto UUID required');
throw new ForbiddenException("Crypto UUID required");
}
async createCrypto(userId: string, dto: CryptoDto) {
@ -59,7 +59,7 @@ export class CryptoService {
},
});
if (existingCryptosWithSameName.length > 0) {
throw new ForbiddenException('Name already taken');
throw new ForbiddenException("Name already taken");
}
const crypto = await this.prisma.crypto.create({
data: {
@ -86,13 +86,13 @@ export class CryptoService {
},
});
if (crypto.quantity < dto.amount) {
throw new ForbiddenException('No more tokens available');
throw new ForbiddenException("No more tokens available");
}
const necessaryAmount = crypto.value * dto.amount;
console.log(necessaryAmount, user.dollarAvailables);
if (necessaryAmount > user.dollarAvailables) {
throw new ForbiddenException('Make money first :) ');
throw new ForbiddenException("Make money first :) ");
}
const userAsset = await this.prisma.userHasCrypto.findFirst({
where: {
@ -159,7 +159,7 @@ export class CryptoService {
});
if (!crypto || crypto.id !== cryptoId)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
return this.prisma.crypto.update({
where: {
@ -181,7 +181,7 @@ export class CryptoService {
});
if (!crypto || crypto.id !== id)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
await this.prisma.crypto.delete({
where: {

View File

@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import {
IsNumber,
IsString,
@ -7,12 +7,12 @@ import {
MaxLength,
Min,
MinLength,
} from 'class-validator';
} from "class-validator";
export class BuyCryptoDto {
@ApiProperty({
type: String,
description: 'Cryptocurrency UUID',
example: '12121-DSZD-E221212-2121221',
description: "Cryptocurrency UUID",
example: "12121-DSZD-E221212-2121221",
})
@MinLength(1)
@MaxLength(50)
@ -22,7 +22,7 @@ export class BuyCryptoDto {
@ApiProperty({
type: Number,
description: 'Amount of token traded',
description: "Amount of token traded",
example: 2,
})
@Min(1)

View File

@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import {
IsNumber,
IsPositive,
@ -8,12 +8,12 @@ import {
MaxLength,
Min,
MinLength,
} from 'class-validator';
} from "class-validator";
export class CryptoDto {
@ApiProperty({
type: String,
description: 'Cryptocurrency name',
example: 'BTC',
description: "Cryptocurrency name",
example: "BTC",
})
@MaxLength(50)
@MinLength(1)
@ -22,7 +22,7 @@ export class CryptoDto {
@ApiProperty({
type: Number,
description: 'Value for the cryptocurrency in $',
description: "Value for the cryptocurrency in $",
example: 1,
})
@Min(1)
@ -33,7 +33,7 @@ export class CryptoDto {
@ApiProperty({
type: Number,
description: 'Quantity of tokens available on the platform',
description: "Quantity of tokens available on the platform",
example: 100,
})
@Min(1)
@ -44,8 +44,8 @@ export class CryptoDto {
@ApiProperty({
type: String,
description: 'Image for the cryptocurrency in ',
example: 'https://myImage/com',
description: "Image for the cryptocurrency in ",
example: "https://myImage/com",
})
@MaxLength(255)
@IsUrl()

View File

@ -1 +1 @@
export * from './crypto.dto';
export * from "./crypto.dto";

View File

@ -1,19 +1,19 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
const config = new DocumentBuilder()
.setTitle('Neptune API')
.setDescription('A fictive app')
.setVersion('1.0')
.setTitle("Neptune API")
.setDescription("A fictive app")
.setVersion("1.0")
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
SwaggerModule.setup("api", app, document);
app.useGlobalPipes(
new ValidationPipe({

View File

@ -1 +1 @@
export * from './offer.dto';
export * from "./offer.dto";

View File

@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import {
IsNumber,
IsPositive,
@ -7,21 +7,21 @@ import {
Max,
MaxLength,
Min,
} from 'class-validator';
} from "class-validator";
export class OfferDto {
@ApiProperty({
type: String,
description: 'Cryptocurrency UUID',
example: '12121-DSZD-E221212-6227933',
description: "Cryptocurrency UUID",
example: "12121-DSZD-E221212-6227933",
})
@IsString()
@IsUUID()
id_crypto: string;
@ApiProperty({
type: 'number',
type: "number",
description: 'Amount traded ',
description: "Amount traded ",
example: 21,
})
@Min(1)
@ -30,4 +30,3 @@ export class OfferDto {
@IsPositive()
amount: number;
}

View File

@ -10,28 +10,28 @@ import {
Post,
UseGuards,
// UseGuards,
} from '@nestjs/common';
import { GetUser } from '../auth/decorator';
} from "@nestjs/common";
// import { JwtGuard } from '../auth/guard';
import { ApiTags } from '@nestjs/swagger';
import { User } from '@prisma/client';
import { JwtGuard } from 'src/auth/guard';
import { OfferService } from './offer.service';
import { OfferDto } from './dto';
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { JwtGuard } from "src/auth/guard";
import { GetUser } from "../auth/decorator";
import { OfferDto } from "./dto";
import { OfferService } from "./offer.service";
@UseGuards(JwtGuard)
@ApiTags('offer')
@Controller('offer')
@ApiTags("offer")
@Controller("offer")
export class OfferController {
constructor(private offerService: OfferService) {}
@Get('/all')
@Get("/all")
getAllRoles(@GetUser() user: User) {
return this.offerService.getOffers(user.id);
}
@HttpCode(HttpStatus.CREATED)
@Post('/create')
@Post("/create")
createRole(
@Body()
dto: OfferDto,
@ -41,9 +41,9 @@ export class OfferController {
}
@HttpCode(HttpStatus.OK)
@Patch('/update/:id')
@Patch("/update/:id")
editOfferById(
@Param('id') offerId: string,
@Param("id") offerId: string,
@Body() dto: OfferDto,
@GetUser() user: User,
) {
@ -51,8 +51,8 @@ export class OfferController {
}
@HttpCode(HttpStatus.NO_CONTENT)
@Delete('/delete/:id')
deleteOfferById(@Param('id') roleId: string, @GetUser() user: User) {
@Delete("/delete/:id")
deleteOfferById(@Param("id") roleId: string, @GetUser() user: User) {
return this.offerService.deleteOfferById(user.id, roleId);
}
}

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { OfferService } from './offer.service';
import { OfferController } from './offer.controller';
import { Module } from "@nestjs/common";
import { OfferController } from "./offer.controller";
import { OfferService } from "./offer.service";
@Module({
providers: [OfferService],

View File

@ -1,9 +1,8 @@
import {ForbiddenException, Injectable} from "@nestjs/common";
import { PrismaService } from "@/prisma/prisma.service";
import { ForbiddenException, Injectable } from "@nestjs/common";
import { checkUserHasAccount, checkUserIsAdmin } from "src/utils/checkUser";
import { OfferDto } from "./dto";
@Injectable()
export class OfferService {
constructor(private prisma: PrismaService) {}
@ -12,7 +11,7 @@ export class OfferService {
await checkUserHasAccount(userId);
return this.prisma.offer.findMany({
orderBy: {
created_at: 'desc',
created_at: "desc",
},
select: {
amount: true,
@ -49,11 +48,11 @@ export class OfferService {
},
});
if (!crypto || !crypto.id) {
throw new ForbiddenException('Crypto doesnt exist');
throw new ForbiddenException("Crypto doesnt exist");
}
if (!offer || offer.id !== offerId)
throw new ForbiddenException('Offer id mandatory');
throw new ForbiddenException("Offer id mandatory");
return this.prisma.offer.update({
where: {
@ -74,7 +73,7 @@ export class OfferService {
});
if (!offer || offer.id !== id)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
await this.prisma.offer.delete({
where: {
@ -83,6 +82,3 @@ export class OfferService {
});
}
}

View File

@ -1,5 +1,5 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
import { Global, Module } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
@Global()
@Module({

View File

@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Injectable } from "@nestjs/common";
// biome-ignore lint/style/useImportType:
import { ConfigService } from '@nestjs/config';
import { PrismaClient } from '@prisma/client';
import { ConfigService } from "@nestjs/config";
import { PrismaClient } from "@prisma/client";
@Injectable()
export class PrismaService extends PrismaClient {
@ -9,10 +9,9 @@ export class PrismaService extends PrismaClient {
super({
datasources: {
db: {
url: config.get('DATABASE_URL'),
url: config.get("DATABASE_URL"),
},
},
});
}
}

View File

@ -1 +1 @@
export * from './promoCode.dto';
export * from "./promoCode.dto";

View File

@ -1,4 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import {
IsNumber,
IsPositive,
@ -7,12 +7,12 @@ import {
MaxLength,
Min,
MinLength,
} from 'class-validator';
} from "class-validator";
export class PromoCodeDto {
@ApiProperty({
type: String,
description: 'Name of the PromoCOde',
example: 'FILOU10',
description: "Name of the PromoCOde",
example: "FILOU10",
})
@MinLength(1)
@MaxLength(50)
@ -21,7 +21,7 @@ export class PromoCodeDto {
@ApiProperty({
type: Number,
description: 'Dollars given for account creation when promoCode applied',
description: "Dollars given for account creation when promoCode applied",
example: 100,
})
@IsPositive()

View File

@ -9,27 +9,27 @@ import {
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { GetUser } from '../auth/decorator';
import { ApiTags } from '@nestjs/swagger';
import { User } from '@prisma/client';
import { PromoCodeDto } from './dto';
import { PromoCodeService } from './promoCode.service';
import { JwtGuard } from 'src/auth/guard';
} from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { JwtGuard } from "src/auth/guard";
import { GetUser } from "../auth/decorator";
import { PromoCodeDto } from "./dto";
import { PromoCodeService } from "./promoCode.service";
@UseGuards(JwtGuard)
@ApiTags('promoCode')
@Controller('promoCode')
@ApiTags("promoCode")
@Controller("promoCode")
export class PromoCodeController {
constructor(private promoService: PromoCodeService) {}
@Get('/all')
@Get("/all")
getAllPromoCodes(@GetUser() user: User) {
return this.promoService.getPromoCodes(user.id);
}
@HttpCode(HttpStatus.CREATED)
@Post('/create')
@Post("/create")
createPromoCode(
// @GetUser() user: User,
@Body()
@ -40,9 +40,9 @@ export class PromoCodeController {
}
@HttpCode(HttpStatus.OK)
@Patch('/update/:id')
@Patch("/update/:id")
editPromoCodeById(
@Param('id') promoCodeId: string,
@Param("id") promoCodeId: string,
@Body() dto: PromoCodeDto,
@GetUser() user: User,
) {
@ -50,8 +50,8 @@ export class PromoCodeController {
}
@HttpCode(HttpStatus.NO_CONTENT)
@Delete('/delete/:id')
deletePromoCodeById(@Param('id') promoCodeId: string, @GetUser() user: User) {
@Delete("/delete/:id")
deletePromoCodeById(@Param("id") promoCodeId: string, @GetUser() user: User) {
return this.promoService.deletePromoCodeById(user.id, promoCodeId);
}
}

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { PromoCodeController } from './promoCode.controller';
import { PromoCodeService } from './promoCode.service';
import { Module } from "@nestjs/common";
import { PromoCodeController } from "./promoCode.controller";
import { PromoCodeService } from "./promoCode.service";
@Module({
providers: [PromoCodeService],

View File

@ -1,13 +1,13 @@
import { ForbiddenException } from '@nestjs/common';
// biome-ignore lint/style/useImportType:
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from "@/prisma/prisma.service";
import { PromoCodeService } from './promoCode.service';
import { checkUserIsAdmin } from "@/utils/checkUser";
import { ForbiddenException } from "@nestjs/common";
// biome-ignore lint/style/useImportType:
import { Test, TestingModule } from "@nestjs/testing";
import { PromoCodeService } from "./promoCode.service";
jest.mock('../utils/checkUser');
jest.mock("../utils/checkUser");
describe('PromoCodeService', () => {
describe("PromoCodeService", () => {
let service: PromoCodeService;
let prisma: PrismaService;
@ -37,35 +37,34 @@ describe('PromoCodeService', () => {
jest.clearAllMocks();
});
describe('getPromoCodes', () => {
it('should get promo codes if user is admin', async () => {
describe("getPromoCodes", () => {
it("should get promo codes if user is admin", async () => {
(checkUserIsAdmin as jest.Mock).mockResolvedValue(true);
const mockPromoCodes = [
{ id: '1', name: 'PROMO10', value: 10 },
{ id: '2', name: 'PROMO20', value: 20 },
{ id: "1", name: "PROMO10", value: 10 },
{ id: "2", name: "PROMO20", value: 20 },
];
mockPrismaService.promoCode.findMany.mockResolvedValue(mockPromoCodes);
const result = await service.getPromoCodes('user-id');
const result = await service.getPromoCodes("user-id");
expect(checkUserIsAdmin).toHaveBeenCalledWith('user-id');
expect(checkUserIsAdmin).toHaveBeenCalledWith("user-id");
expect(prisma.promoCode.findMany).toHaveBeenCalledWith({
orderBy: { name: 'asc' },
orderBy: { name: "asc" },
select: { id: true, name: true, value: true },
});
expect(result).toEqual(mockPromoCodes);
});
it('should throw ForbiddenException if user is not admin', async () => {
(checkUserIsAdmin as jest.Mock).mockRejectedValue(new ForbiddenException('Not an admin'));
await expect(service.getPromoCodes('user-id')).rejects.toThrow(
ForbiddenException,
it("should throw ForbiddenException if user is not admin", async () => {
(checkUserIsAdmin as jest.Mock).mockRejectedValue(
new ForbiddenException("Not an admin"),
);
expect(checkUserIsAdmin).toHaveBeenCalledWith('user-id');
await expect(service.getPromoCodes("user-id")).rejects.toThrow(ForbiddenException);
expect(checkUserIsAdmin).toHaveBeenCalledWith("user-id");
expect(prisma.promoCode.findMany).not.toHaveBeenCalled();
});
});
});

View File

@ -1,7 +1,7 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { PromoCodeDto } from './dto';
import { checkUserIsAdmin } from '../utils/checkUser';
import { ForbiddenException, Injectable } from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
import { checkUserIsAdmin } from "../utils/checkUser";
import { PromoCodeDto } from "./dto";
@Injectable()
export class PromoCodeService {
constructor(private prisma: PrismaService) {}
@ -11,7 +11,7 @@ export class PromoCodeService {
return this.prisma.promoCode.findMany({
orderBy: {
name: 'asc',
name: "asc",
},
select: {
id: true,
@ -33,11 +33,7 @@ export class PromoCodeService {
return promoCode;
}
async editPromoCodeById(
userId: string,
promoCodeId: string,
dto: PromoCodeDto,
) {
async editPromoCodeById(userId: string, promoCodeId: string, dto: PromoCodeDto) {
await checkUserIsAdmin(userId);
const promoCode = await this.prisma.promoCode.findUnique({
@ -47,7 +43,7 @@ export class PromoCodeService {
});
if (!promoCode || promoCode.id !== promoCodeId)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
return this.prisma.promoCode.update({
where: {
@ -68,7 +64,7 @@ export class PromoCodeService {
});
if (!promoCode || promoCode.id !== id)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
await this.prisma.promoCode.delete({
where: {

View File

@ -1 +1 @@
export * from './role.dto';
export * from "./role.dto";

View File

@ -1,10 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, MaxLength, MinLength } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsString, MaxLength, MinLength } from "class-validator";
export class RoleDto {
@ApiProperty({
type: String,
description: 'Role Name',
example: 'user',
description: "Role Name",
example: "user",
})
@MinLength(1)
@MaxLength(50)

View File

@ -10,22 +10,22 @@ import {
Post,
UseGuards,
// UseGuards,
} from '@nestjs/common';
import { GetUser } from '../auth/decorator';
} from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { JwtGuard } from "src/auth/guard";
import { GetUser } from "../auth/decorator";
// import { JwtGuard } from '../auth/guard';
import { RoleDto } from './dto';
import { RoleService } from './role.service';
import { ApiTags } from '@nestjs/swagger';
import { User } from '@prisma/client';
import { JwtGuard } from 'src/auth/guard';
import { RoleDto } from "./dto";
import { RoleService } from "./role.service";
@UseGuards(JwtGuard)
@ApiTags('role')
@Controller('role')
@ApiTags("role")
@Controller("role")
export class RoleController {
constructor(private roleService: RoleService) {}
@Get('/all')
@Get("/all")
getAllRoles(@GetUser() user: User) {
return this.roleService.getRolesAdmin(user.id);
}
@ -35,7 +35,7 @@ export class RoleController {
// }
@HttpCode(HttpStatus.CREATED)
@Post('/create')
@Post("/create")
createRole(
// @GetUser() user: User,
@Body()
@ -46,18 +46,14 @@ export class RoleController {
}
@HttpCode(HttpStatus.OK)
@Patch('/update/:id')
editRoleById(
@Param('id') roleId: string,
@Body() dto: RoleDto,
@GetUser() user: User,
) {
@Patch("/update/:id")
editRoleById(@Param("id") roleId: string, @Body() dto: RoleDto, @GetUser() user: User) {
return this.roleService.editRoleById(user.id, roleId, dto);
}
@HttpCode(HttpStatus.NO_CONTENT)
@Delete('/delete/:id')
deleteRoleById(@Param('id') roleId: string, @GetUser() user: User) {
@Delete("/delete/:id")
deleteRoleById(@Param("id") roleId: string, @GetUser() user: User) {
return this.roleService.deleteRoleById(user.id, roleId);
}
}

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { RoleController } from './role.controller';
import { RoleService } from './role.service';
import { Module } from "@nestjs/common";
import { RoleController } from "./role.controller";
import { RoleService } from "./role.service";
@Module({
providers: [RoleService],
controllers: [RoleController],

View File

@ -1,7 +1,7 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { RoleDto } from './dto';
import { checkUserIsAdmin } from 'src/utils/checkUser';
import { ForbiddenException, Injectable } from "@nestjs/common";
import { checkUserIsAdmin } from "src/utils/checkUser";
import { PrismaService } from "../prisma/prisma.service";
import { RoleDto } from "./dto";
// import { checkRoleLevel, checkUserIsStaff } from 'src/utils/checkUser';
@Injectable()
export class RoleService {
@ -11,7 +11,7 @@ export class RoleService {
await checkUserIsAdmin(userId);
return this.prisma.role.findMany({
orderBy: {
name: 'asc',
name: "asc",
},
select: {
id: true,
@ -40,7 +40,7 @@ export class RoleService {
});
if (!role || role.id !== roleId)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
return this.prisma.role.update({
where: {
@ -61,7 +61,7 @@ export class RoleService {
});
if (!role || role.id !== id)
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
await this.prisma.role.delete({
where: {

View File

@ -1 +1 @@
export * from './trade.dto';
export * from "./trade.dto";

View File

@ -1,10 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, IsUUID } from 'class-validator';
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty, IsString, IsUUID } from "class-validator";
export class TradeDto {
@ApiProperty({
type: String,
description: 'Offer UUID ',
example: '121212-DSDZ1-21212DJDZ-31313',
description: "Offer UUID ",
example: "121212-DSDZ1-21212DJDZ-31313",
})
@IsUUID()
@IsNotEmpty()

View File

@ -6,27 +6,27 @@ import {
HttpStatus,
Post,
UseGuards,
} from '@nestjs/common';
import { GetUser } from '../auth/decorator';
import { ApiTags } from '@nestjs/swagger';
import { User } from '@prisma/client';
import { TradeService } from './trade.service';
import { TradeDto } from './dto';
import { JwtGuard } from 'src/auth/guard';
} from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { JwtGuard } from "src/auth/guard";
import { GetUser } from "../auth/decorator";
import { TradeDto } from "./dto";
import { TradeService } from "./trade.service";
@UseGuards(JwtGuard)
@ApiTags('trade')
@Controller('trade')
@ApiTags("trade")
@Controller("trade")
export class TradeController {
constructor(private tradeService: TradeService) {}
@Get('/all')
@Get("/all")
getAllPromoCodes(@GetUser() user: User) {
return this.tradeService.getTrades(user.id);
}
@HttpCode(HttpStatus.CREATED)
@Post('/create')
@Post("/create")
createPromoCode(
// @GetUser() user: User,
@Body()

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { TradeService } from './trade.service';
import { TradeController } from './trade.controller';
import { Module } from "@nestjs/common";
import { TradeController } from "./trade.controller";
import { TradeService } from "./trade.service";
@Module({
providers: [TradeService],

View File

@ -1,7 +1,7 @@
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { checkUserHasAccount, checkUserIsAdmin } from 'src/utils/checkUser';
import { TradeDto } from './dto';
import { ForbiddenException, Injectable } from "@nestjs/common";
import { checkUserHasAccount, checkUserIsAdmin } from "src/utils/checkUser";
import { PrismaService } from "../prisma/prisma.service";
import { TradeDto } from "./dto";
@Injectable()
export class TradeService {
constructor(private prisma: PrismaService) {}
@ -11,7 +11,7 @@ export class TradeService {
return this.prisma.trade.findMany({
orderBy: {
created_at: 'desc',
created_at: "desc",
},
// include: {
// Giver: true,
@ -43,7 +43,7 @@ export class TradeService {
async getLastTrades() {
return this.prisma.trade.findMany({
orderBy: {
created_at: 'desc',
created_at: "desc",
},
select: {
amount_traded: true,

View File

@ -1,17 +1,17 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
import { GetUser } from '../auth/decorator';
import { JwtGuard } from '../auth/guard';
import { ApiTags } from '@nestjs/swagger';
import { UserService } from './user.service';
import { User } from '@prisma/client';
import { Controller, Get, UseGuards } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { User } from "@prisma/client";
import { GetUser } from "../auth/decorator";
import { JwtGuard } from "../auth/guard";
import { UserService } from "./user.service";
@ApiTags('user')
@ApiTags("user")
@UseGuards(JwtGuard)
@Controller('user')
@Controller("user")
export class UserController {
constructor(private userService: UserService) {}
@Get('/my-assets')
@Get("/my-assets")
GetMyAssets(
@GetUser()
user: User,
@ -19,14 +19,14 @@ export class UserController {
return this.userService.getMyAssets(user.id);
}
@Get('/users-assets')
@Get("/users-assets")
GetAlLAssets(
@GetUser()
user: User,
) {
return this.userService.getUsersAssets(user.id);
}
@Get('/my-trades')
@Get("/my-trades")
GetMyTrades(
@GetUser()
user: User,

View File

@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { Module } from "@nestjs/common";
import { UserController } from "./user.controller";
import { UserService } from "./user.service";
@Module({
providers: [UserService],
controllers: [UserController],

View File

@ -1,8 +1,7 @@
import {Injectable} from "@nestjs/common";
import { PrismaService } from "@/prisma/prisma.service";
import { Injectable } from "@nestjs/common";
import { checkUserHasAccount, checkUserIsAdmin } from "src/utils/checkUser";
@Injectable()
export class UserService {
constructor(private prisma: PrismaService) {}

View File

@ -1,12 +1,12 @@
import { ForbiddenException } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { Roles } from './const/const';
import { ForbiddenException } from "@nestjs/common";
import { PrismaClient } from "@prisma/client";
import { Roles } from "./const/const";
const prisma = new PrismaClient();
export async function checkRoleLevel(userId: string, level: string) {
if (!userId || !level) {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
checkRoleExist(level);
@ -26,13 +26,13 @@ export async function checkRoleLevel(userId: string, level: string) {
if (role?.id) {
checkRoleExist(role.name);
if (level === Roles.ADMIN && role.name !== Roles.ADMIN) {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
} else {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
} else {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
}
@ -42,7 +42,7 @@ function checkRoleExist(role: string) {
case Roles.USER:
break;
default:
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
}
@ -55,10 +55,10 @@ export async function checkUserHasAccount(jwtId: string) {
},
});
if (!user || !user.id) {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
} else {
throw new ForbiddenException('Access to resources denied');
throw new ForbiddenException("Access to resources denied");
}
}
@ -74,13 +74,13 @@ export async function checkUserIsAdmin(jwtId: string) {
},
});
if (!user || !user.id) {
throw new ForbiddenException('Access to resources denied2');
throw new ForbiddenException("Access to resources denied2");
}
if (user.Role.name !== Roles.ADMIN) {
throw new ForbiddenException('Access to resources denied3');
throw new ForbiddenException("Access to resources denied3");
}
} else {
throw new ForbiddenException('Access to resources denied4');
throw new ForbiddenException("Access to resources denied4");
}
}

View File

@ -1,4 +1,4 @@
export const Roles = {
ADMIN: 'admin',
USER: 'user',
ADMIN: "admin",
USER: "user",
};

View File

@ -1,16 +1,16 @@
// auth/test/mocks.ts
import { User } from '@prisma/client';
import { User } from "@prisma/client";
export const getMockUser = (): User => ({
id: 'user-id',
email: 'test@example.com',
firstName: 'Test User',
lastName: 'Test',
hash: 'test-hash',
pseudo: 'test-pseudo',
id: "user-id",
email: "test@example.com",
firstName: "Test User",
lastName: "Test",
hash: "test-hash",
pseudo: "test-pseudo",
isActive: true,
created_at: new Date(),
updated_at: new Date(),
roleId: 'user',
roleId: "user",
dollarAvailables: 1000,
});