@c8y/client
Version:
Client application programming interface to access the Cumulocity IoT-Platform REST services.
152 lines • 4.11 kB
JavaScript
import { __awaiter } from "tslib";
import { Service } from '../core';
/**
* This class allows managing for events.
*/
export class EventService extends Service {
constructor() {
super(...arguments);
this.baseUrl = 'event';
this.listUrl = 'events';
this.propertyName = 'events';
this.channel = '/events/*';
}
/**
* Gets the details of a specific event.
*
* @param {string|number|IIdentified} entityOrId Entity or Id of the entity.
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* const eventId: number = 1;
*
* (async () => {
* const {data, res} = await eventService.detail(eventId);
* })();
* ```
*/
detail(entityOrId) {
const _super = Object.create(null, {
detail: { get: () => super.detail }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.detail.call(this, entityOrId);
});
}
/**
* Creates a new event.
*
* @param {IEvent} entity Event object with mandantory fragments.
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* const mandantoryObject: IEvent = {
* source: device,
* text: 'I am an Event!',
* time: '2018-05-02T10:08:00Z',
* type: 'device-type-here',
* };
*
* (async () => {
* const {data, res} = await eventService.create(mandantoryObject);
* })();
* ```
*/
create(entity) {
const _super = Object.create(null, {
create: { get: () => super.create }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.create.call(this, entity);
});
}
/**
* Updates event data.
*
* @param {Partial<IEvent>} entity Event is partially updatable.
*
* @returns Response wrapped in [[IResult]]
*
* **Example**
* ```typescript
*
* const partialUpdateObject: Partial<IEvent> = {
* source: device,
* text: 'Changed Event!'
* };
*
* (async () => {
* const {data, res} = await eventService.update(partialUpdateObject);
* })();
* ```
*/
update(entity) {
const _super = Object.create(null, {
update: { get: () => super.update }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.update.call(this, entity);
});
}
/**
* Gets the list of events filtered by parameters.
*
* @returns Response wrapped in [[IResultList]]
*
* @param {object} filter Object containing filters for querying events.
*
* **Example**
* ```typescript
*
* const filter: object = {
* pageSize: 100,
* withTotalPages: true
* };
*
* (async () => {
* const {data, res, paging} = await eventService.list(filter);
* })();
* ```
*/
list() {
const _super = Object.create(null, {
list: { get: () => super.list }
});
return __awaiter(this, arguments, void 0, function* (filter = {}) {
return _super.list.call(this, filter);
});
}
/**
* Removes an event with given id.
*
* @returns Response wrapped in [[IResult]]
*
* @param {string | number | IIdentified} entityOrId entity or id of the event.
*
* **Example**
* ```typescript
*
* const eventId: number = 1;
*
* (async () => {
* const {data, res} = await eventService.delete(eventId);
* // data will be null
* })();
* ```
*/
delete(entityOrId) {
const _super = Object.create(null, {
delete: { get: () => super.delete }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.delete.call(this, entityOrId);
});
}
}
//# sourceMappingURL=EventService.js.map