Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Created February 20, 2018 00:31
Show Gist options
  • Select an option

  • Save joegaudet/267567af94edef72d7b6f934e58d5a84 to your computer and use it in GitHub Desktop.

Select an option

Save joegaudet/267567af94edef72d7b6f934e58d5a84 to your computer and use it in GitHub Desktop.
import DS from 'ember-data';
export default Model.extend({
billingLocation: attr('location'),
billingContact: attr('contact'),
});
import DS from 'ember-data';
import formatPhoneNumber from 'star-fox/utils/format-phone-number';
export class Contact {
constructor(hash = {}) {
this.firstName = hash['first-name'] || null;
this.lastName = hash['last-name'] || null;
this.email = hash['email'] || null;
this.phoneNumber = hash['phone-number'] || null;
this.extension = hash['extension'] || null;
this.smsNumber = hash['sms-number'] || null;
}
get name() {
return `${this.firstName} ${this.lastName}`;
}
toString() {
return [
this.name,
this.email,
formatPhoneNumber(this.phoneNumber),
this.extension
]
.filter(_ => !!_)
.join(' – ');
}
}
export default DS.Transform.extend({
deserialize(payload) {
return new Contact(payload);
},
serialize(value) {
return value;
}
});
import DS from 'ember-data';
class Location {
constructor(hash = {}) {
this.building = hash['building'] || null;
this.street = hash['building'] || null;
this.city = hash['city'] || null;
this.province = hash['province'] || null;
this.country = hash['country'] || null;
this.addressCode = hash['addressCode'] || null;
// Delivery Specific Data
this.poBox = hash['po-box'] || null;
this.buzzer = hash['buzzer'] || null;
this.unitNumber = hash['unitNumber'] || null;
this.floor = hash['floor'] || null;
// GIS Data
this.latitude = hash['latitude'] || null;
this.longitude = hash['longitude'] || null;
}
toJson() {
}
toString() {
const ret = [`${this.building} ${this.street}, ${this.city} ${this.province} ${this.country}, ${this.addressCode}`];
if (this.unitNumber) {
ret.unshift(`${this.unitNumber} - `);
}
if (this.floor) {
ret.push(`, Floor: ${this.floor}`);
}
if (this.buzzer) {
ret.push(`, Buzzer: ${this.buzzer}`);
}
return ret.join(' ');
}
}
export default DS.Transform.extend({
deserialize(payload) {
return new Location(payload);
},
serialize(value) {
return value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment