pos-be/src/core/helpers/path/get-action-from-path.helper.ts

29 lines
906 B
TypeScript

import { PrivilegeAction } from 'src/core/strings/constants/privilege.constants';
function containsUuid(str) {
const parts = str.split('/'); // Split the string by "/"
for (const part of parts) {
if (
/^[0-9a-f]{8}\b-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
part,
)
) {
return true;
}
}
return false;
}
export function getAction(method: string, path: string): string {
if (method === 'GET') return PrivilegeAction.VIEW;
else if (method === 'POST') return PrivilegeAction.CREATE;
else if (method === 'DELETE') return PrivilegeAction.DELETE;
else if (method === 'PATCH' || method === 'PUT') {
if (['confirm', 'active', 'inactive'].includes(path))
return PrivilegeAction.CONFIRM;
else if (path.includes('cancel')) return PrivilegeAction.CANCEL;
else return PrivilegeAction.EDIT;
}
return 'forbidden';
}