Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { isEmail } from '../../../../utils/validate';
import { maybe, required, restrictToSchema}from 'rulr';
import { ModelNotFoundError} from '../../../../utils/errors';
import {v4} from 'uuid';
import {OK} from 'http-status-codes';
const validateForgetPassword = maybe(
restrictToSchema({
email: required(isEmail)
})
);
export default (config: Config) => {
return catchErrors(config, async (req, res)=> {
validateForgetPassword(req.body, ['user']);
const {email} = req.body;
const errorId = v4();
try {
await config.service.forgetPassword({email});
const message = config.translator.passwordReminderSent(email);
res.status(OK).json({message});
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { isEmail } from '../../../../utils/validate';
import { maybe, required, restrictToSchema, checkType } from 'rulr';
import { OK } from 'http-status-codes';
const validateLogin = maybe(
restrictToSchema({
email: required(isEmail),
password: required(checkType(String))
})
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
validateLogin(req.body, ['user']);
const {email, password} = req.body;
const {user, token} = await config.service.login({
email, password
});
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_GET_COMMENTS } from '../../../../utils/constants';
import { maybe, optional,checkType, restrictToSchema }from 'rulr';
import { isValidSortObject } from '../../../../utils/validate';
const validateGetComments = maybe(
restrictToSchema({
limit: optional(checkType(String)),
offset: optional(checkType(String)),
sort: optional(isValidSortObject())
}),
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({ permissions, permissionName: CAN_GET_COMMENTS});
validateGetComments(req.query,['comments']);
const {limit, offset, sort} = req.query;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_GET_ROLES } from '../../../../utils/constants';
import { maybe, optional, checkType, restrictToSchema } from 'rulr';
import { isValidSortObject } from '../../../../utils/validate';
const validateGetRoles = maybe(
restrictToSchema({
limit: optional(checkType(String)),
offset: optional(checkType(String)),
sort: optional(isValidSortObject())
}),
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({ permissions, permissionName: CAN_GET_ROLES});
validateGetRoles(req.query,['roles']);
const {limit, offset, sort} = req.query;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_GET_USERS } from '../../../../utils/constants';
import { maybe, optional, checkType, restrictToSchema } from 'rulr';
import { isValidSortObject } from '../../../../utils/validate';
const validateGetUsers = maybe(
restrictToSchema({
limit: optional(checkType(String)),
offset: optional(checkType(String)),
sort: optional(isValidSortObject())
}),
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({ permissions, permissionName: CAN_GET_USERS});
validateGetUsers(req.query,['users']);
const {limit, offset, sort} = req.query;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_GET_PERMISSIONS } from '../../../../utils/constants';
import { maybe, optional, checkType, restrictToSchema} from 'rulr';
import { isValidSortObject } from '../../../../utils/validate';
const validateGetPermissions = maybe(
restrictToSchema({
limit: optional(checkType(String)),
offset: optional(checkType(String)),
sort: optional(isValidSortObject())
}),
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({ permissions, permissionName: CAN_GET_PERMISSIONS});
validateGetPermissions(req.query,['roles']);
const {limit, offset, sort} = req.query;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { Request, Response } from 'express';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_GET_POSTS } from '../../../../utils/constants';
import { maybe, optional, checkType, restrictToSchema }from 'rulr';
import { isValidSortObject } from '../../../../utils/validate';
const validateGetPosts = maybe(
restrictToSchema({
limit: optional(checkType(String)),
offset: optional(checkType(String)),
sort: optional(isValidSortObject())
}),
);
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({ permissions, permissionName: CAN_GET_POSTS});
validateGetPosts(req.query,['posts']);
const {limit, offset, sort} = req.query;