Created
February 25, 2019 10:07
-
-
Save tntdev21/8043ebc41c00c5155fd8e5d462a194d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { User } from '../../models' | |
import { userLocale } from '../../locales' | |
import service from './service' | |
import responseBuilder from '../../utils/response-builder' | |
import errorUtil from '../../utils/error' | |
import to from '../../utils/to' | |
async function show(req, res) { | |
const [error, user] = await to(User.commonUserData(req.user)) | |
if (error) { | |
return res.jsonp(responseBuilder.build(false, {}, errorUtil.parseError(error))) | |
} | |
res.jsonp(responseBuilder.build(true, { user })) | |
} | |
async function register(req, res) { | |
const [error, user] = await to(service.signupUser(req.body)) | |
if (error) { | |
if (error.code === 11000) { | |
return res.jsonp(responseBuilder.build(false, {}, errorUtil.parseError(userLocale.userExisted))) | |
} | |
return res.jsonp(responseBuilder.build(false, {}, errorUtil.parseError(error))) | |
} | |
res.jsonp(responseBuilder.build(true, { user })) | |
} | |
export default { | |
show, | |
register, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment