Skip to content

Commit

Permalink
src/donations: Remove unnecessary relations from query response (#588)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
sashko9807 authored Dec 18, 2023
1 parent cf7c431 commit 5e1bc83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
)
Expand Down
8 changes: 1 addition & 7 deletions apps/api/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 1 addition & 12 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,25 +461,14 @@ export class DonationsService {
id: string,
keycloakId: string,
email?: string,
): Promise<(Donation & { person: Person | null }) | null> {
): Promise<Donation | null> {
return await this.prisma.donation.findFirst({
where: {
id,
status: DonationStatus.succeeded,
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,
Expand Down

0 comments on commit 5e1bc83

Please sign in to comment.