From b98fde4f29708d7b69f6433c95f2b167b10b1505 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Wed, 31 Jan 2024 20:35:34 +0800 Subject: [PATCH] add comments relationship to order model --- addon/models/driver.js | 2 +- addon/models/order.js | 34 +++++++++++++++++++++++++++------- addon/models/vehicle.js | 4 ++-- index.js | 3 +++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/addon/models/driver.js b/addon/models/driver.js index 24ceeb2..e5ebcbc 100644 --- a/addon/models/driver.js +++ b/addon/models/driver.js @@ -195,7 +195,7 @@ export default class DriverModel extends Model { loadVendor() { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); return new Promise((resolve, reject) => { if (isRelationMissing(this, 'vendor')) { diff --git a/addon/models/order.js b/addon/models/order.js index a3b5996..9307bbb 100644 --- a/addon/models/order.js +++ b/addon/models/order.js @@ -39,6 +39,7 @@ export default class OrderModel extends Model { @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; /** @aliases */ @alias('driver_assigned') driver; @@ -56,6 +57,7 @@ export default class OrderModel extends Model { @attr('string') created_by_name; @attr('string') updated_by_name; @attr('string') pod_method; + @attr('string') notes; @attr('string') type; @attr('string') status; @attr('number') adhoc_distance; @@ -410,7 +412,7 @@ export default class OrderModel extends Model { async loadPayload(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.payload_uuid || !isBlank(this.payload)) { return; @@ -434,7 +436,7 @@ export default class OrderModel extends Model { async loadCustomer(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.customer_uuid || !isBlank(this.customer)) { return; @@ -448,7 +450,7 @@ export default class OrderModel extends Model { async loadPurchaseRate(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.purchase_rate_uuid || !isBlank(this.purchase_rate)) { return; @@ -462,7 +464,7 @@ export default class OrderModel extends Model { async loadOrderConfig(options = {}) { const owner = getOwner(this); - const fetch = owner.lookup(`service:fetch`); + const fetch = owner.lookup('service:fetch'); if (!isBlank(this.order_config)) { return; @@ -478,7 +480,7 @@ export default class OrderModel extends Model { async loadDriver(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.driver_assigned_uuid || !isBlank(this.driver_assigned)) { return; @@ -492,7 +494,7 @@ export default class OrderModel extends Model { async loadTrackingNumber(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.tracking_number_uuid || !isBlank(this.tracking_number)) { return; @@ -506,7 +508,7 @@ export default class OrderModel extends Model { async loadTrackingActivity(options = {}) { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); if (!this.tracking_number_uuid) { return; @@ -525,4 +527,22 @@ export default class OrderModel extends Model { return activity; }); } + + async loadComments(options = {}) { + const owner = getOwner(this); + const store = owner.lookup('service:store'); + + return store + .query( + 'comment', + { + subject_uuid: this.id, + }, + options + ) + .then((comments) => { + this.set('comments', comments); + return comments; + }); + } } diff --git a/addon/models/vehicle.js b/addon/models/vehicle.js index eacc9f5..5f1d900 100644 --- a/addon/models/vehicle.js +++ b/addon/models/vehicle.js @@ -102,7 +102,7 @@ export default class VehicleModel extends Model { /** @methods */ loadDriver() { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); return new Promise((resolve) => { if (isRelationMissing(this, 'driver')) { @@ -123,7 +123,7 @@ export default class VehicleModel extends Model { } loadDevices() { const owner = getOwner(this); - const store = owner.lookup(`service:store`); + const store = owner.lookup('service:store'); return new Promise((resolve, reject) => { return store diff --git a/index.js b/index.js index 10ecd1c..de4730f 100644 --- a/index.js +++ b/index.js @@ -2,4 +2,7 @@ module.exports = { name: require('./package').name, + isDevelopingAddon() { + return true; + }, };