-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from fleetbase/dev-v0.1.12
v0.1.12
- Loading branch information
Showing
9 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ import { isArray } from '@ember/array'; | |
import { isBlank } from '@ember/utils'; | ||
import { getOwner } from '@ember/application'; | ||
import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns'; | ||
import groupBy from '@fleetbase/ember-core/utils/macros/group-by'; | ||
import isNotModel from '@fleetbase/ember-core/utils/is-not-model'; | ||
|
||
export default class OrderModel extends Model { | ||
|
@@ -23,12 +22,14 @@ export default class OrderModel extends Model { | |
@attr('string') tracking_number_uuid; | ||
@attr('string') driver_assigned_uuid; | ||
@attr('string') service_quote_uuid; | ||
@attr('string') order_config_uuid; | ||
@attr('string') payload_id; | ||
@attr('string') purchase_rate_id; | ||
@attr('string') driver_id; | ||
|
||
/** @relationships */ | ||
@belongsTo('company') company; | ||
@belongsTo('order-config') order_config; | ||
@belongsTo('customer', { polymorphic: true, async: false }) customer; | ||
@belongsTo('facilitator', { polymorphic: true, async: false }) facilitator; | ||
@belongsTo('transaction', { async: false }) transaction; | ||
|
@@ -37,10 +38,10 @@ export default class OrderModel extends Model { | |
@belongsTo('route', { async: false }) route; | ||
@belongsTo('purchase-rate', { async: false }) purchase_rate; | ||
@belongsTo('tracking-number', { async: false }) tracking_number; | ||
@belongsTo('order-config', { async: false }) order_config; | ||
@hasMany('tracking-status', { async: false }) tracking_statuses; | ||
@hasMany('comment', { async: false }) comments; | ||
@hasMany('file', { async: false }) files; | ||
@hasMany('custom-field-value', { async: false }) custom_field_values; | ||
|
||
/** @aliases */ | ||
@alias('driver_assigned') driver; | ||
|
@@ -101,8 +102,6 @@ export default class OrderModel extends Model { | |
@not('hasPayload') missing_payload; | ||
@bool('dispatched') isDispatched; | ||
@not('dispatched') isNotDispatched; | ||
@equal('type', 'storefront') isStorefrontOrder; | ||
@groupBy('order_config.meta.fields', 'group') groupedMetaFields; | ||
|
||
@computed('payload.{pickup.name,current_waypoint_uui,[email protected]}') | ||
get pickupName() { | ||
|
@@ -411,6 +410,26 @@ export default class OrderModel extends Model { | |
return this; | ||
} | ||
|
||
async persistProperty(key, value, options = {}) { | ||
return this.persistProperties({ [key]: value }, options); | ||
} | ||
|
||
async persistProperties(properties = {}, options = {}) { | ||
const owner = getOwner(this); | ||
const fetch = owner.lookup('service:fetch'); | ||
|
||
this.setProperties(properties); | ||
if (typeof options.onBefore === 'function') { | ||
options.onBefore(this); | ||
} | ||
|
||
return fetch.put(`orders/${this.id}`, properties, { normalizeToEmberData: true, normalizeModelType: 'order' }).then((order) => { | ||
if (typeof options.onAfter === 'function') { | ||
options.onAfter(order); | ||
} | ||
}); | ||
} | ||
|
||
async loadPayload(options = {}) { | ||
const owner = getOwner(this); | ||
const store = owner.lookup('service:store'); | ||
|
@@ -465,18 +484,16 @@ export default class OrderModel extends Model { | |
|
||
async loadOrderConfig(options = {}) { | ||
const owner = getOwner(this); | ||
const fetch = owner.lookup('service:fetch'); | ||
const store = owner.lookup('service:store'); | ||
|
||
if (!isBlank(this.order_config)) { | ||
if (!this.order_config_uuid || !isBlank(this.order_config)) { | ||
return; | ||
} | ||
|
||
return fetch | ||
.get('fleet-ops/order-configs/get-installed', { key: this.type ?? 'default', single: true }, { normalizeToEmberData: true, normalizeModelType: 'order-config', ...options }) | ||
.then((orderConfig) => { | ||
this.set('order_config', orderConfig); | ||
return orderConfig; | ||
}); | ||
return store.findRecord('order-config', this.order_config_uuid, options).then((orderConfig) => { | ||
this.set('order_config', orderConfig); | ||
return orderConfig; | ||
}); | ||
} | ||
|
||
async loadDriver(options = {}) { | ||
|
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,4 @@ | ||
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application'; | ||
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest'; | ||
|
||
export default class OrderConfigSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {} |
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 @@ | ||
export { default } from '@fleetbase/fleetops-data/serializers/order-config'; |
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,24 @@ | ||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'dummy/tests/helpers'; | ||
|
||
module('Unit | Serializer | order config', function (hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function (assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let serializer = store.serializerFor('order-config'); | ||
|
||
assert.ok(serializer); | ||
}); | ||
|
||
test('it serializes records', function (assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let record = store.createRecord('order-config', {}); | ||
|
||
let serializedRecord = record.serialize(); | ||
|
||
assert.ok(serializedRecord); | ||
}); | ||
}); |