mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
import { UserInputError } from 'apollo-server'
|
|
|
|
export default async function alreadyExistingMail({ args, context }) {
|
|
const session = context.driver.session()
|
|
try {
|
|
const existingEmailAddressTxPromise = session.writeTransaction(async (transaction) => {
|
|
const existingEmailAddressTransactionResponse = await transaction.run(
|
|
`
|
|
MATCH (email:EmailAddress {email: $email})
|
|
OPTIONAL MATCH (email)-[:BELONGS_TO]-(user)
|
|
RETURN email, user
|
|
`,
|
|
{ email: args.email },
|
|
)
|
|
return existingEmailAddressTransactionResponse.records.map((record) => {
|
|
return {
|
|
alreadyExistingEmail: record.get('email').properties,
|
|
user: record.get('user') && record.get('user').properties,
|
|
}
|
|
})
|
|
})
|
|
const [emailBelongsToUser] = await existingEmailAddressTxPromise
|
|
const { alreadyExistingEmail, user } = emailBelongsToUser || {}
|
|
if (user) throw new UserInputError('A user account with this email already exists.')
|
|
return alreadyExistingEmail
|
|
} finally {
|
|
session.close()
|
|
}
|
|
}
|