Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createRouteExec(request, response) {
// Build request params
const { name, datalab, port } = matchedData(request);
return proxyRouteApi.createOrUpdateRoute(name, datalab, port)
.then(controllerHelper.sendSuccessfulCreation(response))
.catch(controllerHelper.handleError(response, 'creating', TYPE, name));
}
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
errors = utils_1.getErrors(req);
if (!errors.isEmpty()) {
return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
}
data = __assign({}, filter.matchedData(req), { user_id: req.user.id, completed_at: null, deleted_at: null });
return [4 /*yield*/, todoRepo_1.createTodo(data)];
case 1:
_a.sent();
res.status(201).json({ created: true });
return [2 /*return*/];
}
});
}); });
], (req, res) => {
const objErrors = validationResult(req);
if (!objErrors.isEmpty()) {
return res.status(422).json({ errors: objErrors.mapped() });
}
const data = matchedData(req);
let arrParams = [];
let strSqlWhere = 'stable = 1';
let nRoundDisplayDecimals = conf.tokenDisplayDecimals;
if (data.filter_currency && data.filter_currency !== 'all') {
strSqlWhere += ' AND currency = ?';
arrParams.push(data.filter_currency);
nRoundDisplayDecimals = getNumberRoundDisplayDecimalsOfCurrency(data.filter_currency);
}
if (data.filter_date_from && data.filter_date_to) {
strSqlWhere += ' AND paid_date BETWEEN ? AND ?';
arrParams.push(
moment(data.filter_date_from).format('YYYY-MM-DD 00:00:01'),
moment(data.filter_date_to).format('YYYY-MM-DD 23:59:59')
);
const register = catchErrors(async (req: Request, res: Response) => {
const errors = getErrors(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.mapped() });
}
const data: any = filter.matchedData(req);
const user = await findUserByEmail(data.email);
if(user){
return res.status(422).json(formatError(EMAIL_ALREADY_IN_USE));
}
const token: string = await generateRandomToken();
const createdUser = await createUser({...data, verify_token: token});
const userModel = createdUser.get({ plain: true });
await associateRole(userModel.id, getRoleId(USER_ROLE));
const userInfo = {
_id: userModel.id,
first_name: userModel.first_name,
assignements,
});
})
.catch(reason => {
return buildForm(req, res, next, values, { global: reason });
});
})
.catch(err => {
throw err;
});
})
.catch(reason => {
return buildForm(req, res, next, values, { global: reason });
});
} catch (err) {
const values = matchedData(req, { onlyValidData: false });
return buildForm(req, res, next, values, err.mapped());
}
});
const update = catchErrors(async (req: Request, res: Response) => {
const user = req.user;
if(user.id.toString() !== req.params.userId){
throw new UnauthorizedError();
}
const errors = getErrors(req);
if(!errors.isEmpty()) {
return res.status(422).json({ errors: errors.mapped() });
}
const data: any = filter.matchedData(req);
await updateUser(user.id, data);
res.status(200).json({ updated: true});
});
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
user = req.user;
if (user.id.toString() !== req.params.userId) {
throw new errors_1.UnauthorizedError();
}
errors = utils_1.getErrors(req);
if (!errors.isEmpty()) {
return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
}
data = filter.matchedData(req);
return [4 /*yield*/, userRepo_1.updateUser(user.id, data)];
case 1:
_a.sent();
res.status(200).json({ updated: true });
return [2 /*return*/];
}
});
}); });
function middleware(req, res, next) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return next({
status: 422,
message: Constants.Error.VALIDATION_422_MESSAGE,
data: errors.mapped()
});
}
req.body = matchedData(req);
return next();
}
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
errors = utils_1.getErrors(req);
if (!errors.isEmpty()) {
return [2 /*return*/, res.status(422).json({ errors: errors.mapped() })];
}
data = filter.matchedData(req);
return [4 /*yield*/, userRepo_1.findUserByResetPasswordToken(data.token)];
case 1:
user = _d.sent();
if (!user) {
return [2 /*return*/, res.status(422).json(utils_1.formatError(errors_1.INVALID_PASSWORD_RESET_TOKEN))];
}
olderThanOneHour = (Date.now() - (new Date(user.password_reset_token_expired_at).getTime())) > constants_1.ONE_HOUR;
if (olderThanOneHour) {
return [2 /*return*/, res.status(422).json(utils_1.formatError(errors_1.EXPIRED_PASSWORD_RESET_TOKEN))];
}
_b = (_a = user).update;
_c = {
password_reset_token: null,
password_reset_token_expired_at: null
};
return [4 /*yield*/, utils_2.generateHash(data.password)];
const updateTodo = catchErrors(async (req: Request, res: Response) => {
const errors = getErrors(req);
if(!errors.isEmpty()) {
return res.status(422).json({ errors: errors.mapped() });
}
const data: any = filter.matchedData(req);
const todoId = req.params.todoId;
const todo = await getTodoById(todoId);
if(todo.user_id !== req.user.id){
throw new ForbiddenError();
}
await updateTodoById(todoId, data);
res.status(200).json({ updated: true });
});