mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2444 from gradido/fix-delete-email-contact
fix(backend): delete / undelete email contact as well
This commit is contained in:
commit
effa58d767
@ -366,6 +366,19 @@ describe('AdminResolver', () => {
|
||||
expect(new Date(result.data.deleteUser)).toEqual(expect.any(Date))
|
||||
})
|
||||
|
||||
it('has deleted_at set in users and user contacts', async () => {
|
||||
await expect(
|
||||
User.findOneOrFail({
|
||||
where: { id: user.id },
|
||||
withDeleted: true,
|
||||
relations: ['emailContact'],
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
deletedAt: expect.any(Date),
|
||||
emailContact: expect.objectContaining({ deletedAt: expect.any(Date) }),
|
||||
})
|
||||
})
|
||||
|
||||
describe('delete deleted user', () => {
|
||||
it('throws an error', async () => {
|
||||
jest.clearAllMocks()
|
||||
@ -489,6 +502,15 @@ describe('AdminResolver', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('has deleted_at set to null in users and user contacts', async () => {
|
||||
await expect(
|
||||
User.findOneOrFail({ where: { id: user.id }, relations: ['emailContact'] }),
|
||||
).resolves.toMatchObject({
|
||||
deletedAt: null,
|
||||
emailContact: expect.objectContaining({ deletedAt: null }),
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -200,7 +200,7 @@ export class AdminResolver {
|
||||
@Arg('userId', () => Int) userId: number,
|
||||
@Ctx() context: Context,
|
||||
): Promise<Date | null> {
|
||||
const user = await dbUser.findOne({ id: userId })
|
||||
const user = await dbUser.findOne({ where: { id: userId }, relations: ['emailContact'] })
|
||||
// user exists ?
|
||||
if (!user) {
|
||||
logger.error(`Could not find user with userId: ${userId}`)
|
||||
@ -214,6 +214,7 @@ export class AdminResolver {
|
||||
}
|
||||
// soft-delete user
|
||||
await user.softRemove()
|
||||
await user.emailContact.softRemove()
|
||||
const newUser = await dbUser.findOne({ id: userId }, { withDeleted: true })
|
||||
return newUser ? newUser.deletedAt : null
|
||||
}
|
||||
@ -221,7 +222,10 @@ export class AdminResolver {
|
||||
@Authorized([RIGHTS.UNDELETE_USER])
|
||||
@Mutation(() => Date, { nullable: true })
|
||||
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
|
||||
const user = await dbUser.findOne({ id: userId }, { withDeleted: true })
|
||||
const user = await dbUser.findOne(
|
||||
{ id: userId },
|
||||
{ withDeleted: true, relations: ['emailContact'] },
|
||||
)
|
||||
if (!user) {
|
||||
logger.error(`Could not find user with userId: ${userId}`)
|
||||
throw new Error(`Could not find user with userId: ${userId}`)
|
||||
@ -231,6 +235,7 @@ export class AdminResolver {
|
||||
throw new Error('User is not deleted')
|
||||
}
|
||||
await user.recover()
|
||||
await user.emailContact.recover()
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user