Skip to content

Commit

Permalink
Merge pull request #13 from fleetbase/list-organization
Browse files Browse the repository at this point in the history
added switch, list organization methods
  • Loading branch information
doljko authored Feb 15, 2024
2 parents de00c15 + 91736ff commit 008541b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/@fleetbase/sdk.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/@fleetbase/sdk.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/fleetbase.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/fleetbase.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/fleetbase.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/fleetbase.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/sdk",
"version": "1.2.7",
"version": "1.2.8",
"description": "Fleetbase JS & Node SDK",
"main": "dist/cjs/fleetbase.js",
"module": "dist/esm/fleetbase.js",
Expand All @@ -19,7 +19,10 @@
"dev": "rollup -c -w",
"test": "mocha --require @babel/polyfill --require @babel/register --require source-map-support/register tests/*.test.js",
"prepare": "husky install",
"format": "prettier . --write"
"format": "prettier . --write",
"publish-verdaccio": "npm publish --registry http://localhost:4873",
"unpublish-verdaccio": "npm unpublish --registry http://localhost:4873 --force",
"reset-verdaccio": "pnpm unpublish-verdaccio && pnpm publish-verdaccio"
},
"author": "Ronald A. Richardson <[email protected]> (https://ron.dev)",
"license": "BSD-3-Clause",
Expand Down
38 changes: 37 additions & 1 deletion src/resources/driver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import Resource from '../resource';
import { StoreActions, isPhone, isEmail } from '../utils';
import Organization from './organization';
import { StoreActions, isPhone, Collection } from '../utils';
import { isArray } from '../utils/array';

const serializeOrganizations = (response, adapter) => {
if (isArray(response)) {
return response.map((organizationJson) => {
return new Organization(organizationJson, adapter);
});
}

return new Organization(response, adapter);
};

const driverActions = new StoreActions({
// const { error } = await fleetbase.drivers.login('+1 111-1111');
Expand All @@ -24,6 +36,18 @@ const driverActions = new StoreActions({
return this.adapter.post(`drivers/${id}/track`, params, options).then(this.afterFetch.bind(this));
},

listOrganizations: function (id, params = {}, options = {}) {
return this.adapter.get(`drivers/${id}/organizations`, params, options).then((response) => serializeOrganizations(response, this.adapter));
},

switchOrganization: function (id, params = {}, options = {}) {
return this.adapter.post(`drivers/${id}/switch-organization`, params, options).then((response) => serializeOrganizations(response, this.adapter));
},

currentOrganization: function (id, params = {}, options = {}) {
return this.adapter.get(`drivers/${id}/current-organization`, params, options).then((response) => serializeOrganizations(response, this.adapter));
},

retrieve: function (id) {
return this.findRecord(id);
},
Expand Down Expand Up @@ -82,6 +106,18 @@ class Driver extends Resource {
syncDevice(params = {}, options = {}) {
return this.store.syncDevice(this.id, params, options);
}

listOrganizations(params = {}, options = {}) {
return this.store.listOrganizations(this.id, params, options);
}

switchOrganization(organizationId, options = {}) {
return this.store.switchOrganization(this.id, { next: organizationId }, options);
}

currentOrganization(params = {}, options = {}) {
return this.store.currentOrganization(this.id, params, options);
}
}

export default Driver;
Expand Down

0 comments on commit 008541b

Please sign in to comment.