import OrderappMerchantApi from './index' export default class CategoryApi { api: OrderappMerchantApi constructor (api: OrderappMerchantApi) { this.api = api } async getCategories (): Promise { const endpoint = '/m/category' const response = await this.api.axiosGo.get(endpoint) return response.data } async createCategory (category: IAppCategory): Promise { const data: ICreateCategoryRequestData = { name: category.name, desc: category.desc ?? null, parentId: category.parentId ?? '', locale: this.api.locale ?? 'zh', days: category.weekdays ?? null, start: category.timerange?.[0] ?? null, end: category.timerange?.[1] ?? null, waiterOnly: category.waiterOnly ?? null, takeawayOnly: category.takeawayOnly ?? null, excludedDiscount: category.excludedDiscount ?? false, excludedSurcharge: category.excludedSurcharge ?? false, code: category.code ?? null, isSet: false, type: category.type, } const response = await this.api.axiosGo.post('/m/category', data) return response.data } // 更改指定語言的 name, desc async updateCategoryTranslate ( categoryId: string, data: {name: string, desc: string, locale: string}, ): Promise { if (data.locale == null) { data.locale = this.api.locale ?? 'zh' } const endpoint = `/m/category/${categoryId}/translate` const response = await this.api.axiosGo.post(endpoint, data) return response.data } async updateCategoryParent (categoryId: string, parentId: string): Promise { const endpoint = `/m/category/${categoryId}/parent` const response = await this.api.axiosGo.post(endpoint, { parentId }) return response.data } async updateCategoryDays (categoryId: string, weekdays: WeekDays): Promise { const endpoint = `/m/category/${categoryId}/days` const response = await this.api.axiosGo.post(endpoint, { days: weekdays }) return response.data } async updateCategoryTime (categoryId: string, data: {start: ITimeslot, end: ITimeslot}): Promise { const endpoint = `/m/category/${categoryId}/time` const response = await this.api.axiosGo.post(endpoint, data) return response.data } async updateWaiterOnly (categoryId: string, waiterOnly: boolean): Promise { const endpoint = `/m/category/${categoryId}/waiter` const response = await this.api.axiosGo.post(endpoint, { waiterOnly }) return response.data } async updateTakeawayOnly (categoryId: string, takeawayOnly: boolean): Promise { const endpoint = `/m/category/${categoryId}/takeawayonly` const response = await this.api.axiosGo.post(endpoint, { takeawayOnly }) return response.data } async updateCode (categoryId: string, code: string): Promise { const endpoint = `/m/category/${categoryId}/code` const response = await this.api.axiosGo.post(endpoint, { code }) return response.data } async updateCategoryEnable (categoryId: string, enable: boolean): Promise { const endpoint = `/m/category/${categoryId}/enable` const response = await this.api.axiosGo.post(endpoint, { enable }) return response.data } async deleteCategory (categoryId: string): Promise { const endpoint = `/m/category/${categoryId}` const response = await this.api.axiosGo.delete(endpoint) return response.data } async getCategoryTag (): Promise { const response = await this.api.axiosGo.get('/m/categorytag') return response.data } async createCategoryTag (categoryTag: {name: string, categoryIds: string[], orderCutOffMins: number}): Promise { const response = await this.api.axiosGo.post('/m/categorytag', categoryTag) return response.data } async updateCategoryTag (categoryTag: ICategoryTag): Promise { const response = await this.api.axiosGo.put(`/m/categorytag/${categoryTag.id}`, categoryTag) return response.data } async deleteCategoryTag (id: string): Promise { const response = await this.api.axiosGo.delete(`/m/categorytag/${id}`) return response.data } async reorderCategoryTag (categoryTagIds: string[]): Promise { await this.api.axiosGo.post('/m/merchant/sort/categorytag', { categoryTagIds }) } }