Skip to content

Commit

Permalink
refactor(frontend): convert models, services, transforms, adapters an…
Browse files Browse the repository at this point in the history
…d serializers to typescript
  • Loading branch information
c0rydoras committed Sep 20, 2024
1 parent e7970af commit 905c5b1
Show file tree
Hide file tree
Showing 62 changed files with 1,014 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ export default class ActivityBlockAdapter extends ApplicationAdapter {
return `${super.urlForCreateRecord(...args)}?include=activity`;
}
}

declare module "ember-data/types/registries/adapter" {
export default interface AdapterRegistry {
"activity-block": ActivityBlockAdapter;
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions frontend/app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: 'history' | 'hash' | 'none';
locationType: "history" | "hash" | "none";
rootURL: string;
APP: Record<string, unknown>;
};

export default config;
export default config;
12 changes: 0 additions & 12 deletions frontend/app/models/absence-balance.js

This file was deleted.

29 changes: 29 additions & 0 deletions frontend/app/models/absence-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { AsyncHasMany } from "@ember-data/model";
import Model, { attr, belongsTo, hasMany } from "@ember-data/model";
import type { Duration } from "moment";
import type AbsenceCredit from "timed/models/absence-credit";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";

export default class AbsenceBalance extends Model {
@attr("number")
declare credit?: number;
@attr("number")
declare usedDays?: number;
@attr("django-duration")
declare usedDuration?: Duration;
@attr("number")
declare balance?: number;
@belongsTo("user", { async: false, inverse: "absenceBalances" })
declare user: User;
@belongsTo("absence-type", { async: false, inverse: "absenceBalances" })
declare absenceType: AbsenceType;
@hasMany("absence-credit", { async: true, inverse: null })
declare absenceCredits: AsyncHasMany<AbsenceCredit>;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-balance": AbsenceBalance;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Model, { attr, belongsTo } from "@ember-data/model";
import type { Moment } from "moment";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, belongsTo } from "@ember-data/model";

/**
* The absence credit model
Expand All @@ -19,37 +22,48 @@ export default class AbsenceCredit extends Model {
* @property {Number} days
* @public
*/
@attr("number") days;
@attr("number")
declare days?: number;

/**
* The date
*
* @property {moment} date
* @public
*/
@attr("django-date") date;
@attr("django-date")
declare date?: Moment;

/**
* The comment
*
* @property {String} comment
* @public
*/
@attr("string", { defaultValue: "" }) comment;
@attr("string", { defaultValue: "" })
declare comment: string;

/**
* The absence type for which this credit counts
*
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
@belongsTo("absence-type", { async: false, inverse: null })
declare absenceType: AbsenceType;

/**
* The user to which this credit belongs to
*
* @property {User} user
* @public
*/
@belongsTo("user", { async: false, inverse: null }) user;
@belongsTo("user", { async: false, inverse: null })
declare user: User;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-credit": AbsenceCredit;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { AsyncHasMany } from "@ember-data/model";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, hasMany } from "@ember-data/model";
import type AbsenceBalance from "timed/models/absence-balance";

/**
* The absence type model
Expand All @@ -21,15 +23,17 @@ export default class AbsenceType extends Model {
* @property {String} name
* @public
*/
@attr("string") name;
@attr("string")
declare name?: string;

/**
* Whether the absence type only fills the worktime
*
* @property {Boolean} fillWorktime
* @public
*/
@attr("boolean") fillWorktime;
@attr("boolean")
declare fillWorktime?: boolean;

/**
* The balances for this type
Expand All @@ -38,5 +42,11 @@ export default class AbsenceType extends Model {
* @public
*/
@hasMany("absence-balance", { async: true, inverse: "absenceType" })
absenceBalances;
declare absenceBalances: AsyncHasMany<AbsenceBalance>;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-type": AbsenceType;
}
}
27 changes: 21 additions & 6 deletions frontend/app/models/absence.js → frontend/app/models/absence.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { AsyncBelongsTo } from "@ember-data/model";
import Model, { attr, belongsTo } from "@ember-data/model";
import type { Moment, Duration } from "moment";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, belongsTo } from "@ember-data/model";
import moment from "moment";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";

/**
* The report model
Expand All @@ -20,37 +24,48 @@ export default class Absence extends Model {
* @property {String} comment
* @public
*/
@attr("string", { defaultValue: "" }) comment;
@attr("string", { defaultValue: "" })
declare comment: string;

/**
* The duration
*
* @property {moment.duration} duration
* @public
*/
@attr("django-duration", { defaultValue: () => moment.duration() }) duration;
@attr("django-duration", { defaultValue: () => moment.duration() })
declare duration: Duration;

/**
* The date
*
* @property {moment} date
* @public
*/
@attr("django-date") date;
@attr("django-date")
declare date?: Moment;

/**
* The type of the absence
*
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
@belongsTo("absence-type", { async: false, inverse: null })
declare absenceType: AbsenceType;

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

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
absence: Absence;
}
}
45 changes: 33 additions & 12 deletions frontend/app/models/activity.js → frontend/app/models/activity.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import { service } from "@ember/service";
import type { AsyncBelongsTo } from "@ember-data/model";
import Model, { attr, belongsTo } from "@ember-data/model";
import type StoreService from "@ember-data/store";
import type NotifyService from "ember-notify";
import type { Moment } from "moment";
import moment from "moment";
import { all } from "rsvp";
import type Task from "timed/models/task";
import type User from "timed/models/user";

export default class Activity extends Model {
@attr("django-time") fromTime;
@attr("django-time") toTime;
@attr("string", { defaultValue: "" }) comment;
@attr("django-date") date;
@attr("boolean", { defaultValue: false }) transferred;
@attr("boolean", { defaultValue: false }) review;
@attr("boolean", { defaultValue: false }) notBillable;
@belongsTo("task", { async: true, inverse: null }) task;
@belongsTo("user", { async: true, inverse: null }) user;

@service notify;
@service store;
@attr("django-time")
declare fromTime?: Moment;
@attr("django-time")
declare toTime?: Moment;
@attr("string", { defaultValue: "" })
declare comment: string;
@attr("django-date")
declare date?: Moment;
@attr("boolean", { defaultValue: false })
declare transferred: boolean;
@attr("boolean", { defaultValue: false })
declare review: boolean;
@attr("boolean", { defaultValue: false })
declare notBillable: boolean;
@belongsTo("task", { async: true, inverse: null })
declare task: AsyncBelongsTo<Task>;
@belongsTo("user", { async: true, inverse: null })
declare user: AsyncBelongsTo<User>;

@service declare notify: NotifyService;
@service declare store: StoreService;

get active() {
return !this.toTime && !!this.id;
Expand Down Expand Up @@ -137,3 +152,9 @@ export default class Activity extends Model {
}
}
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
activity: Activity;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { AsyncBelongsTo } from "@ember-data/model";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, belongsTo } from "@ember-data/model";
import type { Moment } from "moment";
import moment from "moment";
import type User from "timed/models/user";

/**
* The attendance model
Expand All @@ -20,23 +23,26 @@ export default class Attendance extends Model {
* @property {moment} date
* @public
*/
@attr("django-date") date;
@attr("django-date")
declare date?: Moment;

/**
* The start time
*
* @property {moment} from
* @public
*/
@attr("django-time") from;
@attr("django-time")
declare from?: Moment;

/**
* The end time
*
* @property {moment} to
* @public
*/
@attr("django-time") to;
@attr("django-time")
declare to?: Moment;

/**
* The user
Expand All @@ -45,7 +51,8 @@ export default class Attendance extends Model {
* @type {User}
* @public
*/
@belongsTo("user", { async: true, inverse: null }) user;
@belongsTo("user", { async: true, inverse: null })
declare user: AsyncBelongsTo<User>;

/**
* The duration between start and end time
Expand All @@ -65,3 +72,9 @@ export default class Attendance extends Model {
return moment.duration(calcTo.diff(this.from));
}
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
attendance: Attendance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ export default class BillingType extends Model {
* @property {String} name
* @public
*/
@attr("string") name;
@attr("string")
declare name?: string;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"billing-type": BillingType;
}
}
6 changes: 0 additions & 6 deletions frontend/app/models/cost-center.js

This file was deleted.

Loading

0 comments on commit 905c5b1

Please sign in to comment.