@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
106 lines (91 loc) • 3.01 kB
JavaScript
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { computed, get } from '@ember/object';
import { notEmpty } from '@ember/object/computed';
import { capitalize } from '@ember/string';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import config from 'ember-get-config';
export default class VendorModel extends Model {
/** @ids */
public_id;
company_uuid;
type_uuid;
place_uuid;
connect_company_uuid;
logo_uuid;
internal_id;
business_id;
/** @relationships */
place;
personnels;
custom_field_values;
/** @attributes */
name;
email;
website_url;
logo_url;
phone;
address;
address_street;
country;
status;
slug;
type;
customer_type;
facilitator_type;
meta;
callbacks;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
has_place;
get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDistanceToNow(this.updated_at);
}
get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}
get updatedAtShort() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'dd, MMM');
}
get createdAgo() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDistanceToNow(this.created_at);
}
get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}
get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}
get prettyType() {
if (typeof this.type !== 'string') {
return '';
}
return this.type.replace('-', ' ').split(' ').map(capitalize).join(' ');
}
get isIntegratedVendor() {
return this.type === 'integrated_vendor';
}
}