From 5e1bc83b6f2f7c123433ce405fbcccc451f84051 Mon Sep 17 00:00:00 2001 From: Aleksandar Petkov Date: Mon, 18 Dec 2023 22:13:21 +0200 Subject: [PATCH] src/donations: Remove unnecessary relations from query response (#588) * src/auth: Add companyName as keycloak attribute * src/donations: Remove person relation from user/:id response Donor's names will be claimed by the session token. --- apps/api/src/auth/auth.service.ts | 4 ++-- apps/api/src/donations/donations.controller.ts | 8 +------- apps/api/src/donations/donations.service.ts | 13 +------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index 2f058e8e6..90e53760e 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -252,7 +252,7 @@ export class AuthService { emailVerified: true, groups: [], requiredActions: verifyEmail ? [RequiredActionAlias.VERIFY_EMAIL] : [], - attributes: { selfReg: true }, + attributes: { selfReg: true, companyName: registerDto.companyName }, credentials: [ { type: 'password', @@ -433,7 +433,7 @@ export class AuthService { const user = await this.personService.findOneByKeycloakId(keycloakId) //Check and throw if user is a beneficiary, organizer or corporate profile - if (!!user && user.beneficiaries.length > 0 || user?.organizer || user?.companyId) { + if ((!!user && user.beneficiaries.length > 0) || user?.organizer || user?.companyId) { throw new InternalServerErrorException( 'Cannot delete a beneficiary, organizer or corporate profile', ) diff --git a/apps/api/src/donations/donations.controller.ts b/apps/api/src/donations/donations.controller.ts index 90e004cee..6ad0c7efd 100644 --- a/apps/api/src/donations/donations.controller.ts +++ b/apps/api/src/donations/donations.controller.ts @@ -178,13 +178,7 @@ export class DonationsController { @Get('user/:id') async userDonationById(@Param('id') id: string, @AuthenticatedUser() user: KeycloakTokenParsed) { const donation = await this.donationsService.getUserDonationById(id, user.sub, user.email) - return { - ...donation, - person: { - firstName: user.given_name, - lastName: user.family_name, - }, - } + return donation } @Post('payment-intent') diff --git a/apps/api/src/donations/donations.service.ts b/apps/api/src/donations/donations.service.ts index 6160f51de..ab2328245 100644 --- a/apps/api/src/donations/donations.service.ts +++ b/apps/api/src/donations/donations.service.ts @@ -461,7 +461,7 @@ export class DonationsService { id: string, keycloakId: string, email?: string, - ): Promise<(Donation & { person: Person | null }) | null> { + ): Promise { return await this.prisma.donation.findFirst({ where: { id, @@ -469,17 +469,6 @@ export class DonationsService { OR: [{ billingEmail: email }, { person: { keycloakId } }], }, include: { - person: { - select: { - id: true, - firstName: true, - lastName: true, - company: { select: { companyName: true } }, - }, - }, - affiliate: { - select: { company: { select: { companyName: true } } }, - }, targetVault: { select: { id: true,