@ndustrial/contxt-sdk
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -0,1 +1,5 @@ | ||
## [v0.0.8](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.9) (2018-04-19) | ||
**Added** | ||
- FacilityGroupings#getAllByOrganizationId for getting all facility groupings for a specific organization | ||
## [v0.0.8](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.8) (2018-04-16) | ||
@@ -2,0 +6,0 @@ **Added** |
@@ -14,2 +14,3 @@ <a name="FacilityGroupings"></a> | ||
* [.getAll()](#FacilityGroupings+getAll) ⇒ <code>Promise</code> | ||
* [.getAllByOrganizationId(organizationId)](#FacilityGroupings+getAllByOrganizationId) ⇒ <code>Promise</code> | ||
* [.removeFacility(facilityGroupingId, facilityId)](#FacilityGroupings+removeFacility) ⇒ <code>Promise</code> | ||
@@ -87,3 +88,4 @@ | ||
### contxtSdk.facilities.groupings.getAll() ⇒ <code>Promise</code> | ||
Get a listing of all facility groupings for the user's organization | ||
Get a listing of all facility groupings available to a user. Includes public groupings across | ||
any organization the user has access to and the user's private groupings. | ||
@@ -102,2 +104,25 @@ API Endpoint: '/groupings' | ||
``` | ||
<a name="FacilityGroupings+getAllByOrganizationId"></a> | ||
### contxtSdk.facilities.groupings.getAllByOrganizationId(organizationId) ⇒ <code>Promise</code> | ||
Get a listing of all facility groupings for an organization. Includes public groupings | ||
across that specific organization and the user's private groupings for that organization. | ||
API Endpoint: '/organizations/:organizationId/groupings' | ||
Method: GET | ||
**Kind**: instance method of [<code>FacilityGroupings</code>](#FacilityGroupings) | ||
**Fulfill**: <code>FacilityGrouping[]</code> | ||
**Reject**: <code>Error</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| organizationId | <code>string</code> | UUID corresponding with an organization | | ||
**Example** | ||
```js | ||
contxtSdk.facilites.groupings.getAll() | ||
.then((groupings) => console.log(groupings)) | ||
.catch((err) => console.log(err)); | ||
``` | ||
<a name="FacilityGroupings+removeFacility"></a> | ||
@@ -104,0 +129,0 @@ |
@@ -479,2 +479,14 @@ import axios from 'axios'; | ||
}, { | ||
key: 'getAllByOrganizationId', | ||
value: function getAllByOrganizationId(organizationId) { | ||
if (!organizationId) { | ||
return Promise.reject(new Error("An organization id is required for getting a list of an organization's facility groupings")); | ||
} | ||
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/groupings').then(function (groupings) { | ||
return groupings.map(formatGroupingFromServer); | ||
}); | ||
} | ||
}, { | ||
key: 'removeFacility', | ||
@@ -481,0 +493,0 @@ value: function removeFacility(facilityGroupingId, facilityId) { |
@@ -483,2 +483,14 @@ 'use strict'; | ||
}, { | ||
key: 'getAllByOrganizationId', | ||
value: function getAllByOrganizationId(organizationId) { | ||
if (!organizationId) { | ||
return Promise.reject(new Error("An organization id is required for getting a list of an organization's facility groupings")); | ||
} | ||
return this._request.get(this._baseUrl + '/organizations/' + organizationId + '/groupings').then(function (groupings) { | ||
return groupings.map(formatGroupingFromServer); | ||
}); | ||
} | ||
}, { | ||
key: 'removeFacility', | ||
@@ -485,0 +497,0 @@ value: function removeFacility(facilityGroupingId, facilityId) { |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -132,3 +132,4 @@ import { | ||
/** | ||
* Get a listing of all facility groupings for the user's organization | ||
* Get a listing of all facility groupings available to a user. Includes public groupings across | ||
* any organization the user has access to and the user's private groupings. | ||
* | ||
@@ -153,2 +154,31 @@ * API Endpoint: '/groupings' | ||
/** | ||
* Get a listing of all facility groupings for an organization. Includes public groupings | ||
* across that specific organization and the user's private groupings for that organization. | ||
* | ||
* API Endpoint: '/organizations/:organizationId/groupings' | ||
* Method: GET | ||
* | ||
* @param {string} organizationId UUID corresponding with an organization | ||
* | ||
* @returns {Promise} | ||
* @fulfill {FacilityGrouping[]} | ||
* @reject {Error} | ||
* | ||
* @example | ||
* contxtSdk.facilites.groupings.getAll() | ||
* .then((groupings) => console.log(groupings)) | ||
* .catch((err) => console.log(err)); | ||
*/ | ||
getAllByOrganizationId(organizationId) { | ||
if (!organizationId) { | ||
return Promise.reject( | ||
new Error("An organization id is required for getting a list of an organization's facility groupings") | ||
); | ||
} | ||
return this._request.get(`${this._baseUrl}/organizations/${organizationId}/groupings`) | ||
.then((groupings) => groupings.map(formatGroupingFromServer)); | ||
} | ||
/** | ||
* Removes a facility from a facility grouping | ||
@@ -155,0 +185,0 @@ * |
@@ -104,3 +104,3 @@ import omit from 'lodash.omit'; | ||
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest); | ||
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost); | ||
const promise = facilityGroupings.addFacility( | ||
@@ -208,3 +208,3 @@ groupingFacility.facilityGroupingId, | ||
it('gets a list of facility groupings', function() { | ||
expect(request.get).to.be.calledOnce; | ||
expect(request.get).to.be.calledWith(`${expectedHost}/groupings`); | ||
}); | ||
@@ -227,2 +227,61 @@ | ||
describe('getAllByOrganizationId', function() { | ||
context('when all required information is provided', function() { | ||
let expectedGrouping; | ||
let expectedOrganizationId; | ||
let formatGroupingFromServer; | ||
let groupingsFromServer; | ||
let promise; | ||
let request; | ||
beforeEach(function() { | ||
const numberOfGroupings = faker.random.number({ min: 1, max: 10 }); | ||
expectedGrouping = fixture.buildList('facilityGrouping', numberOfGroupings); | ||
groupingsFromServer = fixture.buildList('facilityGrouping', numberOfGroupings); | ||
expectedOrganizationId = fixture.build('organization').id; | ||
formatGroupingFromServer = this.sandbox.stub(facilitiesUtils, 'formatGroupingFromServer') | ||
.callsFake((grouping, index) => expectedGrouping[index]); | ||
request = { | ||
...baseRequest, | ||
get: this.sandbox.stub().resolves(groupingsFromServer) | ||
}; | ||
const facilityGroupings = new FacilityGroupings(baseSdk, request, expectedHost); | ||
promise = facilityGroupings.getAllByOrganizationId(expectedOrganizationId); | ||
}); | ||
it('gets a list of facility groupings', function() { | ||
expect(request.get).to.be.calledWith( | ||
`${expectedHost}/organizations/${expectedOrganizationId}/groupings` | ||
); | ||
}); | ||
it('formats the list of facility groupings', function() { | ||
return promise.then(() => { | ||
expect(formatGroupingFromServer).to.have.callCount(groupingsFromServer.length); | ||
groupingsFromServer.forEach((grouping) => { | ||
expect(formatGroupingFromServer).to.be.calledWith(grouping); | ||
}); | ||
}); | ||
}); | ||
it('returns a fulfilled promise with the facility groupings', function() { | ||
return expect(promise).to.be.fulfilled | ||
.and.to.eventually.deep.equal(expectedGrouping); | ||
}); | ||
}); | ||
context('when there is missing required information', function() { | ||
it('returns a rejected promise with an error when no organizationId is provided', function() { | ||
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost); | ||
const promise = facilityGroupings.getAllByOrganizationId(); | ||
return expect(promise).to.be.rejectedWith( | ||
`An organization id is required for getting a list of an organization's facility groupings` | ||
); | ||
}); | ||
}); | ||
}); | ||
describe('removeFacility', function() { | ||
@@ -264,3 +323,3 @@ context('when all required information is supplied', function() { | ||
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest); | ||
const facilityGroupings = new FacilityGroupings(baseSdk, baseRequest, expectedHost); | ||
const promise = facilityGroupings.removeFacility( | ||
@@ -267,0 +326,0 @@ groupingFacility.facilityGroupingId, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
495230
6764