From de8e39a85c41c99f75e25d9373e20beb963d2586 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 3 Aug 2021 14:46:40 +0800 Subject: [PATCH] update package version --- .github/stale.yml | 17 +++++++++++++++++ src/fleetbase.js | 3 ++- src/resource.js | 24 +++++++++++++++++++++++- src/resources/order.js | 15 ++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 .github/stale.yml diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..65a2991 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 20 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/src/fleetbase.js b/src/fleetbase.js index 163db8f..7c0d874 100644 --- a/src/fleetbase.js +++ b/src/fleetbase.js @@ -5,6 +5,7 @@ import { BrowserAdapter, NodeAdapter, EmberJsAdapter, Adapter } from './adapters import { isNodeEnvironment, detectAdapter, isLatitude, isLongitude, isResource, GoogleAddress, Collection, StoreActions } from './utils'; import { pluralize, singularize, classify, dasherize, camelize } from './utils/string'; import { extendStoreActions } from './store'; +import { orderActions } from './resources/order'; /** * // instance @@ -57,7 +58,7 @@ export default class Fleetbase { this.adapter = config.adapter || detectAdapter(this.options); - this.orders = new Store('order', this.adapter); + this.orders = new Store('order', this.adapter).extendActions(orderActions); this.entities = new Store('entity', this.adapter); this.places = new Store('place', this.adapter); this.drivers = new Store('driver', this.adapter); diff --git a/src/resource.js b/src/resource.js index 42d6866..be694a2 100644 --- a/src/resource.js +++ b/src/resource.js @@ -195,6 +195,24 @@ class Resource { return this.update(dirtyAttributes); } + /** + * Returns the date instance resource was created. + * + * @return {Date} + */ + get createdAt() { + return this.hasAttribute('created_at') ? new Date(this.getAttribute('created_at')) : null; + } + + /** + * Returns the date instance resource was created. + * + * @return {Date} + */ + get updatedAt() { + return this.hasAttribute('updated_at') ? new Date(this.getAttribute('updated_at')) : null; + } + /** * Checks if resource is loaded from the server. * @@ -371,10 +389,14 @@ class Resource { */ hasAttribute(property) { if (isArray(property)) { - const attributeKeys = Object.keys(this.attributes); + const attributeKeys = Object.keys(this.attributes || {}); return property.every((prop) => attributeKeys.includes(prop)); } + if (!this.attributes) { + return false; + } + return property in this.attributes; } diff --git a/src/resources/order.js b/src/resources/order.js index f3c2bb8..635c96c 100644 --- a/src/resources/order.js +++ b/src/resources/order.js @@ -1,9 +1,22 @@ import Resource from '../resource'; +import { StoreActions } from '../utils'; + +const orderActions = new StoreActions({ + getDistanceAndTime: function (id, options = {}) { + return this.adapter.get(`${this.namespace}/${id}/distance-and-time`, {}, options); + }, +}); class Order extends Resource { constructor(attributes = {}, adapter, options = {}) { - super(attributes, adapter, 'order', options); + super(attributes, adapter, 'order', { actions: orderActions, ...options }); + } + + getDistanceAndTime() { + return this.store.getDistanceAndTime(this.id); } } export default Order; + +export { orderActions }; \ No newline at end of file