...
 
Commits (3)
......@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `argv.getConfigFileName` take a config from UB_CFG environment variable if `-cfg` cmd line switch omitted
- `FileBaseStoreLoader.load()` now return data version in TubDataCache.
To be used in file-based entitis select's instead of version calculation individually in each entity
- `UBConnection.setDocument` method for convinient uploading content to temp store, for example in model initialization or
data update/migration scripts
### Fixed
- LocalDataStore sometimes not filter by ID (known bug in TubList)
......@@ -501,6 +501,47 @@ UBConnection.prototype.logout = function () {
}
}
/**
* Set document method saves a file content as a potential value of the specified entity instance attribute,
* the value is saved to temp store.
* Call this function before entity insert of update. Result of this function is what shall be assigned to the
* attribute value, to "execParams".
* @param {string} entity Entity name
* @param {string} attribute Entity attribute name
* @param {number} id ID of the record
* @param {ArrayBuffer} data File content
* @param {string} origName
* @param {string} [fileName] If not specified, origName will be used.
* @return {string}
*
* @example
* const myObj = conn.Repository(entityName)
* .attrs('ID', 'mi_modifyDate')
* .where('code', '=', code)
* .selectSingle();
* const {ID, mi_modifyDate} = myObj;
* const data = fs.readFileSync(fileName, {encoding: 'bin'});
* const tempStoreResult = conn.setDocument(entityName, 'configuration', ID, data, fn);
* conn.query({
* entity: entityName,
* method: 'update',
* execParams: {ID, configuration: tempStoreResult, mi_modifyDate}
* });
*/
UBConnection.prototype.setDocument = function (entity, attribute, id, data, origName, fileName) {
const setDocumentResponse = this.xhr({
HTTPMethod: 'POST',
endpoint: 'setDocument',
data,
URLParams: {
entity, attribute, id,
origName: origName || fileName,
filename: fileName || origName
}
})
return JSON.stringify(setDocumentResponse.result)
}
/**
* Execute insert method by add method: 'insert' to `ubq` query (if req.method not already set)
*
......