mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +02:00
refactor(frontend): 🚧 Add group/user CRUD support for admins
This commit is contained in:
parent
917177da5b
commit
695d7e96ae
46 changed files with 2015 additions and 102 deletions
51
frontend/composables/use-groups.ts
Normal file
51
frontend/composables/use-groups.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { useAsync, ref } from "@nuxtjs/composition-api";
|
||||
import { useApiSingleton } from "~/composables/use-api";
|
||||
import { CreateGroup } from "~/api/class-interfaces/groups";
|
||||
|
||||
|
||||
|
||||
export const useGroups = function () {
|
||||
const api = useApiSingleton();
|
||||
const loading = ref(false);
|
||||
|
||||
function getAllGroups() {
|
||||
loading.value = true;
|
||||
const asyncKey = String(Date.now());
|
||||
const groups = useAsync(async () => {
|
||||
const { data } = await api.groups.getAll();
|
||||
return data;
|
||||
}, asyncKey);
|
||||
|
||||
loading.value = false;
|
||||
return groups;
|
||||
}
|
||||
|
||||
async function refreshAllGroups() {
|
||||
loading.value = true;
|
||||
const { data } = await api.groups.getAll();
|
||||
groups.value = data;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
async function deleteGroup(id: string | number) {
|
||||
loading.value = true;
|
||||
const { data } = await api.groups.deleteOne(id);
|
||||
loading.value = false;
|
||||
refreshAllGroups();
|
||||
return data;
|
||||
}
|
||||
|
||||
async function createGroup(payload: CreateGroup) {
|
||||
console.log(payload);
|
||||
loading.value = true;
|
||||
const { data } = await api.groups.createOne(payload);
|
||||
|
||||
if (data && groups.value) {
|
||||
groups.value.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
const groups = getAllGroups();
|
||||
|
||||
return { groups, getAllGroups, refreshAllGroups, deleteGroup, createGroup };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue