Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Add support for devices per group endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
aduchate committed May 4, 2022
1 parent 3a70455 commit 487e0ab
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
71 changes: 71 additions & 0 deletions icc-api/api/IccDeviceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ export class IccDeviceApi {
.catch((err) => this.handleError(err))
}

/**
* One of Name or Last name+First name, Nihii, and Public key are required.
* @summary Create a device
* @param body
* @param groupId
*/
createDeviceInGroup(groupId: string, body?: Device): Promise<Device> {
let _body = null
_body = body

const _url = this.host + `/device/inGroup/${encodeURIComponent(String(groupId))}` + '?ts=' + new Date().getTime()
let headers = this.headers
headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR.Header('Content-Type', 'application/json'))
return XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl)
.then((doc) => new Device(doc.body as JSON))
.catch((err) => this.handleError(err))
}

/**
* Returns the id and _rev of created devices
* @summary Create devices in bulk
Expand Down Expand Up @@ -120,6 +138,23 @@ export class IccDeviceApi {
.catch((err) => this.handleError(err))
}

/**
* Deleting a device. Response is an array containing the id of deleted device.
* @summary Delete a device
* @param groupId
* @param deviceIds
*/
deleteDevicesInGroup(groupId: string, deviceIds: string): Promise<Array<DocIdentifier>> {
let _body = null

const _url =
this.host + `/device/inGroup/${encodeURIComponent(String(groupId))}/${encodeURIComponent(String(deviceIds))}` + '?ts=' + new Date().getTime()
let headers = this.headers
return XHR.sendCommand('DELETE', _url, headers, _body, this.fetchImpl)
.then((doc) => (doc.body as Array<JSON>).map((it) => new DocIdentifier(it)))
.catch((err) => this.handleError(err))
}

/**
* Returns a list of devices along with next start keys and Document ID. If the nextStartKey is Null it means that this is the last page.
* @summary Filter devices for the current user (HcParty)
Expand Down Expand Up @@ -192,6 +227,24 @@ export class IccDeviceApi {
.catch((err) => this.handleError(err))
}

/**
* General information about the device
* @summary Get devices by their IDs
* @param body
* @param groupId
*/
getDevicesInGroup(groupId: string, body?: ListOfIds): Promise<Array<Device>> {
let _body = null
_body = body

const _url = this.host + `/device/inGroup/${encodeURIComponent(String(groupId))}/byIds` + '?ts=' + new Date().getTime()
let headers = this.headers
headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR.Header('Content-Type', 'application/json'))
return XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl)
.then((doc) => (doc.body as Array<JSON>).map((it) => new Device(it)))
.catch((err) => this.handleError(err))
}

/**
*
* @summary Get ids of devices matching the provided filter for the current user (HcParty)
Expand All @@ -209,6 +262,24 @@ export class IccDeviceApi {
.catch((err) => this.handleError(err))
}

/**
* No particular return value. It's just a message.
* @summary Modify a Device.
* @param body
* @param groupId
*/
modifyDeviceInGroup(groupId: string, body?: Device): Promise<Device> {
let _body = null
_body = body

const _url = this.host + `/device/inGroup/${encodeURIComponent(String(groupId))}` + '?ts=' + new Date().getTime()
let headers = this.headers
headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR.Header('Content-Type', 'application/json'))
return XHR.sendCommand('PUT', _url, headers, _body, this.fetchImpl)
.then((doc) => new Device(doc.body as JSON))
.catch((err) => this.handleError(err))
}

/**
* Returns the updated device
* @summary Modify a device
Expand Down
2 changes: 1 addition & 1 deletion icc-api/api/IccUserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class IccUserApi {

/**
* Returns a list of users.
* @summary List users with(out) pagination
* @summary List users with pagination
* @param groupId
* @param startKey An user login
* @param startDocumentId An user document ID
Expand Down
2 changes: 2 additions & 0 deletions icc-api/model/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export namespace Address {
| 'postal'
| 'diplomatic'
| 'reference'
| 'careaddress'
export const AddressTypeEnum = {
Home: 'home' as AddressTypeEnum,
Work: 'work' as AddressTypeEnum,
Expand All @@ -93,5 +94,6 @@ export namespace Address {
Postal: 'postal' as AddressTypeEnum,
Diplomatic: 'diplomatic' as AddressTypeEnum,
Reference: 'reference' as AddressTypeEnum,
Careaddress: 'careaddress' as AddressTypeEnum,
}
}

0 comments on commit 487e0ab

Please sign in to comment.