Skip to content

Instantly share code, notes, and snippets.

Nitish Phanse nitish24p

Block or report user

Report or block nitish24p

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View User.js
const user = {
id: 1,
username: 'Nitish',
age: 25,
profession: 'dev'
}
const error = new TypeError('Something broke in the db');
class User {
View UserCallback.js
exports.createOrAddUser = (req, res, next) => {
User.findUser(req.body, (err, data) => {
if (err) {
return next(err)
};
if (data) {
const existingUser = new User(data);
existingUser.update(req.body, (err, data) => {
if (err) {
View UserPromise.js
exports.createOrAddUserPromise = (req, res, next) => {
User.findUserPromise(req.body)
.then(user => {
if (user) {
const existingUser = new User(user);
return newUser.updatePromise(req.body)
}
const newUser = new User();
return newUser.savePromise(req.body);
})
View AsyncUser.js
exports.createOrAddUserAsync = async (req, res, next) => {
try {
const user = await User.findUserPromise(req.body);
if (user) {
const existingUser = new User(user);
const data = await existingUser.updatePromise(req.body);
return res.send(data);
}
const newUser = new User();
You can’t perform that action at this time.