UNPKG

onoffice

Version:

OnOffice typescript api client and sdk

38 lines (37 loc) 1.56 kB
import { ALL_ESTATE_FIELDS } from '../models/index.js'; export default class OnOfficeAPIClient { getEstates(filter = {}, data = ALL_ESTATE_FIELDS) { return this.readResource('estate', { data, filter }); } getEstate(id, data = 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; } }