Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Allow for soft deleting the person #667

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Soft delete by person id instead of keycloakid
  • Loading branch information
sashko9807 committed Sep 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2d24a81626f36646fab868c785a7267ec339d692
3 changes: 2 additions & 1 deletion apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -494,6 +494,7 @@ export class AuthService {
async deleteUser(keycloakId: string) {
const user = await this.personService.findOneByKeycloakId(keycloakId)

if (!user) throw new NotFoundException('User not found')
//Check and throw if user is a beneficiary, organizer or corporate profile
if ((!!user && user.beneficiaries.length > 0) || user?.organizer || user?.companyId) {
throw new InternalServerErrorException(
@@ -503,7 +504,7 @@ export class AuthService {

return this.authenticateAdmin()
.then(() => this.admin.users.del({ id: keycloakId }))
.then(() => this.personService.softDelete(keycloakId))
.then(() => this.personService.softDelete(user.id))
.then(() => Logger.log(`User with keycloak id ${keycloakId} was successfully deleted!`))
.catch((err) => {
const errorMessage = `Deleting user fails with reason: ${err.message ?? 'server error!'}`
2 changes: 1 addition & 1 deletion apps/api/src/person/person.service.ts
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ export class PersonService {

async softDelete(id: string) {
return await this.prisma.person.update({
where: { keycloakId: id },
where: { id },
data: {
firstName: '',
lastName: '',