* Add endpoint for account balances * Update changelog --------- Co-authored-by: Pavol Kolcun <pavol.kolcun@student.tuke.sk> Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com>
43 lines
1019 B
TypeScript
43 lines
1019 B
TypeScript
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
|
import { AccountBalancesResponse } from '@ghostfolio/common/interfaces';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { AccountBalance, Prisma } from '@prisma/client';
|
|
|
|
@Injectable()
|
|
export class AccountBalanceService {
|
|
public constructor(private readonly prismaService: PrismaService) {}
|
|
|
|
public async createAccountBalance(
|
|
data: Prisma.AccountBalanceCreateInput
|
|
): Promise<AccountBalance> {
|
|
return this.prismaService.accountBalance.create({
|
|
data
|
|
});
|
|
}
|
|
|
|
public async getAccountBalances({
|
|
accountId,
|
|
userId
|
|
}: {
|
|
accountId: string;
|
|
userId: string;
|
|
}): Promise<AccountBalancesResponse> {
|
|
const balances = await this.prismaService.accountBalance.findMany({
|
|
orderBy: {
|
|
date: 'asc'
|
|
},
|
|
select: {
|
|
date: true,
|
|
id: true,
|
|
value: true
|
|
},
|
|
where: {
|
|
accountId,
|
|
userId
|
|
}
|
|
});
|
|
|
|
return { balances };
|
|
}
|
|
}
|