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

Consolidate frontend types (#1245)

This commit is contained in:
Philipp Fischbeck 2022-05-21 21:22:02 +02:00 committed by GitHub
parent 6a88a59981
commit 479900e912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
74 changed files with 261 additions and 582 deletions

View file

@ -18,33 +18,33 @@ export abstract class BaseAPI {
}
}
export abstract class BaseCRUDAPI<T, U> extends BaseAPI implements CrudAPIInterface {
export abstract class BaseCRUDAPI<CreateType, ReadType, UpdateType=CreateType> extends BaseAPI implements CrudAPIInterface {
abstract baseRoute: string;
abstract itemRoute(itemId: string | number): string;
async getAll(start = 0, limit = 9999, params = {} as any) {
return await this.requests.get<T[]>(this.baseRoute, {
return await this.requests.get<ReadType[]>(this.baseRoute, {
params: { start, limit, ...params },
});
}
async createOne(payload: U) {
return await this.requests.post<T>(this.baseRoute, payload);
async createOne(payload: CreateType) {
return await this.requests.post<ReadType>(this.baseRoute, payload);
}
async getOne(itemId: string | number) {
return await this.requests.get<T>(this.itemRoute(itemId));
return await this.requests.get<ReadType>(this.itemRoute(itemId));
}
async updateOne(itemId: string | number, payload: T) {
return await this.requests.put<T>(this.itemRoute(itemId), payload);
async updateOne(itemId: string | number, payload: UpdateType) {
return await this.requests.put<ReadType, UpdateType>(this.itemRoute(itemId), payload);
}
async patchOne(itemId: string, payload: Partial<T>) {
return await this.requests.patch<T>(this.itemRoute(itemId), payload);
async patchOne(itemId: string, payload: Partial<UpdateType>) {
return await this.requests.patch<ReadType, Partial<UpdateType>>(this.itemRoute(itemId), payload);
}
async deleteOne(itemId: string | number) {
return await this.requests.delete<T>(this.itemRoute(itemId));
return await this.requests.delete<ReadType>(this.itemRoute(itemId));
}
}