1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 20:15:24 +02:00

fix: user & household creation (#5699)

This commit is contained in:
Kuchenpirat 2025-07-13 15:57:28 +02:00 committed by GitHub
parent 40d2ac9a6b
commit 9cfc54b1f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 131 additions and 206 deletions

View file

@ -48,28 +48,11 @@ export const useHouseholdSelf = function () {
export const useAdminHouseholds = function () {
const api = useAdminApi();
const loading = ref(false);
const households = ref<HouseholdInDB[] | null>(null);
function getAllHouseholds() {
async function getAllHouseholds() {
loading.value = true;
const asyncKey = String(Date.now());
const { data: households } = useAsyncData(asyncKey, async () => {
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" });
if (data) {
return data.items;
}
else {
return null;
}
});
loading.value = false;
return households;
}
async function refreshAllHouseholds() {
loading.value = true;
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" }); ;
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" });
if (data) {
households.value = data.items;
@ -81,11 +64,15 @@ export const useAdminHouseholds = function () {
loading.value = false;
}
async function refreshAllHouseholds() {
await getAllHouseholds();
}
async function deleteHousehold(id: string | number) {
loading.value = true;
const { data } = await api.households.deleteOne(id);
loading.value = false;
refreshAllHouseholds();
await refreshAllHouseholds();
return data;
}
@ -96,9 +83,9 @@ export const useAdminHouseholds = function () {
if (data && households.value) {
households.value.push(data);
}
loading.value = false;
}
const households = getAllHouseholds();
function useHouseholdsInGroup(groupIdRef: Ref<string>) {
return computed(
() => {
@ -109,6 +96,10 @@ export const useAdminHouseholds = function () {
);
}
if (!households.value) {
getAllHouseholds();
}
return {
households,
useHouseholdsInGroup,