UNPKG

minapp-fetch

Version:
81 lines (80 loc) 3.26 kB
"use strict"; /* * @Author: your name * @Date: 2020-01-23 17:44:21 * @LastEditTime: 2020-06-06 08:50:38 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /minapp-fetch/src/fetch/content/findCategory.ts */ Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils/utils"); const constants_1 = require("./constants/constants"); const error_1 = require("./constants/error"); function fetchFindCategory(contentGroupID, params = {}) { let { BaaS_F, minapp, options } = utils_1.getBaaSF(); return new Promise((resolve, reject) => { if (constants_1.PLATFORM_NAME_BAAS.indexOf(minapp) > -1) { if (minapp === constants_1.PLATFORM_NAME.ZX_CLOUD) { let MyContentCategory = new BaaS_F.ContentCategory(contentGroupID); MyContentCategory.limit(params.limit || 20).offset((params.limit || 20) * ((params.page || 1) - 1)).orderBy(params.orderBy || '-created_at').find({ withCount: params.withCount || false }).then((res) => { // success resolve(res); }, (err) => { // err reject(err); }); } let MyContentGroup = new BaaS_F.ContentGroup(contentGroupID); MyContentGroup.getCategoryList({ withCount: params.withCount || false }).then((res) => { // success resolve(res); }, (err) => { // err reject(err); }); } //MongoDB if (constants_1.PLATFORM_NAME_MONGO_SERVER.indexOf(minapp) > -1) { throw new Error(`minapp.findCategory ${error_1.METHOD_NOT_SUPPORT}`); } //webapi if (minapp === constants_1.PLATFORM_NAME.ZX_WEBAPI) { if (!options) throw new Error(error_1.WEBAPI_OPTIONS_ERROR); BaaS_F({ method: 'get', url: `${options.RequestBase}/hserve/v2.2/content/category/`, headers: options.Header, params: { limit: params.limit || 100, return_total_count: params.withCount ? 1 : 0, content_group_id: contentGroupID, }, }).then((res) => { resolve(res); }).catch((err) => { reject(err); }); } //op 运营后台 if (minapp === constants_1.PLATFORM_NAME.ZX_OP) { BaaS_F.get(`https://cloud.minapp.com/userve/v2.2/content/${contentGroupID}/category`, { params: { limit: params.limit || 100, return_total_count: params.withCount ? 1 : 0, } }).then((res) => { resolve(res); }).catch((err) => { reject(err); }); } if (constants_1.PLATFORM_ALL.indexOf(minapp) === -1) { throw new Error(`minapp.findCategory ${error_1.METHOD_NOT_SUPPORT}`); } }); } exports.default = fetchFindCategory;