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
|
@ -5,7 +5,7 @@ export interface CrudAPIInterface {
|
|||
|
||||
// Route Properties / Methods
|
||||
baseRoute: string;
|
||||
itemRoute(itemId: string): string;
|
||||
itemRoute(itemId: string | number): string;
|
||||
|
||||
// Methods
|
||||
}
|
||||
|
@ -21,6 +21,10 @@ export const crudMixins = <T>(
|
|||
});
|
||||
}
|
||||
|
||||
async function createOne(payload: T) {
|
||||
return await requests.post<T>(baseRoute, payload);
|
||||
}
|
||||
|
||||
async function getOne(itemId: string) {
|
||||
return await requests.get<T>(itemRoute(itemId));
|
||||
}
|
||||
|
@ -37,14 +41,14 @@ export const crudMixins = <T>(
|
|||
return await requests.delete<T>(itemRoute(itemId));
|
||||
}
|
||||
|
||||
return { getAll, getOne, updateOne, patchOne, deleteOne };
|
||||
return { getAll, getOne, updateOne, patchOne, deleteOne, createOne };
|
||||
};
|
||||
|
||||
export abstract class BaseAPIClass<T> implements CrudAPIInterface {
|
||||
export abstract class BaseAPIClass<T, U> implements CrudAPIInterface {
|
||||
requests: ApiRequestInstance;
|
||||
|
||||
abstract baseRoute: string;
|
||||
abstract itemRoute(itemId: string): string;
|
||||
abstract itemRoute(itemId: string | number): string;
|
||||
|
||||
constructor(requests: ApiRequestInstance) {
|
||||
this.requests = requests;
|
||||
|
@ -56,6 +60,10 @@ export abstract class BaseAPIClass<T> implements CrudAPIInterface {
|
|||
});
|
||||
}
|
||||
|
||||
async createOne(payload: U) {
|
||||
return await this.requests.post<T>(this.baseRoute, payload);
|
||||
}
|
||||
|
||||
async getOne(itemId: string) {
|
||||
return await this.requests.get<T>(this.itemRoute(itemId));
|
||||
}
|
||||
|
@ -68,7 +76,7 @@ export abstract class BaseAPIClass<T> implements CrudAPIInterface {
|
|||
return await this.requests.patch(this.itemRoute(itemId), payload);
|
||||
}
|
||||
|
||||
async deleteOne(itemId: string) {
|
||||
async deleteOne(itemId: string | number) {
|
||||
return await this.requests.delete<T>(this.itemRoute(itemId));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue