testing all features

This commit is contained in:
Kevsl
2024-06-06 16:31:31 +02:00
commit 9f5c23c7c9
74 changed files with 18541 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/* eslint-disable prettier/prettier */
import { Body, 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';
@ApiTags('user')
@UseGuards(JwtGuard)
@Controller('user')
export class UserController {
constructor(private userService: UserService) {}
@Get('/my-assets')
GetMyAssets(
@Body()
@GetUser()
user: User
) {
return this.userService.GetMyAssets(user.id);
}
@Get('/my-trades')
GetMyTrades(
@Body()
@GetUser()
user: User
) {
return this.userService.GetMyTrades(user.id);
}
}

8
src/user/user.module.ts Normal file
View File

@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
@Module({
providers: [UserService],
controllers: [UserController],
})
export class UserModule {}

31
src/user/user.service.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class UserService {
constructor(private prisma: PrismaService) {}
async GetMyAssets(userId: string) {
const user = await this.prisma.user.findUnique({
where: {
id: userId,
},
include: {
UserHasCrypto: true,
},
});
return user;
}
async GetMyTrades(userId: string) {
const user = await this.prisma.trade.findMany({
where: {
OR: [{ id_giver: userId }, { id_receiver: userId }],
},
include: {
Crypto: true,
},
});
return user;
}
}