mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-09 14:00:12 +02:00
added endpoint to get offers by crypto id
This commit is contained in:
parent
9cca2e1ede
commit
82549fdad2
@ -29,6 +29,10 @@ export class OfferController {
|
||||
getAllOffers(@GetUser() user: User) {
|
||||
return this.offerService.getOffers(user.id);
|
||||
}
|
||||
@Get('/crypto/:id')
|
||||
getOffersByCryptoId(@GetUser() user: User, @Param('id') cryptoId: string) {
|
||||
return this.offerService.getOffersByCrypto(user.id, cryptoId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@Post('/create')
|
||||
|
@ -31,6 +31,30 @@ export class OfferService {
|
||||
});
|
||||
}
|
||||
|
||||
async getOffersByCrypto(userId: string, cryptoId: string) {
|
||||
await checkUserHasAccount(userId);
|
||||
return this.prisma.offer.findMany({
|
||||
where: {
|
||||
id_crypto: cryptoId,
|
||||
},
|
||||
orderBy: {
|
||||
amount: 'desc',
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
User: {
|
||||
select: {
|
||||
pseudo: true,
|
||||
},
|
||||
},
|
||||
amount: true,
|
||||
created_at: true,
|
||||
id_user: true,
|
||||
Crypto: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async createOffer(userId: string, dto: OfferDto) {
|
||||
await checkUserHasAccount(userId);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user