mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +02:00
feat: Add Households to Mealie (#3970)
This commit is contained in:
parent
0c29cef17d
commit
eb170cc7e5
315 changed files with 6975 additions and 3577 deletions
|
@ -1,5 +1,5 @@
|
|||
import { BaseAPI } from "../base/base-clients";
|
||||
import { EmailInitationResponse, EmailInvitation } from "~/lib/api/types/group";
|
||||
import { EmailInitationResponse, EmailInvitation } from "~/lib/api/types/household";
|
||||
import { ForgotPassword } from "~/lib/api/types/user";
|
||||
import { EmailTest } from "~/lib/api/types/admin";
|
||||
|
||||
|
@ -7,7 +7,7 @@ const routes = {
|
|||
base: "/api/admin/email",
|
||||
forgotPassword: "/api/users/forgot-password",
|
||||
|
||||
invitation: "/api/groups/invitations/email",
|
||||
invitation: "/api/households/invitations/email",
|
||||
};
|
||||
|
||||
export class EmailAPI extends BaseAPI {
|
||||
|
|
|
@ -4,8 +4,8 @@ import { CreateCookBook, RecipeCookBook, UpdateCookBook } from "~/lib/api/types/
|
|||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
cookbooks: `${prefix}/groups/cookbooks`,
|
||||
cookbooksId: (id: number) => `${prefix}/groups/cookbooks/${id}`,
|
||||
cookbooks: `${prefix}/households/cookbooks`,
|
||||
cookbooksId: (id: number) => `${prefix}/households/cookbooks/${id}`,
|
||||
};
|
||||
|
||||
export class CookbookAPI extends BaseCRUDAPI<CreateCookBook, RecipeCookBook, UpdateCookBook> {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { GroupEventNotifierCreate, GroupEventNotifierOut, GroupEventNotifierUpdate } from "~/lib/api/types/group";
|
||||
import { GroupEventNotifierCreate, GroupEventNotifierOut, GroupEventNotifierUpdate } from "~/lib/api/types/household";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
eventNotifier: `${prefix}/groups/events/notifications`,
|
||||
eventNotifierId: (id: string | number) => `${prefix}/groups/events/notifications/${id}`,
|
||||
eventNotifier: `${prefix}/households/events/notifications`,
|
||||
eventNotifierId: (id: string | number) => `${prefix}/households/events/notifications/${id}`,
|
||||
};
|
||||
|
||||
export class GroupEventNotifierApi extends BaseCRUDAPI<
|
||||
|
|
|
@ -4,8 +4,8 @@ import { PlanRulesCreate, PlanRulesOut } from "~/lib/api/types/meal-plan";
|
|||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
rule: `${prefix}/groups/mealplans/rules`,
|
||||
ruleId: (id: string | number) => `${prefix}/groups/mealplans/rules/${id}`,
|
||||
rule: `${prefix}/households/mealplans/rules`,
|
||||
ruleId: (id: string | number) => `${prefix}/households/mealplans/rules/${id}`,
|
||||
};
|
||||
|
||||
export class MealPlanRulesApi extends BaseCRUDAPI<PlanRulesCreate, PlanRulesOut> {
|
||||
|
|
|
@ -4,9 +4,9 @@ import { CreatePlanEntry, CreateRandomEntry, ReadPlanEntry, UpdatePlanEntry } fr
|
|||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
mealplan: `${prefix}/groups/mealplans`,
|
||||
random: `${prefix}/groups/mealplans/random`,
|
||||
mealplanId: (id: string | number) => `${prefix}/groups/mealplans/${id}`,
|
||||
mealplan: `${prefix}/households/mealplans`,
|
||||
random: `${prefix}/households/mealplans/random`,
|
||||
mealplanId: (id: string | number) => `${prefix}/households/mealplans/${id}`,
|
||||
};
|
||||
|
||||
export class MealPlanAPI extends BaseCRUDAPI<CreatePlanEntry, ReadPlanEntry, UpdatePlanEntry> {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { CreateGroupRecipeAction, GroupRecipeActionOut } from "~/lib/api/types/group";
|
||||
import { CreateGroupRecipeAction, GroupRecipeActionOut } from "~/lib/api/types/household";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
groupRecipeActions: `${prefix}/groups/recipe-actions`,
|
||||
groupRecipeActionsId: (id: string | number) => `${prefix}/groups/recipe-actions/${id}`,
|
||||
groupRecipeActions: `${prefix}/households/recipe-actions`,
|
||||
groupRecipeActionsId: (id: string | number) => `${prefix}/households/recipe-actions/${id}`,
|
||||
};
|
||||
|
||||
export class GroupRecipeActionsAPI extends BaseCRUDAPI<CreateGroupRecipeAction, GroupRecipeActionOut> {
|
||||
|
|
|
@ -9,20 +9,20 @@ import {
|
|||
ShoppingListMultiPurposeLabelUpdate,
|
||||
ShoppingListOut,
|
||||
ShoppingListUpdate,
|
||||
} from "~/lib/api/types/group";
|
||||
} from "~/lib/api/types/household";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
shoppingLists: `${prefix}/groups/shopping/lists`,
|
||||
shoppingListsId: (id: string) => `${prefix}/groups/shopping/lists/${id}`,
|
||||
shoppingListIdAddRecipe: (id: string, recipeId: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}`,
|
||||
shoppingListIdRemoveRecipe: (id: string, recipeId: string) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}/delete`,
|
||||
shoppingListIdUpdateLabelSettings: (id: string) => `${prefix}/groups/shopping/lists/${id}/label-settings`,
|
||||
shoppingLists: `${prefix}/households/shopping/lists`,
|
||||
shoppingListsId: (id: string) => `${prefix}/households/shopping/lists/${id}`,
|
||||
shoppingListIdAddRecipe: (id: string, recipeId: string) => `${prefix}/households/shopping/lists/${id}/recipe/${recipeId}`,
|
||||
shoppingListIdRemoveRecipe: (id: string, recipeId: string) => `${prefix}/households/shopping/lists/${id}/recipe/${recipeId}/delete`,
|
||||
shoppingListIdUpdateLabelSettings: (id: string) => `${prefix}/households/shopping/lists/${id}/label-settings`,
|
||||
|
||||
shoppingListItems: `${prefix}/groups/shopping/items`,
|
||||
shoppingListItemsCreateBulk: `${prefix}/groups/shopping/items/create-bulk`,
|
||||
shoppingListItemsId: (id: string) => `${prefix}/groups/shopping/items/${id}`,
|
||||
shoppingListItems: `${prefix}/households/shopping/items`,
|
||||
shoppingListItemsCreateBulk: `${prefix}/households/shopping/items/create-bulk`,
|
||||
shoppingListItemsId: (id: string) => `${prefix}/households/shopping/items/${id}`,
|
||||
};
|
||||
|
||||
export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListCreate, ShoppingListOut, ShoppingListUpdate> {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { CreateWebhook, ReadWebhook } from "~/lib/api/types/group";
|
||||
import { CreateWebhook, ReadWebhook } from "~/lib/api/types/household";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
webhooks: `${prefix}/groups/webhooks`,
|
||||
webhooksId: (id: string | number) => `${prefix}/groups/webhooks/${id}`,
|
||||
webhooksIdTest: (id: string | number) => `${prefix}/groups/webhooks/${id}/test`,
|
||||
webhooks: `${prefix}/households/webhooks`,
|
||||
webhooksId: (id: string | number) => `${prefix}/households/webhooks/${id}`,
|
||||
webhooksIdTest: (id: string | number) => `${prefix}/households/webhooks/${id}/test`,
|
||||
};
|
||||
|
||||
export class WebhooksAPI extends BaseCRUDAPI<CreateWebhook, ReadWebhook> {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { CategoryBase, GroupBase, GroupInDB, GroupSummary, UserOut } from "~/lib/api/types/user";
|
||||
import { GroupBase, GroupInDB, GroupSummary, UserSummary } from "~/lib/api/types/user";
|
||||
import { HouseholdSummary } from "~/lib/api/types/household";
|
||||
import {
|
||||
CreateInviteToken,
|
||||
GroupAdminUpdate,
|
||||
GroupStatistics,
|
||||
GroupStorage,
|
||||
ReadGroupPreferences,
|
||||
ReadInviteToken,
|
||||
SetPermissions,
|
||||
UpdateGroupPreferences,
|
||||
} from "~/lib/api/types/group";
|
||||
|
||||
|
@ -16,16 +13,14 @@ const prefix = "/api";
|
|||
const routes = {
|
||||
groups: `${prefix}/admin/groups`,
|
||||
groupsSelf: `${prefix}/groups/self`,
|
||||
categories: `${prefix}/groups/categories`,
|
||||
members: `${prefix}/groups/members`,
|
||||
permissions: `${prefix}/groups/permissions`,
|
||||
|
||||
preferences: `${prefix}/groups/preferences`,
|
||||
statistics: `${prefix}/groups/statistics`,
|
||||
storage: `${prefix}/groups/storage`,
|
||||
|
||||
invitation: `${prefix}/groups/invitations`,
|
||||
|
||||
households: `${prefix}/households`,
|
||||
membersHouseholdId: (householdId: string | number | null) => {
|
||||
return householdId ?
|
||||
`${prefix}/households/members?householdId=${householdId}` :
|
||||
`${prefix}/groups/members`;
|
||||
},
|
||||
groupsId: (id: string | number) => `${prefix}/admin/groups/${id}`,
|
||||
};
|
||||
|
||||
|
@ -38,14 +33,6 @@ export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate
|
|||
return await this.requests.get<GroupSummary>(routes.groupsSelf);
|
||||
}
|
||||
|
||||
async getCategories() {
|
||||
return await this.requests.get<CategoryBase[]>(routes.categories);
|
||||
}
|
||||
|
||||
async setCategories(payload: CategoryBase[]) {
|
||||
return await this.requests.put<CategoryBase[]>(routes.categories, payload);
|
||||
}
|
||||
|
||||
async getPreferences() {
|
||||
return await this.requests.get<ReadGroupPreferences>(routes.preferences);
|
||||
}
|
||||
|
@ -55,21 +42,12 @@ export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate
|
|||
return await this.requests.put<ReadGroupPreferences, UpdateGroupPreferences>(routes.preferences, payload);
|
||||
}
|
||||
|
||||
async createInvitation(payload: CreateInviteToken) {
|
||||
return await this.requests.post<ReadInviteToken>(routes.invitation, payload);
|
||||
async fetchMembers(householdId: string | number | null = null) {
|
||||
return await this.requests.get<UserSummary[]>(routes.membersHouseholdId(householdId));
|
||||
}
|
||||
|
||||
async fetchMembers() {
|
||||
return await this.requests.get<UserOut[]>(routes.members);
|
||||
}
|
||||
|
||||
async setMemberPermissions(payload: SetPermissions) {
|
||||
// TODO: This should probably be a patch request, which isn't offered by the API currently
|
||||
return await this.requests.put<UserOut, SetPermissions>(routes.permissions, payload);
|
||||
}
|
||||
|
||||
async statistics() {
|
||||
return await this.requests.get<GroupStatistics>(routes.statistics);
|
||||
async fetchHouseholds() {
|
||||
return await this.requests.get<HouseholdSummary[]>(routes.households);
|
||||
}
|
||||
|
||||
async storage() {
|
||||
|
|
64
frontend/lib/api/user/households.ts
Normal file
64
frontend/lib/api/user/households.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { UserOut } from "~/lib/api/types/user";
|
||||
import {
|
||||
HouseholdCreate,
|
||||
HouseholdInDB,
|
||||
UpdateHouseholdAdmin,
|
||||
HouseholdStatistics,
|
||||
ReadHouseholdPreferences,
|
||||
SetPermissions,
|
||||
UpdateHouseholdPreferences,
|
||||
CreateInviteToken,
|
||||
ReadInviteToken,
|
||||
} from "~/lib/api/types/household";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
households: `${prefix}/admin/households`,
|
||||
householdsSelf: `${prefix}/households/self`,
|
||||
members: `${prefix}/households/members`,
|
||||
permissions: `${prefix}/households/permissions`,
|
||||
|
||||
preferences: `${prefix}/households/preferences`,
|
||||
statistics: `${prefix}/households/statistics`,
|
||||
invitation: `${prefix}/households/invitations`,
|
||||
|
||||
householdsId: (id: string | number) => `${prefix}/admin/households/${id}`,
|
||||
};
|
||||
|
||||
export class HouseholdAPI extends BaseCRUDAPI<HouseholdCreate, HouseholdInDB, UpdateHouseholdAdmin> {
|
||||
baseRoute = routes.households;
|
||||
itemRoute = routes.householdsId;
|
||||
/** Returns the Group Data for the Current User
|
||||
*/
|
||||
async getCurrentUserHousehold() {
|
||||
return await this.requests.get<HouseholdInDB>(routes.householdsSelf);
|
||||
}
|
||||
|
||||
async getPreferences() {
|
||||
return await this.requests.get<ReadHouseholdPreferences>(routes.preferences);
|
||||
}
|
||||
|
||||
async setPreferences(payload: UpdateHouseholdPreferences) {
|
||||
// TODO: This should probably be a patch request, which isn't offered by the API currently
|
||||
return await this.requests.put<ReadHouseholdPreferences, UpdateHouseholdPreferences>(routes.preferences, payload);
|
||||
}
|
||||
|
||||
async createInvitation(payload: CreateInviteToken) {
|
||||
return await this.requests.post<ReadInviteToken>(routes.invitation, payload);
|
||||
}
|
||||
|
||||
async fetchMembers() {
|
||||
return await this.requests.get<UserOut[]>(routes.members);
|
||||
}
|
||||
|
||||
async setMemberPermissions(payload: SetPermissions) {
|
||||
// TODO: This should probably be a patch request, which isn't offered by the API currently
|
||||
return await this.requests.put<UserOut, SetPermissions>(routes.permissions, payload);
|
||||
}
|
||||
|
||||
async statistics() {
|
||||
return await this.requests.get<HouseholdStatistics>(routes.statistics);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { QueryValue, route } from "~/lib/api/base/route";
|
||||
import { PaginationData } from "~/lib/api/types/non-generated";
|
||||
import {
|
||||
ChangePassword,
|
||||
DeleteTokenResponse,
|
||||
|
@ -12,7 +10,6 @@ import {
|
|||
UserOut,
|
||||
UserRatingOut,
|
||||
UserRatingSummary,
|
||||
UserSummary,
|
||||
} from "~/lib/api/types/user";
|
||||
|
||||
export interface UserRatingsSummaries {
|
||||
|
@ -26,7 +23,6 @@ export interface UserRatingsOut {
|
|||
const prefix = "/api";
|
||||
|
||||
const routes = {
|
||||
groupUsers: `${prefix}/users/group-users`,
|
||||
usersSelf: `${prefix}/users/self`,
|
||||
ratingsSelf: `${prefix}/users/self/ratings`,
|
||||
passwordReset: `${prefix}/users/reset-password`,
|
||||
|
@ -51,10 +47,6 @@ export class UserApi extends BaseCRUDAPI<UserIn, UserOut, UserBase> {
|
|||
baseRoute: string = routes.users;
|
||||
itemRoute = (itemid: string) => routes.usersId(itemid);
|
||||
|
||||
async getGroupUsers(page = 1, perPage = -1, params = {} as Record<string, QueryValue>) {
|
||||
return await this.requests.get<PaginationData<UserSummary>>(route(routes.groupUsers, { page, perPage, ...params }));
|
||||
}
|
||||
|
||||
async addFavorite(id: string, slug: string) {
|
||||
return await this.requests.post(routes.usersIdFavoritesSlug(id, slug), {});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue