Skip to content

Commit

Permalink
chore(frontend/models): add async && inverse to relationship definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Aug 16, 2024
1 parent 4bbce2e commit c8ba396
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 40 deletions.
7 changes: 4 additions & 3 deletions frontend/app/models/absence-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default class AbsenceBalance extends Model {
@attr("number") usedDays;
@attr("django-duration") usedDuration;
@attr("number") balance;
@belongsTo("user") user;
@belongsTo("absence-type") absenceType;
@hasMany("absence-credit") absenceCredits;
@belongsTo("user", { async: true, inverse: "absenceBalances" }) user;
@belongsTo("absence-type", { async: true, inverse: "absenceBalances" })
absenceType;
@hasMany("absence-credit", { async: true, inverse: null }) absenceCredits;
}
4 changes: 2 additions & 2 deletions frontend/app/models/absence-credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export default class AbsenceCredit extends Model {
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type") absenceType;
@belongsTo("absence-type", { async: true, inverse: null }) absenceType;

/**
* The user to which this credit belongs to
*
* @property {User} user
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;
}
3 changes: 2 additions & 1 deletion frontend/app/models/absence-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export default class AbsenceType extends Model {
* @property {AbsenceBalance[]} absenceBalances
* @public
*/
@hasMany("absence-balance") absenceBalances;
@hasMany("absence-balance", { async: true, inverse: "absenceType" })
absenceBalances;
}
4 changes: 2 additions & 2 deletions frontend/app/models/absence.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export default class Absence extends Model {
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type") absenceType;
@belongsTo("absence-type", { async: true, inverse: null }) absenceType;

/**
* The user
*
* @property {User} user
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;
}
4 changes: 2 additions & 2 deletions frontend/app/models/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default class Activity extends Model {
@attr("boolean", { defaultValue: false }) transferred;
@attr("boolean", { defaultValue: false }) review;
@attr("boolean", { defaultValue: false }) notBillable;
@belongsTo("task") task;
@belongsTo("user") user;
@belongsTo("task", { async: true, inverse: null }) task;
@belongsTo("user", { async: true, inverse: null }) user;

@service notify;
@service store;
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/models/attendance.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Attendance extends Model {
* @type {User}
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;

/**
* The duration between start and end time
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/models/customer-assignee.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default class CustomerAssignee extends Model {
* @type {Customer}
* @public
*/
@belongsTo("customer") customer;
@belongsTo("customer", { async: true, inverse: null }) customer;
/**
* The user
*
* @property user
* @type {User}
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;

/**
* Whether the assignee is a reviewer
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/models/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Customer extends Model {
* @type {Project[]}
* @public
*/
@hasMany("project") projects;
@hasMany("project", { async: true, inverse: "customer" }) projects;

/**
* Long name - alias for name, used for filtering in the customer box
Expand All @@ -57,5 +57,5 @@ export default class Customer extends Model {
* @type {CustomerAssignee[]}
* @public
*/
@hasMany("customer-assignee") assignees;
@hasMany("customer-assignee", { async: true, inverse: null }) assignees;
}
4 changes: 2 additions & 2 deletions frontend/app/models/employment.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export default class Employment extends Model {
* @property {User} user
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: "employments" }) user;

/**
* The work location
*
* @property {Location} location
* @public
*/
@belongsTo("location") location;
@belongsTo("location", { async: true, inverse: null }) location;
}
2 changes: 1 addition & 1 deletion frontend/app/models/overtime-credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default class OvertimeCredit extends Model {
@attr("django-date") date;
@attr("django-duration") duration;
@attr("string", { defaultValue: "" }) comment;
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;
}
4 changes: 2 additions & 2 deletions frontend/app/models/project-assignee.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class ProjectAssignee extends Model {
* @type {Project}
* @public
*/
@belongsTo("project") project;
@belongsTo("project", { async: true, inverse: null }) project;

/**
* The user
Expand All @@ -29,7 +29,7 @@ export default class ProjectAssignee extends Model {
* @type {User}
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;

/**
* Whether the assignee is a reviewer
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class Project extends Model {
* @type {Customer}
* @public
*/
@belongsTo("customer") customer;
@belongsTo("customer", { async: true, inverse: "projects" }) customer;

/**
* Whether the project's comments are visible to the customer
Expand All @@ -78,7 +78,7 @@ export default class Project extends Model {
* @property {BillingType} billingType
* @public
*/
@belongsTo("billing-type") billingType;
@belongsTo("billing-type", { async: true, inverse: null }) billingType;

/**
* The tasks
Expand All @@ -87,7 +87,7 @@ export default class Project extends Model {
* @type {Task[]}
* @public
*/
@hasMany("task") tasks;
@hasMany("task", { async: true, inverse: "project" }) tasks;

/**
* Assigned users to this project
Expand All @@ -96,5 +96,5 @@ export default class Project extends Model {
* @type {ProjectAssignee[]}
* @public
*/
@hasMany("project-assignee") assignees;
@hasMany("project-assignee", { async: true, inverse: null }) assignees;
}
2 changes: 1 addition & 1 deletion frontend/app/models/public-holiday.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export default class PublicHoliday extends Model {
* @property {Location} location
* @public
*/
@belongsTo("location") location;
@belongsTo("location", { async: true, inverse: null }) location;
}
6 changes: 3 additions & 3 deletions frontend/app/models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ export default class Report extends Model {
* @property {Task} task
* @public
*/
@belongsTo("task") task;
@belongsTo("task", { async: true, inverse: null }) task;

/**
* The user
*
* @property {User} user
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;

/**
* The user which verified this report
*
* @property {User} verifiedBy
* @public
*/
@belongsTo("user") verifiedBy;
@belongsTo("user", { async: true, inverse: null }) verifiedBy;
}
4 changes: 2 additions & 2 deletions frontend/app/models/task-assignee.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default class TaskAssignee extends Model {
* @type {Task}
* @public
*/
@belongsTo("task") task;
@belongsTo("task", { async: true, inverse: "assignees" }) task;
/**
* The user
*
* @property user
* @type {User}
* @public
*/
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;

/**
* Whether the assignee is a reviewer
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/models/task-statistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default class TaskStatistics extends Model {
@attr("django-duration") duration;
@attr("django-duration") estimatedTime;
@attr("django-duration") mostRecentRemainingEffort;
@belongsTo("project") project;
@belongsTo("project", { async: true, inverse: null }) project;
}
12 changes: 10 additions & 2 deletions frontend/app/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export default class Task extends Model {
@attr("boolean", { defaultValue: false }) archived;
@attr("string", { defaultValue: "" }) reference;

@belongsTo("project") project;
@hasMany("task-assignee") assignees;
@belongsTo("project", {
async: true,
inverse: "tasks",
})
project;
@hasMany("task-assignee", {
async: true,
inverse: "task",
})
assignees;

/**
* Flag saying that this is a task.
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/models/user-statistic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Model, { attr, belongsTo } from "@ember-data/model";
export default class UserStatistic extends Model {
@attr("django-duration") duration;

@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: null }) user;
}
11 changes: 6 additions & 5 deletions frontend/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,40 @@ export default class User extends Model {
* @property {User[]} supervisors
* @public
*/
@hasMany("user", { inverse: "supervisees" }) supervisors;
@hasMany("user", { inverse: "supervisees", async: true }) supervisors;

/**
* The users supervisees
*
* @property {User[]} supervisees
* @public
*/
@hasMany("user", { inverse: "supervisors" }) supervisees;
@hasMany("user", { inverse: "supervisors", async: true }) supervisees;

/**
* The users employments
*
* @property {Employment[]} employments
* @public
*/
@hasMany("employment") employments;
@hasMany("employment", { async: true, inverse: "user" }) employments;

/**
* The users worktime balances
*
* @property {WorktimeBalance[]} worktimeBalances
* @public
*/
@hasMany("worktime-balances") worktimeBalances;
@hasMany("worktime-balances", { async: true, inverse: "user" })
worktimeBalances;

/**
* The users absence balances
*
* @property {AbsenceBalance[]} absenceBalances
* @public
*/
@hasMany("absence-balance") absenceBalances;
@hasMany("absence-balance", { async: true, inverse: "user" }) absenceBalances;

/**
* The full name
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/models/worktime-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Model, { attr, belongsTo } from "@ember-data/model";
export default class WorktimeBalance extends Model {
@attr("django-date") date;
@attr("django-duration") balance;
@belongsTo("user") user;
@belongsTo("user", { async: true, inverse: "worktimeBalances" }) user;
}

0 comments on commit c8ba396

Please sign in to comment.