mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1019 B
42 lines
1019 B
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 };
|
|
}
|
|
}
|
|
|