2021-10-23 16:42:20 -08:00
|
|
|
import { BaseAPI } from "../_base";
|
2022-08-14 10:37:44 -08:00
|
|
|
import { AssignCategories, AssignSettings, AssignTags, DeleteRecipes, ExportRecipes } from "~/types/api-types/recipe";
|
2022-05-21 21:22:02 +02:00
|
|
|
import { GroupDataExport } from "~/types/api-types/group";
|
2021-10-18 19:41:41 -08:00
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
// Many bulk actions return nothing
|
2022-01-09 07:15:23 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
2022-08-14 10:37:44 -08:00
|
|
|
interface BulkActionResponse {}
|
2021-12-04 14:18:46 -09:00
|
|
|
|
2021-10-18 19:41:41 -08:00
|
|
|
const prefix = "/api";
|
|
|
|
|
|
|
|
const routes = {
|
|
|
|
bulkExport: prefix + "/recipes/bulk-actions/export",
|
2021-12-04 14:18:46 -09:00
|
|
|
purgeExports: prefix + "/recipes/bulk-actions/export/purge",
|
2021-10-18 19:41:41 -08:00
|
|
|
bulkCategorize: prefix + "/recipes/bulk-actions/categorize",
|
|
|
|
bulkTag: prefix + "/recipes/bulk-actions/tag",
|
|
|
|
bulkDelete: prefix + "/recipes/bulk-actions/delete",
|
2022-08-14 10:37:44 -08:00
|
|
|
bulkSettings: prefix + "/recipes/bulk-actions/settings",
|
2021-10-18 19:41:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export class BulkActionsAPI extends BaseAPI {
|
2022-05-21 21:22:02 +02:00
|
|
|
async bulkExport(payload: ExportRecipes) {
|
2021-10-18 19:41:41 -08:00
|
|
|
return await this.requests.post<BulkActionResponse>(routes.bulkExport, payload);
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
async bulkCategorize(payload: AssignCategories) {
|
2021-10-18 19:41:41 -08:00
|
|
|
return await this.requests.post<BulkActionResponse>(routes.bulkCategorize, payload);
|
|
|
|
}
|
|
|
|
|
2022-08-14 10:37:44 -08:00
|
|
|
async bulkSetSettings(payload: AssignSettings) {
|
|
|
|
return await this.requests.post<BulkActionResponse>(routes.bulkSettings, payload);
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
async bulkTag(payload: AssignTags) {
|
2021-10-18 19:41:41 -08:00
|
|
|
return await this.requests.post<BulkActionResponse>(routes.bulkTag, payload);
|
|
|
|
}
|
|
|
|
|
2022-05-21 21:22:02 +02:00
|
|
|
async bulkDelete(payload: DeleteRecipes) {
|
2021-10-18 19:41:41 -08:00
|
|
|
return await this.requests.post<BulkActionResponse>(routes.bulkDelete, payload);
|
|
|
|
}
|
2021-12-04 14:18:46 -09:00
|
|
|
|
|
|
|
async fetchExports() {
|
|
|
|
return await this.requests.get<GroupDataExport[]>(routes.bulkExport);
|
|
|
|
}
|
|
|
|
|
|
|
|
async purgeExports() {
|
2022-05-21 21:22:02 +02:00
|
|
|
return await this.requests.delete<BulkActionResponse>(routes.purgeExports);
|
2021-12-04 14:18:46 -09:00
|
|
|
}
|
2021-10-18 19:41:41 -08:00
|
|
|
}
|