make code simpler

This commit is contained in:
Nitwel
2020-10-24 12:49:22 +02:00
parent b9d44d052f
commit f88b3f288b

View File

@@ -90,33 +90,31 @@ export default function useUpdatePermissions(
const actions = ['create', 'read', 'update', 'delete'];
await Promise.all(
actions.map((action) =>
(async () => {
const permission = getPermission(action);
if (permission) {
try {
await api.patch(`/permissions/${permission.id}`, {
fields: '*',
permissions: null,
validation: null,
});
} catch (err) {
console.error(err);
}
} else {
try {
await api.post('/permissions/', {
role: role.value,
collection: collection.value.collection,
action: action,
fields: '*',
});
} catch (err) {
console.error(err);
}
actions.map(async (action) => {
const permission = getPermission(action);
if (permission) {
try {
await api.patch(`/permissions/${permission.id}`, {
fields: '*',
permissions: null,
validation: null,
});
} catch (err) {
console.error(err);
}
})()
)
} else {
try {
await api.post('/permissions/', {
role: role.value,
collection: collection.value.collection,
action: action,
fields: '*',
});
} catch (err) {
console.error(err);
}
}
})
);
await refresh?.();