UNPKG

@tasolutions/express-core

Version:
32 lines (26 loc) 1.03 kB
const _ = require('lodash'); const { getAuthItems } = require("../../../clients/userService/api.client"); const { routeInfo } = require("../../../config"); module.exports = { filterActions: async (userId, actionLists) => { const authItems = await getAuthItems(userId); const routeAuthItems = _.filter(authItems, { route_name: routeInfo.name }); return actionLists.filter(action => { return routeAuthItems.some(i => { return ( i.path === action.path && i.http_method.toLowerCase() === action.method.toLowerCase() ); }); });; }, filterModels: async (userId, models) => { const authItems = await getAuthItems(userId); const routeAuthItems = _.filter(authItems, { route_name: routeInfo.name }); return models.filter(model => { return routeAuthItems.some(authItem => { return authItem.path === model.path; }); }); }, }