mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Remove neode update from production code
- Favor transaction functions we have more control over
This commit is contained in:
parent
6903a6cc71
commit
8a93e402b9
@ -101,23 +101,37 @@ export default {
|
|||||||
const blockedUser = await neode.find('User', args.id)
|
const blockedUser = await neode.find('User', args.id)
|
||||||
return blockedUser.toJson()
|
return blockedUser.toJson()
|
||||||
},
|
},
|
||||||
UpdateUser: async (object, args, context, resolveInfo) => {
|
UpdateUser: async (_parent, params, context, _resolveInfo) => {
|
||||||
const { termsAndConditionsAgreedVersion } = args
|
const { termsAndConditionsAgreedVersion } = params
|
||||||
if (termsAndConditionsAgreedVersion) {
|
if (termsAndConditionsAgreedVersion) {
|
||||||
const regEx = new RegExp(/^[0-9]+\.[0-9]+\.[0-9]+$/g)
|
const regEx = new RegExp(/^[0-9]+\.[0-9]+\.[0-9]+$/g)
|
||||||
if (!regEx.test(termsAndConditionsAgreedVersion)) {
|
if (!regEx.test(termsAndConditionsAgreedVersion)) {
|
||||||
throw new ForbiddenError('Invalid version format!')
|
throw new ForbiddenError('Invalid version format!')
|
||||||
}
|
}
|
||||||
args.termsAndConditionsAgreedAt = new Date().toISOString()
|
params.termsAndConditionsAgreedAt = new Date().toISOString()
|
||||||
}
|
}
|
||||||
args = await fileUpload(args, { file: 'avatarUpload', url: 'avatar' })
|
params = await fileUpload(params, { file: 'avatarUpload', url: 'avatar' })
|
||||||
|
const session = context.driver.session()
|
||||||
|
|
||||||
|
const writeTxResultPromise = session.writeTransaction(async transaction => {
|
||||||
|
const updateUserTransactionResponse = await transaction.run(
|
||||||
|
`
|
||||||
|
MATCH (user:User {id: $params.id})
|
||||||
|
SET user += $params
|
||||||
|
SET user.updatedAt = toString(datetime())
|
||||||
|
RETURN user
|
||||||
|
`,
|
||||||
|
{ params },
|
||||||
|
)
|
||||||
|
return updateUserTransactionResponse.records.map(record => record.get('user').properties)
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const user = await neode.find('User', args.id)
|
const [user] = await writeTxResultPromise
|
||||||
if (!user) return null
|
return user
|
||||||
await user.update({ ...args, updatedAt: new Date().toISOString() })
|
} catch (error) {
|
||||||
return user.toJson()
|
throw new UserInputError(error.message)
|
||||||
} catch (e) {
|
} finally {
|
||||||
throw new UserInputError(e.message)
|
session.close()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DeleteUser: async (object, params, context, resolveInfo) => {
|
DeleteUser: async (object, params, context, resolveInfo) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user