Skip to content

Instantly share code, notes, and snippets.

@denisrudnei
Last active March 12, 2020 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denisrudnei/c5bbe4308263e84ec2781de8f5fc893d to your computer and use it in GitHub Desktop.
Save denisrudnei/c5bbe4308263e84ec2781de8f5fc893d to your computer and use it in GitHub Desktop.
sacar: (root, {
numero,
valor
}) => {
return new Promise((resolve, reject) => {
Conta.findOne({
numero
})
.then(value => {
newSaldo = value.saldo
if (valor > value.saldo) {
reject(new Error("Saldo Insuficiente"))
} else {
newSaldo = value.saldo - valor
}
})
.then(() => Conta.updateOne({
numero
}, {
$set: {
saldo: newSaldo
}
}))
.then(() => Conta.findOne({
numero
}))
resolve({
saldo: newSaldo
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment