const { PG_UNIQUE_VIOLATION, PG_NOT_NULL_VIOLATION } = require('postgres-error-codes')
async function createUserMethod(req, res, next) {
try {
// Run insert user SQL
} catch (err) {
// If user with same email already exists
if (err.code === PG_UNIQUE_VIOLATION) {
return next('Email already exists!')
}
// Param should not be null
if (err.code === PG_NOT_NULL_VIOLATION) {
return next('Email required!')
}
next(err)
}
}