import OrderappMerchantApi from './index' export default class MenuApi { api: OrderappMerchantApi constructor (api: OrderappMerchantApi) { this.api = api } async getCategoryMenus (merchantId: string, categoryId: string): Promise>> { const endpoint = '/m/menu' const response = await this.api.axiosGo.get(endpoint, { params: { merchantID: merchantId, categoryID: categoryId, takeaway: false, }, }) return response.data.filter((menu: IMenu) => !menu.deleted) } async getCategorySets (merchantId: string, categoryId: string, query: IGetCategorySetsQuery): Promise>> { const endpoint = '/m/set' const response = await this.api.axiosGo.get(endpoint, { params: { merchantID: merchantId, categoryID: categoryId, ...query, }, }) return response.data.filter((set: ISet) => !set.deleted) } async getSetMenus (merchantId: string, setId: string): Promise>> { const endpoint = '/m/setmenu' const response = await this.api.axiosGo.get(endpoint, { params: { merchantID: merchantId, setID: setId, takeaway: false, }, }) return response.data.filter((setMenu: ISetMenu) => !setMenu.deleted) } async getPromotedSetMenus (): Promise { const response = await this.api.axiosGo.get('/m/setmenu', { params: { promoted: true }, }) return response.data } // * set async getSet (id: string, locale?: string): Promise { const response = await this.api.axiosGo.get(`/m/set/info/${id}`, { headers: { 'Accept-Language': locale != null ? locale : this.api.locale, }, }) return response.data } async getSoldOutSets (): Promise { const response = await this.api.axiosGo.get('/m/set', { params: { soldOut: true }, }) return response.data } async getPromotedSets (): Promise { const response = await this.api.axiosGo.get('/m/set', { params: { promoted: true }, }) return response.data } async createSet (set: ICreateSetRequestData): Promise { const endpoint = '/m/set' const response = await this.api.axiosGo.post(endpoint, set) return response.data } async updateSet (setId: string, set: IUpdateSetRequestData): Promise { const endpoint = `/m/set/${setId}/info` const response = await this.api.axiosGo.post(endpoint, set) return response.data } async deleteSet (setId: string): Promise { const endpoint = `/m/set/${setId}` await this.api.axiosGo.delete(endpoint) } // 修改外帶價格 async updateSetTakeawayPrice (setId: string, data: IUpdateTakeawayPriceRequestData): Promise { const endpoint = `/m/set/${setId}/price` const response = await this.api.axiosGo.post(endpoint, data) return response.data } async addSetStep (setId: string, step: ISetStep): Promise { const endpoint = `/m/set/${setId}/step` const response = await this.api.axiosGo.post(endpoint, step) return response.data } async updateSetStep (setId: string, step: ISetStep): Promise { const endpoint = `/m/set/${setId}/step/${step.key}` const response = await this.api.axiosGo.post(endpoint, step) return response.data } async deleteSetStep (setId: string, stepKey: string): Promise { const endpoint = `/m/set/${setId}/step/${stepKey}` const response = await this.api.axiosGo.delete(endpoint) return response.data } // 允許外賣 async updateSetTakeawayEnable (enabled: boolean): Promise { const endpoint = '/m/set/takeaway' const response = await this.api.axiosGo.post(endpoint, { enabled }) return response.data } // 允許堂食 async updateSetNonTakeawayEnable (enabled: boolean): Promise { const endpoint = '/m/set/nontakeaway' const response = await this.api.axiosGo.post(endpoint, { enabled }) return response.data } // * Set Menu async addSetMenu (setId: string, step: string, menuId: string): Promise { const endpoint = '/m/setmenu' const response = await this.api.axiosGo.post(endpoint, { setID: setId, step: step, menuID: menuId, }) return response.data } async updateSetMenu (setId: string, setMenuId: string, setMenu: ISetMenu): Promise { const endpoint = `/m/setmenu/${setMenuId}/info` const response = await this.api.axiosGo.post(endpoint, { ...setMenu, setID: setId, categoryID: setMenu.categoryId, }) return response.data } async updateSetMenuPrice (setMenuId: string, data: IUpdateTakeawayPriceRequestData): Promise { const endpoint = `/m/setmenu/${setMenuId}/price` const response = await this.api.axiosGo.post(endpoint, data) return response.data } async deleteSetMenu (setMenuId: string): Promise { const endpoint = `/m/setmenu/${setMenuId}` await this.api.axiosGo.delete(endpoint) } // * Set Option // 新增選項群 async createSetOptionGroup (setId: string, optionGroup: IMenuOptionGroup): Promise { const endpoint = `/m/set/${setId}/group` const response = await this.api.axiosGo.post(endpoint, optionGroup) return response.data } // 修改選項群 async updateSetOptionGroup (setId: string, groupId: string, optionGroup: IMenuOptionGroup): Promise { const endpoint = `/m/set/${setId}/group/${groupId}` const response = await this.api.axiosGo.post(endpoint, optionGroup) return response.data } // 刪除選項群 async deleteSetOptionGroup (setId: string, groupId: string): Promise { const endpoint = `/m/set/${setId}/group/${groupId}` const response = await this.api.axiosGo.delete(endpoint) return response.data } // 新增選項 async createSetOption (setId: string, groupId: string, option: IMenuOptionItem): Promise { const endpoint = `/m/set/${setId}/group/${groupId}/opt` const response = await this.api.axiosGo.post(endpoint, option) return response.data } // 修改選項 async updateSetOption (setId: string, groupId: string, optionId: string, option: IMenuOptionItem): Promise { const endpoint = `/m/set/${setId}/group/${groupId}/opt/${optionId}` const response = await this.api.axiosGo.post(endpoint, option) return response.data } // 刪除選項 async deleteSetOption (setId: string, groupId: string, optionId: string): Promise { const endpoint = `/m/set/${setId}/group/${groupId}/opt/${optionId}` const response = await this.api.axiosGo.delete(endpoint) return response.data } // * Menu async getMenu (id: string, locale?: string): Promise { const response = await this.api.axiosGo.get(`/m/menu/info/${id}`, { headers: { 'Accept-Language': locale != null ? locale : this.api.locale, }, }) return response.data } async getSoldOutMenus (): Promise { const response = await this.api.axiosGo.get('/m/menu', { params: { soldOut: true }, }) return response.data } async getPromotedMenus (): Promise { const response = await this.api.axiosGo.get('/m/menu', { params: { promoted: true }, }) return response.data } // 建立 menu,要另外再 call updateMenuTakeawayPrice, updateMenuTakeawayEnable 和 updateMenuNonTakeawayEnable async createMenu (menu: ICreateMenuRequestData): Promise { const endpoint = '/m/menu' const response = await this.api.axiosGo.post(endpoint, menu) return response.data } async deleteMenu ( menuId: string, perm: boolean = false, // 永久刪除 ): Promise { const endpoint = `/m/menu/${menuId}` await this.api.axiosGo.delete(endpoint, { params: { perm } }) } async revealMenu (menuId: string): Promise { await this.api.axiosGo.put(`/m/menu/${menuId}/reveal`) } async updateMenu (menuId: string, menu: ICreateMenuRequestData): Promise { const endpoint = `/m/menu/${menuId}/info` const response = await this.api.axiosGo.post(endpoint, menu) return response.data } // 修改外帶價格 async updateMenuTakeawayPrice (menuId: string, data: IUpdateTakeawayPriceRequestData): Promise { const endpoint = `/m/menu/${menuId}/price` const response = await this.api.axiosGo.post(endpoint, data) return response.data } // 允許外賣 async updateMenuTakeawayEnable (menuId: string, enabled: boolean): Promise { const endpoint = `/m/menu/${menuId}/takeaway` const response = await this.api.axiosGo.post(endpoint, { enabled }) return response.data } // 允許堂食 async updateMenuNonTakeawayEnable (menuId: string, enabled: boolean): Promise { const endpoint = `/m/menu/${menuId}/nontakeaway` const response = await this.api.axiosGo.post(endpoint, { enabled }) return response.data } // * Menu Option // 新增選項群 async createMenuOptionGroup (menuId: string, optionGroup: IMenuOptionGroup): Promise { const endpoint = `/m/menu/${menuId}/group` const response = await this.api.axiosGo.post(endpoint, optionGroup) return response.data } // 修改選項群 async updateMenuOptionGroup (menuId: string, groupId: string, optionGroup: IMenuOptionGroup): Promise { const endpoint = `/m/menu/${menuId}/group/${groupId}` const response = await this.api.axiosGo.post(endpoint, optionGroup) return response.data } // 刪除選項群 async deleteMenuOptionGroup (menuId: string, groupId: string): Promise { const endpoint = `/m/menu/${menuId}/group/${groupId}` const response = await this.api.axiosGo.delete(endpoint) return response.data } // 新增選項 async createMenuOption (menuId: string, groupId: string, option: IMenuOptionItem): Promise { const endpoint = `/m/menu/${menuId}/group/${groupId}/opt` const response = await this.api.axiosGo.post(endpoint, option) return response.data } // 修改選項 async updateMenuOption (menuId: string, groupId: string, optionId: string, option: IMenuOptionItem): Promise { const endpoint = `/m/menu/${menuId}/group/${groupId}/opt/${optionId}` const response = await this.api.axiosGo.post(endpoint, option) return response.data } // 刪除選項 async deleteMenuOption (menuId: string, groupId: string, optionId: string): Promise { const endpoint = `/m/menu/${menuId}/group/${groupId}/opt/${optionId}` const response = await this.api.axiosGo.delete(endpoint) return response.data } }