dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
188 lines • 9.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiveLinkQueryViaCloud = void 0;
const tslib_1 = require("tslib");
const dms_platform_bridge_factory_1 = require("../../platform/dms-platform-bridge-factory");
const dms_api_wrapper_1 = require("../../platform-web/dms-api-wrapper");
const livelink_query_apparea_1 = require("./livelink-query-apparea");
class LiveLinkQueryViaCloud extends livelink_query_apparea_1.LiveLinkQueryAppArea {
executeCommand(parameters) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
throw new Error('LiveLinkQuery.executeCommand for viaCloud is not supported');
});
}
executeSelect() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
let authToken = this.customAuthToken;
if (!authToken)
authToken = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getSessionKey", null);
let url = `${dms_api_wrapper_1.DmsAPIWrapper._baseAPIUrl}/livelink/${this._serviceName}/${this._entityName}`;
const data = {
index: this._page != null ? this._page : 0,
filter: this._filter != null ? this.sqlOperatorsToODATAOperators(this._filter) : '',
top: this._max != null ? this._max : 50,
company: this._company ? this._company : undefined,
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
try {
//cloud application area
const appArea = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getApparea", null);
var response = yield dms_api_wrapper_1.DmsAPIWrapper.executeApiRequest(appArea, url, 'GET', authToken);
if (response) {
let d = response.data ? response.data : response;
if (typeof d === 'string') {
d = JSON.parse(d);
}
const v = d.value;
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err);
}
});
}
executeCount() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
let authToken = this.customAuthToken;
if (!authToken)
authToken = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getSessionKey", null);
let url = `${dms_api_wrapper_1.DmsAPIWrapper._baseAPIUrl}/livelink/${this._serviceName}/${this._entityName}`;
const data = {
index: this._page != null ? this._page : 0,
filter: this._filter != null ? this.sqlOperatorsToODATAOperators(this._filter) : '',
top: this._max != null ? this._max : 50,
company: this._company ? this._company : undefined,
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
try {
//cloud application area
const appArea = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getApparea", null);
var response = yield dms_api_wrapper_1.DmsAPIWrapper.executeApiRequest(appArea, url, 'GET', authToken);
if (response) {
let d = response.data ? response.data : response;
if (typeof d === 'string') {
d = JSON.parse(d);
}
const v = d.value;
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return Array.isArray(v) ? v.length : 0;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err);
}
});
}
executeCreate(entity) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
let authToken = this.customAuthToken;
if (!authToken)
authToken = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getSessionKey", null);
let url = `${dms_api_wrapper_1.DmsAPIWrapper._baseAPIUrl}/livelink/${this._serviceName}/${this._entityName}/create`;
try {
const appArea = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getApparea", null);
var response = yield dms_api_wrapper_1.DmsAPIWrapper.executeApiRequest(appArea, url, 'POST', authToken, null, JSON.stringify(entity));
if (response && response.data) {
const v = JSON.parse(response.data).value;
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err);
}
});
}
executeUpdate(entity, pkValues, pkFields) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const appArea = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getApparea", null);
let authToken = this.customAuthToken;
if (!authToken)
authToken = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getSessionKey", null);
const pkValuesStirng = pkValues ? `?pk=${pkValues.join(',')}` : '';
let url = `${dms_api_wrapper_1.DmsAPIWrapper._baseAPIUrl}/livelink/${this._serviceName}/${this._entityName}/update${pkValuesStirng}`;
try {
var response = yield dms_api_wrapper_1.DmsAPIWrapper.executeApiRequest(appArea, url, 'POST', authToken, null, JSON.stringify(entity));
if (response && response.data) {
return JSON.parse(response.data).value;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err);
}
});
}
executeDelete(entity, pkValues, pkFields) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const appArea = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getApparea", null);
let authToken = this.customAuthToken;
if (!authToken)
authToken = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getSessionKey", null);
let url = `${dms_api_wrapper_1.DmsAPIWrapper._baseAPIUrl}/livelink/${this._serviceName}/${this._entityName}/delete`;
try {
var response = yield dms_api_wrapper_1.DmsAPIWrapper.executeApiRequest(appArea, url, 'POST', authToken, null, JSON.stringify(entity));
if (response && response.data) {
return JSON.parse(response.data).value;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err);
}
});
}
}
exports.LiveLinkQueryViaCloud = LiveLinkQueryViaCloud;
//# sourceMappingURL=livelink-query-viacloud.js.map