Skip to content

Commit

Permalink
add comments relationship to order model
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jan 31, 2024
1 parent 934cb4d commit b98fde4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
34 changes: 27 additions & 7 deletions addon/models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
});
}
}
4 changes: 2 additions & 2 deletions addon/models/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

module.exports = {
name: require('./package').name,
isDevelopingAddon() {
return true;
},
};

0 comments on commit b98fde4

Please sign in to comment.