Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert partially to Typescript #81

Open
wants to merge 13 commits into
base: primary
Choose a base branch
from
Prev Previous commit
Next Next commit
Convert more models
  • Loading branch information
backspace committed May 19, 2018
commit 8d7fabdeed44a4c99106d728d9c7a72630367554
6 changes: 0 additions & 6 deletions app/models/commitment.js

This file was deleted.

6 changes: 6 additions & 0 deletions app/models/commitment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import DS from 'ember-data';

export default class Commitment extends DS.Model.extend({
slot: DS.belongsTo('slot', { async: false }),
person: DS.belongsTo('person')
}) {}
6 changes: 3 additions & 3 deletions app/models/institution.js → app/models/institution.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { computed, get } from '@ember/object';
import DS from 'ember-data';
import dollars from 'prison-rideshare-ui/utils/dollars';

export default DS.Model.extend({
export default class Institution extends DS.Model.extend({
name: DS.attr(),
rate: DS.attr('number', {defaultValue: 0}),

@@ -11,10 +11,10 @@ export default DS.Model.extend({
validationErrors: computed('errors.[]', function() {
const attributes = get(this.constructor, 'attributes');

return attributes._keys.list.reduce((response, key) => {
return attributes._keys.list.reduce((response: ValidationDictionary, key: string) => {
const errors = this.get(`errors.${key}`) || [];
response[key] = errors.mapBy('message');
return response;
}, {});
})
});
}) {}
8 changes: 4 additions & 4 deletions app/models/person.js → app/models/person.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, get } from '@ember/object';
import DS from 'ember-data';

export default DS.Model.extend({
export default class Person extends DS.Model.extend({
name: DS.attr(),

email: DS.attr('string'),
@@ -14,7 +14,7 @@ export default DS.Model.extend({
notes: DS.attr('string'),
selfNotes: DS.attr('string'),

reimbursements: DS.hasMany(),
reimbursements: DS.hasMany('reimbursement'),

drivings: DS.hasMany('ride', {inverse: 'driver'}),
carOwnings: DS.hasMany('ride', {inverse: 'carOwner'}),
@@ -28,10 +28,10 @@ export default DS.Model.extend({
validationErrors: computed('errors.[]', function() {
const attributes = get(this.constructor, 'attributes');

return attributes._keys.list.reduce((response, key) => {
return attributes._keys.list.reduce((response: ValidationDictionary, key: string) => {
const errors = this.get(`errors.${key}`) || [];
response[key] = errors.mapBy('message');
return response;
}, {});
})
});
}) {}
8 changes: 4 additions & 4 deletions app/models/reimbursement.js → app/models/reimbursement.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import DS from 'ember-data';
import dollars from 'prison-rideshare-ui/utils/dollars';

export default DS.Model.extend({
export default class Reimbursement extends DS.Model.extend({
foodExpenses: DS.attr('number', {defaultValue: 0}),
carExpenses: DS.attr('number', {defaultValue: 0}),

person: DS.belongsTo(),
person: DS.belongsTo('person'),
donation: DS.attr('boolean'),
processed: DS.attr('boolean'),

foodExpensesDollars: dollars('foodExpenses'),
carExpensesDollars: dollars('carExpenses'),

ride: DS.belongsTo(),
ride: DS.belongsTo('ride'),

insertedAt: DS.attr('date')
});
}) {}
4 changes: 2 additions & 2 deletions app/utils/dollars.js → app/utils/dollars.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { computed } from '@ember/object';

export default function(property) {
export default function(property: string) {
return computed(property, {
get() {
return this.get(property)/100;
},

set(key, value) {
set(_key: string, value: number) {
this.set(property, Math.floor(value*100));
return value;
}
4 changes: 4 additions & 0 deletions types/prison-rideshare-ui/index.d.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ declare global {
id: String;
date: Date;
}

interface ValidationDictionary {
[index: string]: string;
}
}

export {};