mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
Fix more typing issues (#928)
* Fix or comment several ts-ignores * Fix typing related to BaseOverflowButton * Remove unused functionality of useCookbooks, fix usage bug * Fix more typing, add some comments * Only allow ts-ignore if it has a comment
This commit is contained in:
parent
c4540f1395
commit
f794208862
45 changed files with 126 additions and 249 deletions
|
@ -1,5 +1,5 @@
|
|||
import { BaseCRUDAPI } from "../_base";
|
||||
import { UserRead } from "./admin-users";
|
||||
import { UserOut } from "~/types/api-types/user";
|
||||
const prefix = "/api";
|
||||
|
||||
export interface Token {
|
||||
|
@ -29,7 +29,7 @@ export interface GroupRead extends GroupCreate {
|
|||
id: number;
|
||||
categories: any[];
|
||||
webhooks: any[];
|
||||
users: UserRead[];
|
||||
users: UserOut[];
|
||||
preferences: Preferences;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,39 +1,14 @@
|
|||
import { BaseCRUDAPI } from "../_base";
|
||||
import { UserIn, UserOut } from "~/types/api-types/user";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
export interface UserCreate {
|
||||
username: string;
|
||||
fullName: string;
|
||||
email: string;
|
||||
admin: boolean;
|
||||
group: string;
|
||||
advanced: boolean;
|
||||
canInvite: boolean;
|
||||
canManage: boolean;
|
||||
canOrganize: boolean;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UserToken {
|
||||
name: string;
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface UserRead extends UserToken {
|
||||
id: number;
|
||||
groupId: number;
|
||||
favoriteRecipes: any[];
|
||||
tokens: UserToken[];
|
||||
}
|
||||
|
||||
const routes = {
|
||||
adminUsers: `${prefix}/admin/users`,
|
||||
adminUsersId: (tag: string) => `${prefix}/admin/users/${tag}`,
|
||||
};
|
||||
|
||||
export class AdminUsersApi extends BaseCRUDAPI<UserRead, UserCreate> {
|
||||
export class AdminUsersApi extends BaseCRUDAPI<UserOut, UserIn> {
|
||||
baseRoute: string = routes.adminUsers;
|
||||
itemRoute = routes.adminUsersId;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ export class RecipeAPI extends BaseCRUDAPI<Recipe, CreateRecipe> {
|
|||
|
||||
async createAsset(recipeSlug: string, payload: CreateAsset) {
|
||||
const formData = new FormData();
|
||||
// @ts-ignore
|
||||
formData.append("file", payload.file);
|
||||
formData.append("name", payload.name);
|
||||
formData.append("extension", payload.extension);
|
||||
|
@ -65,8 +64,7 @@ export class RecipeAPI extends BaseCRUDAPI<Recipe, CreateRecipe> {
|
|||
updateImage(slug: string, fileObject: File) {
|
||||
const formData = new FormData();
|
||||
formData.append("image", fileObject);
|
||||
// @ts-ignore
|
||||
formData.append("extension", fileObject.name.split(".").pop());
|
||||
formData.append("extension", fileObject.name.split(".").pop() ?? "");
|
||||
|
||||
return this.requests.put<any>(routes.recipesRecipeSlugImage(slug), formData);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ export interface CreateAsset {
|
|||
name: string;
|
||||
icon: string;
|
||||
extension: string;
|
||||
file?: File;
|
||||
file: File;
|
||||
}
|
||||
|
||||
export interface RecipeCommentCreate {
|
||||
|
|
|
@ -1,33 +1,19 @@
|
|||
import { BaseCRUDAPI } from "../_base";
|
||||
import { Recipe } from "~/types/api-types/recipe";
|
||||
import { RecipeTool, RecipeToolCreate, RecipeToolResponse } from "~/types/api-types/recipe";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
export interface CreateTool {
|
||||
name: string;
|
||||
onHand: boolean;
|
||||
}
|
||||
|
||||
export interface Tool extends CreateTool {
|
||||
id: number;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export interface RecipeToolResponse extends Tool {
|
||||
recipes: Recipe[];
|
||||
}
|
||||
|
||||
const routes = {
|
||||
tools: `${prefix}/tools`,
|
||||
toolsId: (id: string) => `${prefix}/tools/${id}`,
|
||||
toolsSlug: (id: string) => `${prefix}/tools/slug/${id}`,
|
||||
};
|
||||
|
||||
export class ToolsApi extends BaseCRUDAPI<Tool, CreateTool> {
|
||||
export class ToolsApi extends BaseCRUDAPI<RecipeTool, RecipeToolCreate> {
|
||||
baseRoute: string = routes.tools;
|
||||
itemRoute = routes.toolsId;
|
||||
|
||||
async byslug(slug: string) {
|
||||
return await this.requests.get<Tool>(routes.toolsSlug(slug));
|
||||
return await this.requests.get<RecipeToolResponse>(routes.toolsSlug(slug));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,18 @@ import { BaseAPI } from "../_base";
|
|||
|
||||
const prefix = "/api";
|
||||
|
||||
interface DownloadData {
|
||||
fileToken: string,
|
||||
}
|
||||
|
||||
export class UtilsAPI extends BaseAPI {
|
||||
async download(url: string) {
|
||||
const { response } = await this.requests.get(url);
|
||||
const { response } = await this.requests.get<DownloadData>(url);
|
||||
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const token: string = response.data.fileToken;
|
||||
|
||||
const tokenURL = prefix + "/utils/download?token=" + token;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue