-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
198 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,52 @@ | ||
import Resource from '../resource'; | ||
import { StoreActions, isPhone, isEmail } from '../utils'; | ||
|
||
const driverActions = new StoreActions({ | ||
// const { error } = await fleetbase.drivers.login('+1 111-1111'); | ||
login: function (identity, password = null, attributes = {}) { | ||
// handle phone number authentication | ||
if (isPhone(identity)) { | ||
return this.adapter.post('drivers/login-with-sms', { phone: identity }); | ||
} | ||
|
||
if (!password) { | ||
throw new Error('Login requires password!'); | ||
} | ||
|
||
return this.adapter.post('drivers/login', { identity, password, ...attributes }).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
verifyCode: function (identity, code, attributes = {}) { | ||
return this.adapter.post('drivers/verify-code', { identity, code, ...attributes }).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
retrieve: function (id) { | ||
return this.findRecord(id); | ||
}, | ||
}); | ||
|
||
class Driver extends Resource { | ||
constructor(attributes = {}, adapter, options = {}) { | ||
super(attributes, adapter, 'driver', options); | ||
} | ||
|
||
get token() { | ||
return this.getAttribute('token'); | ||
} | ||
|
||
get isOnline() { | ||
return this.getAttribute('online') === true; | ||
} | ||
|
||
syncDevice(token) { | ||
return this.adapter | ||
.setHeaders({ 'Driver-Token': this.token }) | ||
.post('drivers/register-device', token) | ||
.then(() => { | ||
return this; | ||
}); | ||
} | ||
} | ||
|
||
export default Driver; | ||
export { driverActions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,119 @@ | ||
import Resource from '../resource'; | ||
import { StoreActions } from '../utils'; | ||
import { isValid as isValidDate } from 'date-fns'; | ||
|
||
const orderActions = new StoreActions({ | ||
getDistanceAndTime: function (id, options = {}) { | ||
return this.adapter.get(`${this.namespace}/${id}/distance-and-time`, {}, options); | ||
getDistanceAndTime: function (id, params = {}, options = {}) { | ||
return this.adapter.get(`${this.namespace}/${id}/distance-and-time`, params, options); | ||
}, | ||
|
||
getNextActivity: function (id, params = {}, options = {}) { | ||
return this.adapter.get(`${this.namespace}/${id}/next-activity`, params, options); | ||
}, | ||
|
||
dispatch: function (id, params = {}, options = {}) { | ||
return this.adapter.post(`${this.namespace}/${id}/dispatch`, params, options).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
start: function (id,params = {}, options = {}) { | ||
return this.adapter.post(`${this.namespace}/${id}/start`, params, options).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
updateActivity: function (id, params = {}, options = {}) { | ||
return this.adapter.post(`${this.namespace}/${id}/update-activity`, params, options).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
complete: function (id, params = {}, options = {}) { | ||
return this.adapter.post(`${this.namespace}/${id}/complete`, params, options).then(this.afterFetch.bind(this)); | ||
}, | ||
|
||
cancel: function (id, params = {}, options = {}) { | ||
return this.adapter.delete(`${this.namespace}/${id}/cancel`, params, options).then(this.afterFetch.bind(this)); | ||
} | ||
}); | ||
|
||
class Order extends Resource { | ||
constructor(attributes = {}, adapter, options = {}) { | ||
super(attributes, adapter, 'order', { actions: orderActions, ...options }); | ||
} | ||
|
||
getDistanceAndTime() { | ||
return this.store.getDistanceAndTime(this.id); | ||
getDistanceAndTime(params = {}, options = {}) { | ||
return this.store.getDistanceAndTime(this.id, params, options); | ||
} | ||
|
||
dispatch(params = {}, options = {}) { | ||
return this.store.dispatch(this.id, params, options); | ||
} | ||
|
||
start(params = {}, options = {}) { | ||
return this.store.start(this.id, params, options); | ||
} | ||
|
||
getNextActivity(params = {}, options = {}) { | ||
return this.store.getNextActivity(this.id, params, options); | ||
} | ||
|
||
updateActivity(params = {}, options = {}) { | ||
return this.store.updateActivity(this.id, params, options); | ||
} | ||
|
||
cancel(params = {}, options = {}) { | ||
return this.store.cancel(this.id, params, options); | ||
} | ||
|
||
complete(params = {}, options = {}) { | ||
return this.store.complete(this.id, params, options); | ||
} | ||
|
||
get isDispatched() { | ||
return this.getAttribute('dispatched_at') !== null; | ||
} | ||
|
||
get isNotDispatched() { | ||
return this.getAttribute('dispatched_at') == null; | ||
} | ||
|
||
get isStarted() { | ||
return this.getAttribute('started_at') !== null; | ||
} | ||
|
||
get isNotStarted() { | ||
return this.getAttribute('started_at') == null; | ||
} | ||
|
||
get isCompleted() { | ||
return this.getAttribute('status') == 'completed'; | ||
} | ||
|
||
get isCanceled() { | ||
return this.getAttribute('status') == 'canceled'; | ||
} | ||
|
||
get isEnroute() { | ||
return this.getAttribute('status') == 'driver_enroute' || this.getAttribute('status') === 'enroute'; | ||
} | ||
|
||
get isInProgress() { | ||
return this.isStarted && !this.isCanceled && !this.isCompleted; | ||
} | ||
|
||
get scheduledAt() { | ||
return this.isAttributeFilled('scheduled_at') ? new Date(this.getAttribute('scheduled_at')) : null; | ||
} | ||
|
||
get startedAt() { | ||
return this.isAttributeFilled('started_at') ? new Date(this.getAttribute('started_at')) : null; | ||
} | ||
|
||
get dispatchedAt() { | ||
return this.isAttributeFilled('dispatched_at') ? new Date(this.getAttribute('dispatched_at')) : null; | ||
} | ||
|
||
get status() { | ||
return this.getAttribute('status'); | ||
} | ||
} | ||
|
||
export default Order; | ||
|
||
export { orderActions }; | ||
export { orderActions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const isEmail = (email = '') => { | ||
return /\S+@\S+\.\S+/.test(email); | ||
} | ||
|
||
export default isEmail; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const isPhone = (phone = '') => { | ||
return /^[+]?[\s./0-9]*[(]?[0-9]{1,4}[)]?[-\s./0-9]*$/g.test(phone); | ||
} | ||
|
||
export default isPhone; |