I am new using Neo4J and I came across this error today, in my conception, I am closing and opening the sessions, however I am receiving this error.
I simply want to know if there is already a node with the email received in the request, if yes, do not register, if not, then do the registration normally.
does anyone have any idea where I'm going wrong, again I'm a layman in neo4j
thanks in advance
exports.createUser = (req, res) => {
const userName = req.body.name;
const userEmail = req.body.email;
const userPassword = req.body.password;
const alreadyRegistered =
session.run(
`MATCH (n { email: '${userEmail}' })
RETURN n`
);
alreadyRegistered.then(result => {
session.close();
if(result.records.length){
res.send('Já existi um usuário com este e-mail cadastrado');
}
});
const create =
session.run(
`CREATE (n:User {name: '${userName}', email: '${userEmail}', password: '${userPassword}'})
RETURN n`
);
create.then(result => {
session.close();
const singleRecord = result.records[0];
const node = singleRecord.get(0);
res.send(`Usuário ${userName} cadastrado com sucesso`)
driver.close();
});
};