import messages from '../../../config/messages'; import { handler as ErrorHandler } from '../../middlewares/error'; import User from '../../../common/models/user.model'; exports.register = async (req, res, next) => { const user = new User( req.body ); user.save() .then(data => { res.json({ code: 0, message: messages.CREATE_SUCCESS, data: User.transform(data) }); }).catch(ex => { ErrorHandler(ex, req, res, next); }); }; exports.login = async (req, res, next) => { res.json({ code: 0, message: null, data: { token: req.locals.token, user: req.locals.user } }); }; exports.loginToken = async (req, res, next) => res.json({ code: 0, message: messages.CREATE_SUCCESS, data: { token: req.locals.token, data: req.locals.user } });