dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
106 lines • 5.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BusinessObjectBase = void 0;
const tslib_1 = require("tslib");
const livelink_query_service_1 = require("../lib-core/livelink-query-service");
const uuid4 = tslib_1.__importStar(require("uuid"));
const dms_root_container_1 = require("../ioc/dms-root-container");
const application_context_service_1 = require("./application-context-service");
class BusinessObjectBase {
constructor() {
this.state = 0;
this["DMS_ROWID"] = uuid4.v4();
}
validateMembers() {
if (!this.members)
throw new Error(`'${this.boName}' does not have members property.Is this a valid business object?`);
for (var i = 0; i < this.members.length; i++) {
let member = this.members[i];
if (member.required) {
if (this[member.name] == undefined || this[member.name] == null) {
throw new Error(`Value for member '${this.boName}.${member.name}' is required`);
}
}
}
;
}
// protected abstract query(): DbQuery<BusinessObjectBase>;
// protected abstract livelinkQuery(): LiveLinkQuery<BusinessObjectBase>;
/**
* stores the current instance in the local db storage as new record
* and syncronises the instance to the server side
*/
add(company) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (this.state == 1)
throw new Error('This entity instance can not be added, because it was already added.');
if (this.state == 3)
throw new Error('This entity instance can not be added, because it was already deleted .');
this.validateMembers();
var q = this.query();
var keys = yield q.executeCreate(this);
this.state = 1;
if (!this.dontPostToSyncLog) {
const dms = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService);
var ll = new livelink_query_service_1.LiveLinkQuery(dms, livelink_query_service_1.appAreaServiceName, this.appCode, this.boName, this.boTableName, this.boSyncName, this.members);
if (company) {
ll.company(company);
}
yield ll.postToSyncLog(this);
}
});
}
/**
* updates the current instance in the local db storage
* and syncronises the instance to the server side
*/
update(company) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this['DMS_ROWID'])
throw new Error('This entity instance can not be updated, because it does not have DMS_ROWID valie.');
if (this.state == 3)
throw new Error('This entity instance can not be updated, because it was already deleted .');
if (!this['DMS_ROWID'])
throw new Error(`Business object ${this.boName} requires value for DMS_ROW to be updated`);
this.validateMembers();
var q = this.query();
yield q.executeUpdate(this);
this.state = 2;
if (!this.dontPostToSyncLog) {
const dms = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService);
var ll = new livelink_query_service_1.LiveLinkQuery(dms, '$$apparea', this.appCode, this.boName, this.boTableName, this.boSyncName, this.members);
if (company) {
ll.company(company);
}
yield ll.postToSyncLog(this);
}
});
}
/**
* deletes the current instance from the local db storage
* and syncronises the instance to the server side
*/
delete(company) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!this['DMS_ROWID'])
throw new Error('This entity instance can not be added, because it does not have DMS_ROWID value.');
if (this.state == 3)
throw new Error('This entity instance can not be updated, because it was already deleted .');
if (!this['DMS_ROWID'])
throw new Error(`Business object ${this.boName} requires value for DMS_ROW to be deleted`);
var q = this.query();
yield q.executeDelete({ DMS_ROWID: this['DMS_ROWID'] });
this.state = 3;
if (!this.dontPostToSyncLog) {
const dms = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService);
var ll = new livelink_query_service_1.LiveLinkQuery(dms, livelink_query_service_1.appAreaServiceName, this.appCode, this.boName, this.boTableName, this.boSyncName, this.members);
if (company) {
ll.company(company);
}
yield ll.postToSyncLog(this);
}
});
}
}
exports.BusinessObjectBase = BusinessObjectBase;
//# sourceMappingURL=business-object.js.map