@ndustrial/contxt-sdk
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -0,1 +1,9 @@ | ||
## [v0.0.8](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.8) (2018-04-16) | ||
**Added** | ||
- Added some methods to help out when working with facility groupings. They are namespaced under facilities (i.e. `facilities.groupings.methodName()`) and include: | ||
- FacilityGroupings#addFacility to add a facility to a facility grouping | ||
- FacilityGroupings#create for creating new facility groupings | ||
- FacilityGroupings#getAll for getting a list of all facility groupings | ||
- FacilityGroupings#removeFacility to remove a facility from a facility grouping | ||
## [v0.0.7](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.7) (2018-03-29) | ||
@@ -2,0 +10,0 @@ **Renamed** |
@@ -11,3 +11,3 @@ <a name="Facilities"></a> | ||
* [new Facilities(sdk, request)](#new_Facilities_new) | ||
* [.create(options)](#Facilities+create) ⇒ <code>Promise</code> | ||
* [.create(facility)](#Facilities+create) ⇒ <code>Promise</code> | ||
* [.createOrUpdateInfo(facilityId, update)](#Facilities+createOrUpdateInfo) ⇒ <code>Promise</code> | ||
@@ -31,3 +31,3 @@ * [.delete(facilityId)](#Facilities+delete) ⇒ <code>Promise</code> | ||
### contxtSdk.facilities.create(options) ⇒ <code>Promise</code> | ||
### contxtSdk.facilities.create(facility) ⇒ <code>Promise</code> | ||
Creates a new facility | ||
@@ -44,13 +44,13 @@ | ||
| --- | --- | --- | | ||
| options | <code>Object</code> | | | ||
| [options.address1] | <code>string</code> | | | ||
| [options.address2] | <code>string</code> | | | ||
| [options.city] | <code>string</code> | | | ||
| [options.geometryId] | <code>string</code> | UUID corresponding with a geometry | | ||
| options.name | <code>string</code> | | | ||
| options.organizationId | <code>string</code> | UUID corresponding with an organization | | ||
| [options.state] | <code>string</code> | | | ||
| options.timezone | <code>string</code> | | | ||
| [options.weatherLocationId] | <code>number</code> | | | ||
| [options.zip] | <code>string</code> | | | ||
| facility | <code>Object</code> | | | ||
| [facility.address1] | <code>string</code> | | | ||
| [facility.address2] | <code>string</code> | | | ||
| [facility.city] | <code>string</code> | | | ||
| [facility.geometryId] | <code>string</code> | UUID corresponding with a geometry | | ||
| facility.name | <code>string</code> | | | ||
| facility.organizationId | <code>string</code> | UUID corresponding with an organization | | ||
| [facility.state] | <code>string</code> | | | ||
| facility.timezone | <code>string</code> | | | ||
| [facility.weatherLocationId] | <code>number</code> | | | ||
| [facility.zip] | <code>string</code> | | | ||
@@ -57,0 +57,0 @@ **Example** |
@@ -23,2 +23,6 @@ ## Classes | ||
</dd> | ||
<dt><a href="./FacilityGroupings.md">FacilityGroupings</a></dt> | ||
<dd><p>Module that provides access to facility groupings, and helps manage | ||
the relationship between those groupings and facilities</p> | ||
</dd> | ||
<dt><a href="./MachineAuth.md">MachineAuth</a> : <code><a href="./Typedefs.md#SessionType">SessionType</a></code></dt> | ||
@@ -56,2 +60,6 @@ <dd><p>A SessionType that allows machine to machine communication between Node.js servers. This would | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityGrouping">FacilityGrouping</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#FacilityGroupingFacility">FacilityGroupingFacility</a> : <code>Object</code></dt> | ||
<dd></dd> | ||
<dt><a href="./Typedefs.md#MachineAuthSessionInfo">MachineAuthSessionInfo</a> : <code>Object</code></dt> | ||
@@ -58,0 +66,0 @@ <dd></dd> |
@@ -75,16 +75,16 @@ <a name="Audience"></a> | ||
| id | <code>number</code> | | | ||
| Info | <code>Object</code> | User declared information | | ||
| [Info] | <code>Object</code> | User declared information | | ||
| name | <code>string</code> | | | ||
| Organization | <code>Object</code> | | | ||
| Organization.createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| Organization.id | <code>string</code> | UUID formatted id | | ||
| Organization.name | <code>string</code> | | | ||
| Organization.updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [Organization] | <code>Object</code> | | | ||
| [Organization.createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [Organization.id] | <code>string</code> | UUID formatted id | | ||
| [Organization.name] | <code>string</code> | | | ||
| [Organization.updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| state | <code>string</code> | | | ||
| tags | <code>Array.<Object></code> | | | ||
| tags[].createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| tags[].id | <code>number</code> | | | ||
| tags[].facilityId | <code>number</code> | | | ||
| tags[].name | <code>string</code> | | | ||
| tags[].updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [tags] | <code>Array.<Object></code> | | | ||
| [tags[].createdAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| [tags[].id] | <code>number</code> | | | ||
| [tags[].facilityId] | <code>number</code> | | | ||
| [tags[].name] | <code>string</code> | | | ||
| [tags[].updatedAt] | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| timezone | <code>string</code> | An IANA Time Zone Database string, i.e. America/Los_Angeles | | ||
@@ -94,2 +94,33 @@ | weatherLocationId | <code>number</code> | | | ||
<a name="FacilityGrouping"></a> | ||
## FacilityGrouping : <code>Object</code> | ||
**Kind**: global typedef | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| description | <code>string</code> | | | ||
| [facilities] | [<code>Array.<Facility></code>](#Facility) | | | ||
| id | <code>string</code> | UUID | | ||
| isPrivate | <code>boolean</code> | | | ||
| name | <code>string</code> | | | ||
| organizationId | <code>string</code> | UUID | | ||
| ownerId | <code>string</code> | Auth0 identifer of the user | | ||
| parentGroupingId | <code>string</code> | UUID | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
<a name="FacilityGroupingFacility"></a> | ||
## FacilityGroupingFacility : <code>Object</code> | ||
**Kind**: global typedef | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| createdAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
| facilityGroupingId | <code>string</code> | UUID | | ||
| facilityId | <code>number</code> | | | ||
| id | <code>string</code> | UUID | | ||
| updatedAt | <code>string</code> | ISO 8601 Extended Format date/time string | | ||
<a name="MachineAuthSessionInfo"></a> | ||
@@ -96,0 +127,0 @@ |
303
es/index.js
@@ -295,2 +295,206 @@ import axios from 'axios'; | ||
function formatFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var facility = { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
createdAt: input.created_at, | ||
geometryId: input.geometry_id, | ||
id: input.id, | ||
name: input.name, | ||
organizationId: input.organization_id, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weatherLocationId: input.weather_location_id, | ||
zip: input.zip | ||
}; | ||
if (input.Info) { | ||
facility.info = input.Info; | ||
} | ||
if (input.Organization) { | ||
facility.organization = formatOrganizationFromServer(input.Organization); | ||
} | ||
if (input.tags) { | ||
facility.tags = formatTagsFromServer(input.tags); | ||
} | ||
return facility; | ||
} | ||
function formatFacilityToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
geometry_id: input.geometryId, | ||
Info: input.info, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weather_location_id: input.weatherLocationId, | ||
zip: input.zip | ||
}; | ||
} | ||
function formatGroupingFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
facilityGroupingId: input.facility_grouping_id, | ||
facilityId: input.facility_id, | ||
id: input.id, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
function formatGroupingFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var grouping = { | ||
createdAt: input.created_at, | ||
description: input.description, | ||
id: input.id, | ||
isPrivate: input.is_private, | ||
name: input.name, | ||
organizationId: input.organization_id, | ||
ownerId: input.owner_id, | ||
parentGroupingId: input.parent_grouping_id, | ||
updatedAt: input.updated_at | ||
}; | ||
if (input.facilities) { | ||
grouping.facilities = input.facilities.map(formatFacilityFromServer); | ||
} | ||
return grouping; | ||
} | ||
function formatGroupingToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
description: input.description, | ||
is_private: input.isPrivate, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
owner_id: input.ownerId, | ||
parent_grouping_id: input.parentGroupingId | ||
}; | ||
} | ||
function formatOrganizationFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
id: input.id, | ||
name: input.name, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
function formatTagsFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return input.map(function (tag) { | ||
return { | ||
createdAt: tag.created_at, | ||
facilityId: tag.facility_id, | ||
id: tag.id, | ||
name: tag.name, | ||
updatedAt: tag.updated_at | ||
}; | ||
}); | ||
} | ||
var FacilityGroupings = function () { | ||
function FacilityGroupings(sdk, request, baseUrl) { | ||
classCallCheck(this, FacilityGroupings); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(FacilityGroupings, [{ | ||
key: 'addFacility', | ||
value: function addFacility(facilityGroupingId, facilityId) { | ||
var errorMsg = void 0; | ||
if (!facilityGroupingId) { | ||
errorMsg = 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.'; | ||
} else if (!facilityId) { | ||
errorMsg = 'A facilityId is required to create a relationship between a facility grouping and a facility.'; | ||
} | ||
if (errorMsg) { | ||
return Promise.reject(new Error(errorMsg)); | ||
} | ||
return this._request.post(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId).then(function (groupingFacility) { | ||
return formatGroupingFacilityFromServer(groupingFacility); | ||
}); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create() { | ||
var grouping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var requiredFields = ['name', 'organizationId']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!grouping[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to create a new facility grouping.')); | ||
} | ||
} | ||
var data = formatGroupingToServer(grouping); | ||
return this._request.post(this._baseUrl + '/groupings', data).then(function (grouping) { | ||
return formatGroupingFromServer(grouping); | ||
}); | ||
} | ||
}, { | ||
key: 'getAll', | ||
value: function getAll() { | ||
return this._request.get(this._baseUrl + '/groupings').then(function (groupings) { | ||
return groupings.map(formatGroupingFromServer); | ||
}); | ||
} | ||
}, { | ||
key: 'removeFacility', | ||
value: function removeFacility(facilityGroupingId, facilityId) { | ||
var errorMsg = void 0; | ||
if (!facilityGroupingId) { | ||
errorMsg = 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.'; | ||
} else if (!facilityId) { | ||
errorMsg = 'A facilityId is required to remove a relationship between a facility grouping and a facility.'; | ||
} | ||
if (errorMsg) { | ||
return Promise.reject(new Error(errorMsg)); | ||
} | ||
return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId); | ||
} | ||
}]); | ||
return FacilityGroupings; | ||
}(); | ||
var Facilities = function () { | ||
@@ -301,5 +505,9 @@ | ||
this._baseUrl = sdk.config.audiences.facilities.host + '/v1'; | ||
var baseUrl = sdk.config.audiences.facilities.host + '/v1'; | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
this.groupings = new FacilityGroupings(sdk, request, baseUrl); | ||
} | ||
@@ -310,4 +518,2 @@ | ||
value: function create() { | ||
var _this = this; | ||
var facility = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -325,6 +531,6 @@ | ||
var data = this._formatFacilityToServer(facility); | ||
var data = formatFacilityToServer(facility); | ||
return this._request.post(this._baseUrl + '/facilities', data).then(function (facility) { | ||
return _this._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -370,4 +576,2 @@ } | ||
value: function get$$1(facilityId) { | ||
var _this2 = this; | ||
if (!facilityId) { | ||
@@ -378,3 +582,3 @@ return Promise.reject(new Error('A facility id is required for getting information about a facility')); | ||
return this._request.get(this._baseUrl + '/facilities/' + facilityId).then(function (facility) { | ||
return _this2._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -386,7 +590,5 @@ } | ||
value: function getAll() { | ||
var _this3 = this; | ||
return this._request.get(this._baseUrl + '/facilities').then(function (facilities) { | ||
return facilities.map(function (facility) { | ||
return _this3._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -399,4 +601,2 @@ }); | ||
value: function getAllByOrganizationId(organizationId) { | ||
var _this4 = this; | ||
if (!organizationId) { | ||
@@ -408,3 +608,3 @@ return Promise.reject(new Error("An organization id is required for getting a list of an organization's facilities")); | ||
return facilities.map(function (facility) { | ||
return _this4._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -429,79 +629,6 @@ }); | ||
var formattedUpdate = this._formatFacilityToServer(_update); | ||
var formattedUpdate = formatFacilityToServer(_update); | ||
return this._request.put(this._baseUrl + '/facilities/' + facilityId, formattedUpdate); | ||
} | ||
}, { | ||
key: '_formatFacilityFromServer', | ||
value: function _formatFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
createdAt: input.created_at, | ||
geometryId: input.geometry_id, | ||
id: input.id, | ||
info: input.Info, | ||
name: input.name, | ||
organization: this._formatOrganizationFromServer(input.Organization), | ||
organizationId: input.organization_id, | ||
state: input.state, | ||
tags: this._formatTagsFromServer(input.tags), | ||
timezone: input.timezone, | ||
weatherLocationId: input.weather_location_id, | ||
zip: input.zip | ||
}; | ||
} | ||
}, { | ||
key: '_formatFacilityToServer', | ||
value: function _formatFacilityToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
geometry_id: input.geometryId, | ||
Info: input.info, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weather_location_id: input.weatherLocationId, | ||
zip: input.zip | ||
}; | ||
} | ||
}, { | ||
key: '_formatOrganizationFromServer', | ||
value: function _formatOrganizationFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
id: input.id, | ||
name: input.name, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
}, { | ||
key: '_formatTagsFromServer', | ||
value: function _formatTagsFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return input.map(function (tag) { | ||
return { | ||
createdAt: tag.created_at, | ||
facilityId: tag.facility_id, | ||
id: tag.id, | ||
name: tag.name, | ||
updatedAt: tag.updated_at | ||
}; | ||
}); | ||
} | ||
}]); | ||
@@ -508,0 +635,0 @@ return Facilities; |
303
lib/index.js
@@ -299,2 +299,206 @@ 'use strict'; | ||
function formatFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var facility = { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
createdAt: input.created_at, | ||
geometryId: input.geometry_id, | ||
id: input.id, | ||
name: input.name, | ||
organizationId: input.organization_id, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weatherLocationId: input.weather_location_id, | ||
zip: input.zip | ||
}; | ||
if (input.Info) { | ||
facility.info = input.Info; | ||
} | ||
if (input.Organization) { | ||
facility.organization = formatOrganizationFromServer(input.Organization); | ||
} | ||
if (input.tags) { | ||
facility.tags = formatTagsFromServer(input.tags); | ||
} | ||
return facility; | ||
} | ||
function formatFacilityToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
geometry_id: input.geometryId, | ||
Info: input.info, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weather_location_id: input.weatherLocationId, | ||
zip: input.zip | ||
}; | ||
} | ||
function formatGroupingFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
facilityGroupingId: input.facility_grouping_id, | ||
facilityId: input.facility_id, | ||
id: input.id, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
function formatGroupingFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var grouping = { | ||
createdAt: input.created_at, | ||
description: input.description, | ||
id: input.id, | ||
isPrivate: input.is_private, | ||
name: input.name, | ||
organizationId: input.organization_id, | ||
ownerId: input.owner_id, | ||
parentGroupingId: input.parent_grouping_id, | ||
updatedAt: input.updated_at | ||
}; | ||
if (input.facilities) { | ||
grouping.facilities = input.facilities.map(formatFacilityFromServer); | ||
} | ||
return grouping; | ||
} | ||
function formatGroupingToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
description: input.description, | ||
is_private: input.isPrivate, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
owner_id: input.ownerId, | ||
parent_grouping_id: input.parentGroupingId | ||
}; | ||
} | ||
function formatOrganizationFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
id: input.id, | ||
name: input.name, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
function formatTagsFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return input.map(function (tag) { | ||
return { | ||
createdAt: tag.created_at, | ||
facilityId: tag.facility_id, | ||
id: tag.id, | ||
name: tag.name, | ||
updatedAt: tag.updated_at | ||
}; | ||
}); | ||
} | ||
var FacilityGroupings = function () { | ||
function FacilityGroupings(sdk, request, baseUrl) { | ||
classCallCheck(this, FacilityGroupings); | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
} | ||
createClass(FacilityGroupings, [{ | ||
key: 'addFacility', | ||
value: function addFacility(facilityGroupingId, facilityId) { | ||
var errorMsg = void 0; | ||
if (!facilityGroupingId) { | ||
errorMsg = 'A facilityGroupingId is required to create a relationship between a facility grouping and a facility.'; | ||
} else if (!facilityId) { | ||
errorMsg = 'A facilityId is required to create a relationship between a facility grouping and a facility.'; | ||
} | ||
if (errorMsg) { | ||
return Promise.reject(new Error(errorMsg)); | ||
} | ||
return this._request.post(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId).then(function (groupingFacility) { | ||
return formatGroupingFacilityFromServer(groupingFacility); | ||
}); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create() { | ||
var grouping = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var requiredFields = ['name', 'organizationId']; | ||
for (var i = 0; requiredFields.length > i; i++) { | ||
var field = requiredFields[i]; | ||
if (!grouping[field]) { | ||
return Promise.reject(new Error('A ' + field + ' is required to create a new facility grouping.')); | ||
} | ||
} | ||
var data = formatGroupingToServer(grouping); | ||
return this._request.post(this._baseUrl + '/groupings', data).then(function (grouping) { | ||
return formatGroupingFromServer(grouping); | ||
}); | ||
} | ||
}, { | ||
key: 'getAll', | ||
value: function getAll() { | ||
return this._request.get(this._baseUrl + '/groupings').then(function (groupings) { | ||
return groupings.map(formatGroupingFromServer); | ||
}); | ||
} | ||
}, { | ||
key: 'removeFacility', | ||
value: function removeFacility(facilityGroupingId, facilityId) { | ||
var errorMsg = void 0; | ||
if (!facilityGroupingId) { | ||
errorMsg = 'A facilityGroupingId is required to remove a relationship between a facility grouping and a facility.'; | ||
} else if (!facilityId) { | ||
errorMsg = 'A facilityId is required to remove a relationship between a facility grouping and a facility.'; | ||
} | ||
if (errorMsg) { | ||
return Promise.reject(new Error(errorMsg)); | ||
} | ||
return this._request.delete(this._baseUrl + '/groupings/' + facilityGroupingId + '/facility/' + facilityId); | ||
} | ||
}]); | ||
return FacilityGroupings; | ||
}(); | ||
var Facilities = function () { | ||
@@ -305,5 +509,9 @@ | ||
this._baseUrl = sdk.config.audiences.facilities.host + '/v1'; | ||
var baseUrl = sdk.config.audiences.facilities.host + '/v1'; | ||
this._baseUrl = baseUrl; | ||
this._request = request; | ||
this._sdk = sdk; | ||
this.groupings = new FacilityGroupings(sdk, request, baseUrl); | ||
} | ||
@@ -314,4 +522,2 @@ | ||
value: function create() { | ||
var _this = this; | ||
var facility = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -329,6 +535,6 @@ | ||
var data = this._formatFacilityToServer(facility); | ||
var data = formatFacilityToServer(facility); | ||
return this._request.post(this._baseUrl + '/facilities', data).then(function (facility) { | ||
return _this._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -374,4 +580,2 @@ } | ||
value: function get$$1(facilityId) { | ||
var _this2 = this; | ||
if (!facilityId) { | ||
@@ -382,3 +586,3 @@ return Promise.reject(new Error('A facility id is required for getting information about a facility')); | ||
return this._request.get(this._baseUrl + '/facilities/' + facilityId).then(function (facility) { | ||
return _this2._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -390,7 +594,5 @@ } | ||
value: function getAll() { | ||
var _this3 = this; | ||
return this._request.get(this._baseUrl + '/facilities').then(function (facilities) { | ||
return facilities.map(function (facility) { | ||
return _this3._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -403,4 +605,2 @@ }); | ||
value: function getAllByOrganizationId(organizationId) { | ||
var _this4 = this; | ||
if (!organizationId) { | ||
@@ -412,3 +612,3 @@ return Promise.reject(new Error("An organization id is required for getting a list of an organization's facilities")); | ||
return facilities.map(function (facility) { | ||
return _this4._formatFacilityFromServer(facility); | ||
return formatFacilityFromServer(facility); | ||
}); | ||
@@ -433,79 +633,6 @@ }); | ||
var formattedUpdate = this._formatFacilityToServer(_update); | ||
var formattedUpdate = formatFacilityToServer(_update); | ||
return this._request.put(this._baseUrl + '/facilities/' + facilityId, formattedUpdate); | ||
} | ||
}, { | ||
key: '_formatFacilityFromServer', | ||
value: function _formatFacilityFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
createdAt: input.created_at, | ||
geometryId: input.geometry_id, | ||
id: input.id, | ||
info: input.Info, | ||
name: input.name, | ||
organization: this._formatOrganizationFromServer(input.Organization), | ||
organizationId: input.organization_id, | ||
state: input.state, | ||
tags: this._formatTagsFromServer(input.tags), | ||
timezone: input.timezone, | ||
weatherLocationId: input.weather_location_id, | ||
zip: input.zip | ||
}; | ||
} | ||
}, { | ||
key: '_formatFacilityToServer', | ||
value: function _formatFacilityToServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
address1: input.address1, | ||
address2: input.address2, | ||
city: input.city, | ||
geometry_id: input.geometryId, | ||
Info: input.info, | ||
name: input.name, | ||
organization_id: input.organizationId, | ||
state: input.state, | ||
timezone: input.timezone, | ||
weather_location_id: input.weatherLocationId, | ||
zip: input.zip | ||
}; | ||
} | ||
}, { | ||
key: '_formatOrganizationFromServer', | ||
value: function _formatOrganizationFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return { | ||
createdAt: input.created_at, | ||
id: input.id, | ||
name: input.name, | ||
updatedAt: input.updated_at | ||
}; | ||
} | ||
}, { | ||
key: '_formatTagsFromServer', | ||
value: function _formatTagsFromServer() { | ||
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return input.map(function (tag) { | ||
return { | ||
createdAt: tag.created_at, | ||
facilityId: tag.facility_id, | ||
id: tag.id, | ||
name: tag.name, | ||
updatedAt: tag.updated_at | ||
}; | ||
}); | ||
} | ||
}]); | ||
@@ -512,0 +639,0 @@ return Facilities; |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
# contxt-sdk | ||
# contxt-sdk [![wercker status](https://app.wercker.com/status/869ef086297da79ddd0cbf3564f7cba6/s/master "wercker status")](https://app.wercker.com/project/byKey/869ef086297da79ddd0cbf3564f7cba6) | ||
@@ -3,0 +3,0 @@ ## Installation |
@@ -8,2 +8,4 @@ 'use strict'; | ||
require('./facility'); | ||
require('./facilityGrouping'); | ||
require('./facilityGroupingFacility'); | ||
require('./facilityInfo'); | ||
@@ -10,0 +12,0 @@ require('./facilityTag'); |
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
486717
73
6666