simplify fetching

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-17 16:16:51 +02:00
parent b0265efb29
commit 52c7980e08
2 changed files with 8 additions and 6 deletions

View File

@ -29,9 +29,10 @@
} }
// Merge the Apps list and the roles response to get something that makes sense for the table // Merge the Apps list and the roles response to get something that makes sense for the table
$: appList = Object.keys($apps?.data).map(app => ({ $: appList = Object.keys($apps?.data).map(id => ({
name: $apps?.data?.[app]?.name, ...$apps?.data?.[id],
role: $roleFetch?.data?.roles?.[app], _id: id,
role: $roleFetch?.data?.roles?.[id],
})) }))
let selectedApp let selectedApp
@ -49,6 +50,7 @@
} }
async function openUpdateRolesModal({ detail }) { async function openUpdateRolesModal({ detail }) {
console.log(detail)
selectedApp = detail selectedApp = detail
editRolesModal.show() editRolesModal.show()
} }

View File

@ -9,8 +9,8 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const roles = fetchData(`/api/admin/roles/${app._id}`) const roles = app.roles
$: options = $roles?.data?.roles?.map(role => role._id) let options = roles.map(role => role._id)
let selectedRole let selectedRole
async function updateUserRoles() { async function updateUserRoles() {
@ -22,7 +22,7 @@
}, },
}) })
if (res.status === 400) { if (res.status === 400) {
notifications.error("Failed to update role.") notifications.error("Failed to update role")
} else { } else {
notifications.success("Roles updated") notifications.success("Roles updated")
dispatch("update") dispatch("update")