Skip to content

Instantly share code, notes, and snippets.

@gauthierm
Created November 15, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauthierm/cfe0f899671ea1288604b548ebfad206 to your computer and use it in GitHub Desktop.
Save gauthierm/cfe0f899671ea1288604b548ebfad206 to your computer and use it in GitHub Desktop.
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
suffix: DS.attr('string'),
company: DS.attr('string'),
phone: DS.attr('string'),
line1: DS.attr('string'),
line2: DS.attr('string'),
city: DS.attr('string'),
postalCode: DS.attr('string'),
provStateOther: DS.attr('string'),
// Relationships
country: DS.belongsTo('country'),
provState: DS.belongsTo('prov-state'),
// Computed
fullName: Ember.computed('firstName', 'lastName', 'suffix', function () {
if (this.get('suffix')) {
return `${this.get('firstName')} ${this.get('lastName')}, ${this.get('suffix')}`;
}
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
copyFrom(address) {
const keys = [
'firstName',
'lastName',
'suffix',
'company',
'phone',
'line1',
'line2',
'city',
'postalCode',
'provStateOther',
'country',
'provState',
];
const values = keys.map(key => address.get(key));
const properties = keys.reduce((map, key, index) => {
const newMap = map;
newMap[key] = values[index];
return newMap;
}, {});
this.setProperties(properties);
return this;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment