Skip to content

Commit e15c193

Browse files
committed
refactor(frontend): convert models, services, transforms, adapters and serializers to typescript
1 parent e7970af commit e15c193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+971
-231
lines changed

frontend/app/adapters/activity-block.js renamed to frontend/app/adapters/activity-block.ts

+6
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ export default class ActivityBlockAdapter extends ApplicationAdapter {
4141
return `${super.urlForCreateRecord(...args)}?include=activity`;
4242
}
4343
}
44+
45+
declare module "ember-data/types/registries/adapter" {
46+
export default interface AdapterRegistry {
47+
"activity-block": ActivityBlockAdapter;
48+
}
49+
}

frontend/app/config/environment.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ declare const config: {
66
environment: string;
77
modulePrefix: string;
88
podModulePrefix: string;
9-
locationType: 'history' | 'hash' | 'none';
9+
locationType: "history" | "hash" | "none";
1010
rootURL: string;
1111
APP: Record<string, unknown>;
1212
};
1313

14-
export default config;
14+
export default config;

frontend/app/models/absence-balance.js

-12
This file was deleted.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { AsyncHasMany } from "@ember-data/model";
2+
import Model, { attr, belongsTo, hasMany } from "@ember-data/model";
3+
import type { Duration } from "moment";
4+
import type AbsenceCredit from "timed/models/absence-credit";
5+
import type AbsenceType from "timed/models/absence-type";
6+
import type User from "timed/models/user";
7+
8+
export default class AbsenceBalance extends Model {
9+
@attr("number")
10+
declare credit?: number;
11+
@attr("number")
12+
declare usedDays?: number;
13+
@attr("django-duration")
14+
declare usedDuration?: Duration;
15+
@attr("number")
16+
declare balance?: number;
17+
@belongsTo("user", { async: false, inverse: "absenceBalances" })
18+
declare user: User;
19+
@belongsTo("absence-type", { async: false, inverse: "absenceBalances" })
20+
declare absenceType: AbsenceType;
21+
@hasMany("absence-credit", { async: true, inverse: null })
22+
declare absenceCredits: AsyncHasMany<AbsenceCredit>;
23+
}
24+
25+
declare module "ember-data/types/registries/model" {
26+
export default interface ModelRegistry {
27+
"absence-balance": AbsenceBalance;
28+
}
29+
}

frontend/app/models/absence-credit.js renamed to frontend/app/models/absence-credit.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import Model, { attr, belongsTo } from "@ember-data/model";
2+
import type { Moment } from "moment";
3+
import type AbsenceType from "timed/models/absence-type";
4+
import type User from "timed/models/user";
15
/**
26
* @module timed
37
* @submodule timed-models
48
* @public
59
*/
6-
import Model, { attr, belongsTo } from "@ember-data/model";
710

811
/**
912
* The absence credit model
@@ -19,37 +22,48 @@ export default class AbsenceCredit extends Model {
1922
* @property {Number} days
2023
* @public
2124
*/
22-
@attr("number") days;
25+
@attr("number")
26+
declare days?: number;
2327

2428
/**
2529
* The date
2630
*
2731
* @property {moment} date
2832
* @public
2933
*/
30-
@attr("django-date") date;
34+
@attr("django-date")
35+
declare date?: Moment;
3136

3237
/**
3338
* The comment
3439
*
3540
* @property {String} comment
3641
* @public
3742
*/
38-
@attr("string", { defaultValue: "" }) comment;
43+
@attr("string", { defaultValue: "" })
44+
declare comment: string;
3945

4046
/**
4147
* The absence type for which this credit counts
4248
*
4349
* @property {AbsenceType} absenceType
4450
* @public
4551
*/
46-
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
52+
@belongsTo("absence-type", { async: false, inverse: null })
53+
declare absenceType: AbsenceType;
4754

4855
/**
4956
* The user to which this credit belongs to
5057
*
5158
* @property {User} user
5259
* @public
5360
*/
54-
@belongsTo("user", { async: false, inverse: null }) user;
61+
@belongsTo("user", { async: false, inverse: null })
62+
declare user: User;
63+
}
64+
65+
declare module "ember-data/types/registries/model" {
66+
export default interface ModelRegistry {
67+
"absence-credit": AbsenceCredit;
68+
}
5569
}

frontend/app/models/absence-type.js renamed to frontend/app/models/absence-type.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import type { AsyncHasMany } from "@ember-data/model";
12
/**
23
* @module timed
34
* @submodule timed-models
45
* @public
56
*/
67
import Model, { attr, hasMany } from "@ember-data/model";
8+
import type AbsenceBalance from "timed/models/absence-balance";
79

810
/**
911
* The absence type model
@@ -21,15 +23,17 @@ export default class AbsenceType extends Model {
2123
* @property {String} name
2224
* @public
2325
*/
24-
@attr("string") name;
26+
@attr("string")
27+
declare name?: string;
2528

2629
/**
2730
* Whether the absence type only fills the worktime
2831
*
2932
* @property {Boolean} fillWorktime
3033
* @public
3134
*/
32-
@attr("boolean") fillWorktime;
35+
@attr("boolean")
36+
declare fillWorktime?: boolean;
3337

3438
/**
3539
* The balances for this type
@@ -38,5 +42,11 @@ export default class AbsenceType extends Model {
3842
* @public
3943
*/
4044
@hasMany("absence-balance", { async: true, inverse: "absenceType" })
41-
absenceBalances;
45+
declare absenceBalances: AsyncHasMany<AbsenceBalance>;
46+
}
47+
48+
declare module "ember-data/types/registries/model" {
49+
export default interface ModelRegistry {
50+
"absence-type": AbsenceType;
51+
}
4252
}

frontend/app/models/absence.js renamed to frontend/app/models/absence.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import type { AsyncBelongsTo } from "@ember-data/model";
2+
import Model, { attr, belongsTo } from "@ember-data/model";
3+
import type { Moment, Duration } from "moment";
14
/**
25
* @module timed
36
* @submodule timed-models
47
* @public
58
*/
6-
import Model, { attr, belongsTo } from "@ember-data/model";
79
import moment from "moment";
10+
import type AbsenceType from "timed/models/absence-type";
11+
import type User from "timed/models/user";
812

913
/**
1014
* The report model
@@ -20,37 +24,48 @@ export default class Absence extends Model {
2024
* @property {String} comment
2125
* @public
2226
*/
23-
@attr("string", { defaultValue: "" }) comment;
27+
@attr("string", { defaultValue: "" })
28+
declare comment: string;
2429

2530
/**
2631
* The duration
2732
*
2833
* @property {moment.duration} duration
2934
* @public
3035
*/
31-
@attr("django-duration", { defaultValue: () => moment.duration() }) duration;
36+
@attr("django-duration", { defaultValue: () => moment.duration() })
37+
declare duration: Duration;
3238

3339
/**
3440
* The date
3541
*
3642
* @property {moment} date
3743
* @public
3844
*/
39-
@attr("django-date") date;
45+
@attr("django-date")
46+
declare date?: Moment;
4047

4148
/**
4249
* The type of the absence
4350
*
4451
* @property {AbsenceType} absenceType
4552
* @public
4653
*/
47-
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
54+
@belongsTo("absence-type", { async: false, inverse: null })
55+
declare absenceType: AbsenceType;
4856

4957
/**
5058
* The user
5159
*
5260
* @property {User} user
5361
* @public
5462
*/
55-
@belongsTo("user", { async: true, inverse: null }) user;
63+
@belongsTo("user", { async: true, inverse: null })
64+
declare user: AsyncBelongsTo<User>;
65+
}
66+
67+
declare module "ember-data/types/registries/model" {
68+
export default interface ModelRegistry {
69+
absence: Absence;
70+
}
5671
}

frontend/app/models/activity.js renamed to frontend/app/models/activity.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
import { service } from "@ember/service";
2+
import type { AsyncBelongsTo } from "@ember-data/model";
23
import Model, { attr, belongsTo } from "@ember-data/model";
4+
import type StoreService from "@ember-data/store";
5+
import type NotifyService from "ember-notify";
6+
import type { Moment } from "moment";
37
import moment from "moment";
48
import { all } from "rsvp";
9+
import type Task from "timed/models/task";
10+
import type User from "timed/models/user";
511

612
export default class Activity extends Model {
7-
@attr("django-time") fromTime;
8-
@attr("django-time") toTime;
9-
@attr("string", { defaultValue: "" }) comment;
10-
@attr("django-date") date;
11-
@attr("boolean", { defaultValue: false }) transferred;
12-
@attr("boolean", { defaultValue: false }) review;
13-
@attr("boolean", { defaultValue: false }) notBillable;
14-
@belongsTo("task", { async: true, inverse: null }) task;
15-
@belongsTo("user", { async: true, inverse: null }) user;
16-
17-
@service notify;
18-
@service store;
13+
@attr("django-time")
14+
declare fromTime?: Moment;
15+
@attr("django-time")
16+
declare toTime?: Moment;
17+
@attr("string", { defaultValue: "" })
18+
declare comment: string;
19+
@attr("django-date")
20+
declare date?: Moment;
21+
@attr("boolean", { defaultValue: false })
22+
declare transferred: boolean;
23+
@attr("boolean", { defaultValue: false })
24+
declare review: boolean;
25+
@attr("boolean", { defaultValue: false })
26+
declare notBillable: boolean;
27+
@belongsTo("task", { async: true, inverse: null })
28+
declare task: AsyncBelongsTo<Task>;
29+
@belongsTo("user", { async: true, inverse: null })
30+
declare user: AsyncBelongsTo<User>;
31+
32+
@service declare notify: NotifyService;
33+
@service declare store: StoreService;
1934

2035
get active() {
2136
return !this.toTime && !!this.id;
@@ -137,3 +152,9 @@ export default class Activity extends Model {
137152
}
138153
}
139154
}
155+
156+
declare module "ember-data/types/registries/model" {
157+
export default interface ModelRegistry {
158+
activity: Activity;
159+
}
160+
}

frontend/app/models/attendance.js renamed to frontend/app/models/attendance.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import type { AsyncBelongsTo } from "@ember-data/model";
12
/**
23
* @module timed
34
* @submodule timed-models
45
* @public
56
*/
67
import Model, { attr, belongsTo } from "@ember-data/model";
8+
import type { Moment } from "moment";
79
import moment from "moment";
10+
import type User from "timed/models/user";
811

912
/**
1013
* The attendance model
@@ -20,23 +23,26 @@ export default class Attendance extends Model {
2023
* @property {moment} date
2124
* @public
2225
*/
23-
@attr("django-date") date;
26+
@attr("django-date")
27+
declare date?: Moment;
2428

2529
/**
2630
* The start time
2731
*
2832
* @property {moment} from
2933
* @public
3034
*/
31-
@attr("django-time") from;
35+
@attr("django-time")
36+
declare from?: Moment;
3237

3338
/**
3439
* The end time
3540
*
3641
* @property {moment} to
3742
* @public
3843
*/
39-
@attr("django-time") to;
44+
@attr("django-time")
45+
declare to?: Moment;
4046

4147
/**
4248
* The user
@@ -45,7 +51,8 @@ export default class Attendance extends Model {
4551
* @type {User}
4652
* @public
4753
*/
48-
@belongsTo("user", { async: true, inverse: null }) user;
54+
@belongsTo("user", { async: true, inverse: null })
55+
declare user: AsyncBelongsTo<User>;
4956

5057
/**
5158
* The duration between start and end time
@@ -65,3 +72,9 @@ export default class Attendance extends Model {
6572
return moment.duration(calcTo.diff(this.from));
6673
}
6774
}
75+
76+
declare module "ember-data/types/registries/model" {
77+
export default interface ModelRegistry {
78+
attendance: Attendance;
79+
}
80+
}

frontend/app/models/billing-type.js renamed to frontend/app/models/billing-type.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@ export default class BillingType extends Model {
1919
* @property {String} name
2020
* @public
2121
*/
22-
@attr("string") name;
22+
@attr("string")
23+
declare name?: string;
24+
}
25+
26+
declare module "ember-data/types/registries/model" {
27+
export default interface ModelRegistry {
28+
"billing-type": BillingType;
29+
}
2330
}

frontend/app/models/cost-center.js

-6
This file was deleted.

0 commit comments

Comments
 (0)