mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
replace username too
This commit is contained in:
parent
deddb51c42
commit
bd612bd310
2 changed files with 23 additions and 8 deletions
|
|
@ -42,7 +42,7 @@ import {
|
|||
import { userRepository } from '../../repository/user'
|
||||
import { createUser } from '../../services/create_user'
|
||||
import { sendVerificationEmail } from '../../services/send_emails'
|
||||
import { updateUser } from '../../services/user'
|
||||
import { softDeleteUser } from '../../services/user'
|
||||
import { authorized, userDataToUser } from '../../utils/helpers'
|
||||
import { validateUsername } from '../../utils/usernamePolicy'
|
||||
import { WithDataSourcesContext } from '../types'
|
||||
|
|
@ -321,11 +321,7 @@ export const deleteAccountResolver = authorized<
|
|||
MutationDeleteAccountArgs
|
||||
>(async (_, { userID }, { log }) => {
|
||||
// soft delete user and change email address for user to sign up again
|
||||
const result = await updateUser(userID, {
|
||||
status: StatusType.Deleted,
|
||||
email: `deleted_user_${userID}@omnivore.app`,
|
||||
sourceUserId: `deleted_user_${userID}`,
|
||||
})
|
||||
const result = await softDeleteUser(userID)
|
||||
if (!result.affected) {
|
||||
log.error('Error deleting user account')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { DeepPartial, FindOptionsWhere, In } from 'typeorm'
|
||||
import { Profile } from '../entity/profile'
|
||||
import { StatusType, User } from '../entity/user'
|
||||
import { authTrx, getRepository, queryBuilderToRawSql } from '../repository'
|
||||
import { userRepository } from '../repository/user'
|
||||
|
|
@ -14,9 +15,27 @@ export const deleteUser = async (userId: string) => {
|
|||
)
|
||||
}
|
||||
|
||||
export const updateUser = async (userId: string, update: Partial<User>) => {
|
||||
export const softDeleteUser = async (userId: string) => {
|
||||
return authTrx(
|
||||
async (t) => t.getRepository(User).update(userId, update),
|
||||
async (t) => {
|
||||
// change email address and username for user to sign up again
|
||||
await t.getRepository(Profile).update(
|
||||
{
|
||||
user: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
{
|
||||
username: `deleted_user_${userId}`,
|
||||
}
|
||||
)
|
||||
|
||||
return t.getRepository(User).update(userId, {
|
||||
status: StatusType.Deleted,
|
||||
email: `deleted_user_${userId}@omnivore.app`,
|
||||
sourceUserId: `deleted_user_${userId}`,
|
||||
})
|
||||
},
|
||||
undefined,
|
||||
userId
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue