Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.register = async (req, res, next) => {
try {
const userData = omit(req.body, 'role');
const user = await new User(userData).save();
const userTransformed = user.transform();
const token = generateTokenResponse(user, user.token());
res.status(httpStatus.CREATED);
return res.json({ token, user: userTransformed });
} catch (error) {
return next(User.checkDuplicateEmail(error));
}
};
create: async (req, res, next) => {
try {
const newThread = new Thread(req.body);
newThread.author = req.user;
await newThread.save();
return res.status(httpStatus.CREATED).json(newThread);
} catch (err) {
return next(err);
}
},
delete: async (req, res, next) => {
return res.status(httpstatus.CONFLICT)
.send({
code: 'MLMOD14',
error: err.message,
location: err.location,
});
}
else {
return errors.unknownError(res, err);
}
}
}
case 'numbers': {
try {
const model = await numbers.trainClassifier(req.project);
return res.status(httpstatus.CREATED).json(returnNumberClassifier(model));
}
catch (err) {
return errors.unknownError(res, err);
}
}
case 'sounds':
return errors.notImplemented(res);
}
}
const createUser = catchAsync(async (req, res) => {
const user = await userService.createUser(req.body);
res.status(httpStatus.CREATED).send(user.transform());
});
const registerUser = async (req, res, next) => {
let newUser;
try {
await validation.register(req.body);
newUser = await service.register(req.body);
} catch (error) {
return next(error);
}
delete newUser.password;
delete newUser.salt;
delete newUser.imap_password;
return res.status(status.CREATED).json({ newUser });
};
exports.register = async (req, res, next) => {
try {
const activationKey = uuidv1()
const body = req.body
body.activationKey = activationKey
const user = new User(body)
const savedUser = await user.save()
res.status(httpStatus.CREATED)
res.send(savedUser.transform())
} catch (error) {
return next(User.checkDuplicateEmailError(error))
}
}
.then((user) => {
return res.status(httpstatus.CREATED).json({
id : user.id,
token : user.token,
sessionExpiry : user.sessionExpiry,
jwt : auth.generateJwt(user),
});
})
.catch((err) => {
create: async function(req, res) {
const transaction = await transactionsDAL.create(req.body);
res.status(httpStatus.CREATED).json(jsonResponse.create(httpStatus.CREATED, transaction));
},
update: async function(req, res) {
export const signup = async (req, res, next) => {
try {
const data = req.body;
const result = await authService.signup(data);
return Response.success(res, result, httpStatus.CREATED);
} catch (exception) {
next(exception);
}
};
export async function create(req, res, next) {
const body = filteredBody(req.body, contants.WHITELIST.posts.create);
try {
return res
.status(HTTPStatus.CREATED)
.json(await Post.createPost(body, req.user._id));
} catch (err) {
err.status = HTTPStatus.BAD_REQUEST;
return next(err);
}
}