mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
attempt to write resolver functions
This commit is contained in:
parent
02411347a7
commit
da76ae7aab
2 changed files with 50 additions and 0 deletions
|
|
@ -327,6 +327,17 @@ class UserModel extends DataModel<UserData, CreateSet, UpdateSet> {
|
|||
}
|
||||
return this.kx.transaction((tx) => this.updateProfile(userId, set, tx))
|
||||
}
|
||||
|
||||
@logMethod
|
||||
deleteUser(userId: string, tx: Knex.Transaction): boolean {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const result = super.delete(userId, tx) as any
|
||||
if (result.error) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default UserModel
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import {
|
||||
DeleteAccountSuccess,
|
||||
DeleteAccountError,
|
||||
DeleteAccountErrorCode,
|
||||
MutationDeleteAccountArgs,
|
||||
GoogleSignupResult,
|
||||
LoginErrorCode,
|
||||
LoginResult,
|
||||
|
|
@ -355,3 +359,38 @@ export const signupResolver: ResolverFn<
|
|||
return { errorCodes: [SignupErrorCode.Unknown] }
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteAccountResolver = authorized<
|
||||
DeleteAccountSuccess,
|
||||
DeleteAccountError,
|
||||
MutationDeleteAccountArgs
|
||||
>(async (_, { userID }, { models, claims, log }) => {
|
||||
const user = await models.user.get(userID)
|
||||
|
||||
if (!user || user.id !== claims.uid) {
|
||||
return {
|
||||
errorCodes: [DeleteAccountErrorCode.Unauthorized],
|
||||
}
|
||||
}
|
||||
|
||||
const deleteUserResult = await authTrx((tx) =>
|
||||
models.user.deleteUser(userID as string, tx)
|
||||
)
|
||||
|
||||
if (!deleteUserResult) {
|
||||
return {
|
||||
errorCodes: [DeleteAccountErrorCode.Forbidden],
|
||||
}
|
||||
}
|
||||
|
||||
log.info('Deleting a user account', {
|
||||
userID,
|
||||
labels: {
|
||||
source: 'resolver',
|
||||
resolver: 'deleteAccountResolver',
|
||||
uid: claims.uid,
|
||||
},
|
||||
})
|
||||
|
||||
return { userID }
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue