All files / src/lib/api/admin taxonomy.ts

100% Statements 8/8
100% Branches 3/3
100% Functions 6/6
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48      95x   6x 6x       2x       2x                     2x             2x                 3x            
import { request } from "../base";
import type { TaxonomyItem } from "../taxonomy";
 
export const adminTaxonomyApi = {
	async listTaxonomy(type: string, includeInactive = false) {
		const query = includeInactive ? "?includeInactive=true" : "";
		return request<TaxonomyItem[]>(`/api/admin/taxonomy/${type}${query}`);
	},
 
	async getTaxonomyItem(type: string, id: string) {
		return request<TaxonomyItem>(`/api/admin/taxonomy/${type}/${id}`);
	},
 
	async createTaxonomyItem(type: string, data: Partial<TaxonomyItem>) {
		return request<TaxonomyItem>(`/api/admin/taxonomy/${type}`, {
			method: "POST",
			body: data,
		});
	},
 
	async updateTaxonomyItem(
		type: string,
		id: string,
		data: Partial<TaxonomyItem>,
	) {
		return request<TaxonomyItem>(`/api/admin/taxonomy/${type}/${id}`, {
			method: "PUT",
			body: data,
		});
	},
 
	async deleteTaxonomyItem(type: string, id: string) {
		return request(`/api/admin/taxonomy/${type}/${id}`, {
			method: "DELETE",
		});
	},
 
	async reorderTaxonomy(
		type: string,
		items: Array<{ id: string; sortOrder: number }>,
	) {
		return request(`/api/admin/taxonomy/${type}/reorder`, {
			method: "PATCH",
			body: { items },
		});
	},
};