-
-
Save denisrudnei/c5bbe4308263e84ec2781de8f5fc893d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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