Skip to content

Modular logistics and supply chain operating system (LSOS)

1.5 KB
Raw Blame
import Model, { attr, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { format, formatDistanceToNow } from 'date-fns';

export default class RoleModel extends Model {
    /** @ids */
    @attr('string') company_uuid;

    /** @relationships */
    @hasMany('policy') policies;
    @hasMany('permission') permissions;

    /** @attributes */
    @attr('string') name;
    @attr('string') guard_name;
    @attr('string') description;
    @attr('string') service;
    @attr('string') type;
    @attr('boolean') is_mutable;
    @attr('boolean') is_deletable;

    /** @dates */
    @attr('date') created_at;
    @attr('date') updated_at;

    /** @methods */
    toJSON() {
        return this.serialize();
    }

    /** @computed */
    @computed('permissions') get permissionsArray() {
        return this.permissions.toArray();
    }

    @computed('updated_at') get updatedAgo() {
        return formatDistanceToNow(this.updated_at);
    }

    @computed('updated_at') get updatedAt() {
        return format(this.updated_at, 'yyyy-MM-dd HH:mm');
    }

    @computed('updated_at') get updatedAtShort() {
        return format(this.updated_at, 'PP');
    }

    @computed('created_at') get createdAgo() {
        return formatDistanceToNow(this.created_at);
    }

    @computed('created_at') get createdAt() {
        return format(this.created_at, 'yyyy-MM-dd HH:mm');
    }

    @computed('created_at') get createdAtShort() {
        return format(this.created_at, 'PP');
    }
}