Browse Source

update in code

pull/2484/head
Pavol Kolcun 2 years ago
committed by Thomas
parent
commit
62a17688ce
  1. 10
      apps/api/src/app/account/account.controller.ts
  2. 20
      apps/api/src/services/account-balance/account-balance.service.ts

10
apps/api/src/app/account/account.controller.ts

@ -37,12 +37,12 @@ import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/
@Controller('account') @Controller('account')
export class AccountController { export class AccountController {
public constructor( public constructor(
private readonly accountService: AccountService,
private readonly accountBalanceService: AccountBalanceService, private readonly accountBalanceService: AccountBalanceService,
private readonly accountService: AccountService,
private readonly impersonationService: ImpersonationService, private readonly impersonationService: ImpersonationService,
private readonly portfolioService: PortfolioService, private readonly portfolioService: PortfolioService,
@Inject(REQUEST) private readonly request: RequestWithUser @Inject(REQUEST) private readonly request: RequestWithUser
) {} ) { }
@Delete(':id') @Delete(':id')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@ -125,8 +125,10 @@ export class AccountController {
public async getAccountBalancesById( public async getAccountBalancesById(
@Param('id') id: string @Param('id') id: string
): Promise<AccountBalances> { ): Promise<AccountBalances> {
return this.accountBalanceService.getAccountBalances({
return await this.accountBalanceService.getAccountBalances(id); accountId: id,
userId: this.request.user.id
});
} }
@Post() @Post()

20
apps/api/src/services/account-balance/account-balance.service.ts

@ -5,7 +5,7 @@ import { AccountBalance, Prisma } from '@prisma/client';
@Injectable() @Injectable()
export class AccountBalanceService { export class AccountBalanceService {
public constructor(private readonly prismaService: PrismaService) {} public constructor(private readonly prismaService: PrismaService) { }
public async createAccountBalance( public async createAccountBalance(
data: Prisma.AccountBalanceCreateInput data: Prisma.AccountBalanceCreateInput
@ -15,17 +15,25 @@ export class AccountBalanceService {
}); });
} }
public async getAccountBalances(accountId: string): Promise<AccountBalances> { public async getAccountBalances({
accountId,
userId
}: {
accountId: string;
userId: string;
}): Promise<AccountBalances> {
const balances = await this.prismaService.accountBalance.findMany({ const balances = await this.prismaService.accountBalance.findMany({
where: {
accountId: accountId,
},
select: { select: {
date: true, date: true,
id: true, id: true,
value: true value: true
},
where: {
accountId,
userId
} }
}); });
return { balances }
return { balances };
} }
} }

Loading…
Cancel
Save