mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2026-02-07 02:46:13 +01:00
testing all features
This commit is contained in:
31
src/user/user.controller.ts
Normal file
31
src/user/user.controller.ts
Normal 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
8
src/user/user.module.ts
Normal 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
31
src/user/user.service.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user