minapp-fetch
Version:
72 lines (71 loc) • 2.77 kB
JavaScript
;
/*
* @Author: your name
* @Date: 2020-01-23 18:19:36
* @LastEditTime: 2020-06-06 08:53:00
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /minapp-fetch/src/fetch/content/getCategory.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 fetchGetCategory(contentGroupID, categoryID) {
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.get(categoryID).then((res) => {
// success
resolve(res);
}, (err) => {
// err
reject(err);
});
}
let MyContentGroup = new BaaS_F.ContentGroup(contentGroupID);
MyContentGroup.getCategory(categoryID).then((res) => {
// success
resolve(res);
}, (err) => {
// err
reject(err);
});
}
//MongoDB
if (constants_1.PLATFORM_NAME_MONGO_SERVER.indexOf(minapp) > -1) {
throw new Error(`minapp.getCategory ${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/${categoryID}/`,
headers: options.Header,
params: {
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/${categoryID}/`).then((res) => {
resolve(res);
}).catch((err) => {
reject(err);
});
}
if (constants_1.PLATFORM_ALL.indexOf(minapp) === -1) {
throw new Error(`minapp.getCategory ${error_1.METHOD_NOT_SUPPORT}`);
}
});
}
exports.default = fetchGetCategory;