|
@ -57,9 +57,11 @@ export class AccountService { |
|
|
Platform?: Platform; |
|
|
Platform?: Platform; |
|
|
})[] |
|
|
})[] |
|
|
> { |
|
|
> { |
|
|
const { include, skip, take, cursor, where, orderBy } = params; |
|
|
const { include = {}, skip, take, cursor, where, orderBy } = params; |
|
|
|
|
|
|
|
|
return this.prismaService.account.findMany({ |
|
|
include.balances = { orderBy: { createdAt: 'desc' }, take: 1 }; |
|
|
|
|
|
|
|
|
|
|
|
const accounts = await this.prismaService.account.findMany({ |
|
|
cursor, |
|
|
cursor, |
|
|
include, |
|
|
include, |
|
|
orderBy, |
|
|
orderBy, |
|
@ -67,15 +69,32 @@ export class AccountService { |
|
|
take, |
|
|
take, |
|
|
where |
|
|
where |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return accounts.map((account) => { |
|
|
|
|
|
return { ...account, balance: account.balances[0]?.value ?? 0 }; |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async createAccount( |
|
|
public async createAccount( |
|
|
data: Prisma.AccountCreateInput, |
|
|
data: Prisma.AccountCreateInput, |
|
|
aUserId: string |
|
|
aUserId: string |
|
|
): Promise<Account> { |
|
|
): Promise<Account> { |
|
|
return this.prismaService.account.create({ |
|
|
const account = await this.prismaService.account.create({ |
|
|
data |
|
|
data |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await this.prismaService.accountBalance.create({ |
|
|
|
|
|
data: { |
|
|
|
|
|
Account: { |
|
|
|
|
|
connect: { |
|
|
|
|
|
id_userId: { id: account.id, userId: aUserId } |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
value: <any>data.balance |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return account; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async deleteAccount( |
|
|
public async deleteAccount( |
|
@ -90,7 +109,6 @@ export class AccountService { |
|
|
public async getAccounts(aUserId: string) { |
|
|
public async getAccounts(aUserId: string) { |
|
|
const accounts = await this.accounts({ |
|
|
const accounts = await this.accounts({ |
|
|
include: { |
|
|
include: { |
|
|
balances: { orderBy: { createdAt: 'desc' }, take: 1 }, |
|
|
|
|
|
Order: true, |
|
|
Order: true, |
|
|
Platform: true |
|
|
Platform: true |
|
|
}, |
|
|
}, |
|
@ -153,16 +171,13 @@ export class AccountService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const accounts = await this.accounts({ |
|
|
const accounts = await this.accounts({ |
|
|
where, |
|
|
where |
|
|
include: { |
|
|
|
|
|
balances: { orderBy: { createdAt: 'desc' }, take: 1 } |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
for (const account of accounts) { |
|
|
for (const account of accounts) { |
|
|
totalCashBalanceInBaseCurrency = totalCashBalanceInBaseCurrency.plus( |
|
|
totalCashBalanceInBaseCurrency = totalCashBalanceInBaseCurrency.plus( |
|
|
this.exchangeRateDataService.toCurrency( |
|
|
this.exchangeRateDataService.toCurrency( |
|
|
account.balances[0].value, |
|
|
account.balance, |
|
|
account.currency, |
|
|
account.currency, |
|
|
currency |
|
|
currency |
|
|
) |
|
|
) |
|
|