onoffice
Version:
OnOffice typescript api client and sdk
41 lines (40 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
class OnOfficeAPIClient {
getEstates(filter = {}, data = models_1.ALL_ESTATE_FIELDS) {
return this.readResource('estate', {
data,
filter
});
}
getEstate(id, data = models_1.ALL_ESTATE_FIELDS) {
return this.readResource('estate', {
data
}, id).then(res => res[0]);
}
getEstateImages(id) {
return this.getResource('estatepictures', {
estateids: [id],
categories: ['Foto'],
size: 'original',
language: 'GER'
}).then(records => new Array().concat(...records.map(({ elements }) => elements)));
}
getResource(type, parameters) {
return this.fetchAction('urn:onoffice-de-ns:smart:2.5:smartml:action:get', type, '', '', parameters).then(res => OnOfficeAPIClient.reduceActionsResponse(res)).then(results => results[0].data.records);
}
readResource(type, parameters, id = '') {
return this.fetchAction('urn:onoffice-de-ns:smart:2.5:smartml:action:read', type, '', String(id), parameters).then(res => OnOfficeAPIClient.reduceActionsResponse(res)).then(results => results[0].data.records);
}
unlockProvider(parameterCacheId, isRegularCustomer = 0) {
return this.fetchAction("urn:onoffice-de-ns:smart:2.5:smartml:action:do", "unlockProvider", "", "", {
parameterCacheId,
isRegularCustomer
});
}
static reduceActionsResponse(res) {
return res.response.results;
}
}
exports.default = OnOfficeAPIClient;