Skip to content

Commit 7ba810e

Browse files
authored
feat(cayenne): datatypes v2
* feat: grapql endpoints for datatypes and device types * fix: changed parameters, url and lint errors * fix: lint errors * fix: remove unused endpoint
1 parent 711b907 commit 7ba810e

File tree

3 files changed

+597
-233
lines changed

3 files changed

+597
-233
lines changed

lib/Services/cayenne.js

Lines changed: 206 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,93 @@ class Cayenne {
357357
return this.auth.send(this.service, 'GET', url);
358358
}
359359

360+
/**
361+
* Get V2 one things data type
362+
*/
363+
deleteThingDataTypeV2(id) {
364+
const url = `${this.url}/v2/things/datatypes/${id}`;
365+
return this.auth.send(this.service, 'DELETE', url);
366+
}
367+
368+
/**
369+
* @param {Object} payload
370+
* @param {String} payload.name
371+
* @param {String} payload.label
372+
* @param {String} payload.payload
373+
*/
374+
createThingDataTypeV2(payload) {
375+
const url = `${this.url}/v2/things/datatypes`;
376+
return this.auth.send(this.service, 'POST', url, { payload });
377+
}
378+
379+
/**
380+
* @param {Object} id
381+
* @param {Object} payload
382+
* @param {String} payload.name
383+
* @param {String} payload.label
384+
* @param {String} payload.payload
385+
*/
386+
updateThingDataTypeV2(id, payload) {
387+
const url = `${this.url}/v2/things/datatypes/${id}`;
388+
return this.auth.send(this.service, 'PUT', url, { payload });
389+
}
390+
360391
/**
361392
* Get V2 one things data type properties
393+
* @param {String} typeId
362394
* @param {Object} query
363395
* @param {Number} [query.limit]
364396
* @param {Number} [query.page]
365397
*/
366-
getThingDataTypePropertiesV2(id, query) {
367-
const url = `${this.url}/v2/things/datatypes/${id}/properties`;
398+
getThingDataTypePropertiesV2(typeId, query) {
399+
const url = `${this.url}/v2/things/datatypes/${typeId}/properties`;
400+
return this.auth.send(this.service, 'GET', url, { query });
401+
}
402+
403+
/**
404+
* Count V2 all things data types
405+
* @param {Object} query
406+
*/
407+
countThingDataTypePropertiesV2(typeId, query) {
408+
const url = `${this.url}/v2/things/datatypes/${typeId}/properties`;
368409
return this.auth.send(this.service, 'GET', url, { query });
369410
}
370411

412+
/**
413+
* Create a V2 datatype property
414+
* @param {String} typeId
415+
* @param {Object} payload
416+
*/
417+
createThingDataTypePropertyV2(typeId, payload) {
418+
const url = `${this.url}/v2/things/datatypes/${typeId}/properties`;
419+
return this.auth.send(this.service, 'POST', url, { payload });
420+
}
421+
422+
/**
423+
* Update V2 datatypes properties
424+
* @param {String} typeId
425+
* @param {Number} propertyId
426+
* @param {Object} payload
427+
*/
428+
updateThingDataTypePropertyV2(typeId, pid, payload) {
429+
const url = `${this.url}/v2/things/datatypes/${typeId}/properties/${pid}`;
430+
return this.auth.send(this.service, 'PUT', url, { payload });
431+
}
432+
433+
/**
434+
* delete V2 one things data type properties
435+
* @param {String} typeId
436+
* @param {Number} pid
437+
*/
438+
deleteThingDataTypePropertyV2(typeId, pid) {
439+
const url = `${this.url}/v2/things/datatypes/${typeId}/properties/${pid}`;
440+
return this.auth.send(this.service, 'GET', url);
441+
}
442+
371443
/**
372444
* Get V2 one things data type property by it's id
445+
* @param {String} typeId
446+
* @param {Number} pid
373447
*/
374448
getThingDataTypePropertyV2(id, pid) {
375449
const url = `${this.url}/v2/things/datatypes/${id}/properties/${pid}`;
@@ -402,6 +476,14 @@ class Cayenne {
402476
return this.auth.send(this.service, 'GET', url);
403477
}
404478

479+
/**
480+
* Count device types
481+
*/
482+
countDeviceTypes() {
483+
const url = `${this.url}/things/types/count`;
484+
return this.auth.send(this.service, 'GET', url);
485+
}
486+
405487
/**
406488
* Gets a device's meta data by device type id
407489
* @param {String} deviceTypeId
@@ -428,6 +510,15 @@ class Cayenne {
428510
});
429511
}
430512

513+
/**
514+
* Count a device's meta data by device type id
515+
* @param {String} deviceTypeId
516+
*/
517+
countDeviceTypeMeta(deviceTypeId) {
518+
const url = `${this.url}/things/types/${deviceTypeId}/meta/count`;
519+
return this.auth.send(this.service, 'GET', url);
520+
}
521+
431522
/**
432523
* Gets a device's meta data by device type id
433524
* @param {String} deviceTypeId
@@ -465,6 +556,15 @@ class Cayenne {
465556
return this.auth.send(this.service, 'GET', url);
466557
}
467558

559+
/**
560+
* Count a device's channel meta by device type id
561+
* @param {String} deviceTypeId
562+
*/
563+
countDeviceTypeChannels(deviceTypeId) {
564+
const url = `${this.url}/things/types/${deviceTypeId}/channels/count`;
565+
return this.auth.send(this.service, 'GET', url);
566+
}
567+
468568
/**
469569
* Get a device type's uses
470570
* @param {String} deviceTypeId
@@ -474,6 +574,15 @@ class Cayenne {
474574
return this.auth.send(this.service, 'GET', url);
475575
}
476576

577+
/**
578+
* Count a device type's uses
579+
* @param {String} deviceTypeId
580+
*/
581+
countDeviceTypeUses(deviceTypeId) {
582+
const url = `${this.url}/things/types/${deviceTypeId}/uses/count`;
583+
return this.auth.send(this.service, 'GET', url);
584+
}
585+
477586
/**
478587
* Creates a new device type
479588
* @param {Object} payload
@@ -496,6 +605,29 @@ class Cayenne {
496605
return this.auth.send(this.service, 'POST', url, { payload });
497606
}
498607

608+
/**
609+
* Updates a device type
610+
* @param {String} id
611+
* @param {Object} payload
612+
* @param {String} payload.name
613+
* @param {String} payload.description
614+
* @param {String} payload.model
615+
* @param {String} payload.version
616+
* @param {String} payload.properties
617+
* @param {String} payload.manufacturer
618+
* @param {String} payload.transport_protocol
619+
* @param {String} payload.protocol_version
620+
* @param {String} payload.category
621+
* @param {String} payload.codec
622+
* @param {String} payload.subcategory
623+
* @param {String} payload.parent_constraint
624+
* @param {String} payload.child_constraint
625+
*/
626+
updateDeviceType(deviceTypeId, payload) {
627+
const url = `${this.url}/things/types/${deviceTypeId}`;
628+
return this.auth.send(this.service, 'PUT', url, { payload });
629+
}
630+
499631
/**
500632
* @param {String} deviceTypeId
501633
* @param {Object} payload
@@ -509,6 +641,32 @@ class Cayenne {
509641
return this.auth.send(this.service, 'POST', url, { payload });
510642
}
511643

644+
/**
645+
* @param {String} deviceTypeId
646+
* @param {Object} payload
647+
* @param {String} payload.name
648+
* @param {String} payload.datatype
649+
* @param {String} payload.channel
650+
* @param {String} [payload.ipso]
651+
*/
652+
updateDeviceTypeChannel(deviceTypeId, channelId, payload) {
653+
const url = `${
654+
this.url
655+
}/things/types/${deviceTypeId}/channels/${channelId}`;
656+
return this.auth.send(this.service, 'PUT', url, { payload });
657+
}
658+
659+
/**
660+
* @param {String} deviceTypeId
661+
* @param {String} channelId
662+
*/
663+
deleteDeviceTypeChannel(deviceTypeId, channelId) {
664+
const url = `${
665+
this.url
666+
}/things/types/${deviceTypeId}/channels/${channelId}`;
667+
return this.auth.send(this.service, 'DELETE', url);
668+
}
669+
512670
/**
513671
* @param {String} deviceTypeId
514672
* @param {Object} payload
@@ -520,6 +678,29 @@ class Cayenne {
520678
return this.auth.send(this.service, 'POST', url, { payload });
521679
}
522680

681+
/**
682+
* @param {String} deviceTypeId
683+
* @param {String} metaId
684+
* @param {Object} payload
685+
* @param {String} payload.name
686+
* @param {String} payload.datatype
687+
* @param {String} payload.channel
688+
* @param {String} [payload.ipso]
689+
*/
690+
updateDeviceTypeMeta(deviceTypeId, metaId, payload) {
691+
const url = `${this.url}/things/types/${deviceTypeId}/meta/${metaId}`;
692+
return this.auth.send(this.service, 'PUT', url, { payload });
693+
}
694+
695+
/**
696+
* @param {String} deviceTypeId
697+
* @param {String} metaId
698+
*/
699+
deleteDeviceTypeMeta(deviceTypeId, metaId) {
700+
const url = `${this.url}/things/types/${deviceTypeId}/channels/${metaId}`;
701+
return this.auth.send(this.service, 'DELETE', url);
702+
}
703+
523704
/**
524705
* @param {String} deviceTypeId
525706
* @param {Object} payload
@@ -534,6 +715,29 @@ class Cayenne {
534715
return this.auth.send(this.service, 'POST', url, { payload });
535716
}
536717

718+
/**
719+
* @param {String} deviceTypeId
720+
* @param {String} useId
721+
* @param {Object} payload
722+
* @param {String} payload.name
723+
* @param {String} payload.datatype
724+
* @param {String} payload.channel
725+
* @param {String} [payload.ipso]
726+
*/
727+
updateDeviceTypeUse(deviceTypeId, useId, payload) {
728+
const url = `${this.url}/things/types/${deviceTypeId}/meta/${useId}`;
729+
return this.auth.send(this.service, 'PUT', url, { payload });
730+
}
731+
732+
/**
733+
* @param {String} deviceTypeId
734+
* @param {String} useId
735+
*/
736+
deleteDeviceTypeUse(deviceTypeId, useId) {
737+
const url = `${this.url}/things/types/${deviceTypeId}/channels/${useId}`;
738+
return this.auth.send(this.service, 'DELETE', url);
739+
}
740+
537741
/**
538742
* Delete a device type
539743
* @param {String} deviceTypeId

0 commit comments

Comments
 (0)