Skip to content

Modular logistics and supply chain operating system (LSOS)

added computed date properties to ChatChannelModel

Ronald A. Richardson4191d6a0bba6
diff --git a/console/app/models/chat-channel.js b/console/app/models/chat-channel.js
index 205445cf..c3721336 100644
--- a/console/app/models/chat-channel.js
+++ b/console/app/models/chat-channel.js
@@ -1,26 +1,58 @@
import Model, { attr, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
-import { slugify } from 'ember-string';
+import { format, formatDistanceToNow } from 'date-fns';
export default class ChatChannel extends Model {
- /** @attributes */
- @attr('string') name;
- @attr('string') slug;
- @attr meta;
-
- /** @relationships */
- @hasMany('chat-participant', { async: true }) participants;
- @hasMany('chat-message', { async: true }) messages;
- @hasMany('chat-attachment', { async: true }) attachments;
- @hasMany('chat-presence', { async: true }) presences;
-
- /** @computed */
- @computed('name') get slugifiedName() {
- return slugify(this.name);
- }
-
- /** @dates */
- @attr('date') created_at;
- @attr('date') updated_at;
- @attr('date') deleted_at;
+ /** @ids */
+ @attr('string') public_id;
+ @attr('string') company_uuid;
+
+ /** @attributes */
+ @attr('string') name;
+ @attr('string') slug;
+ @attr('array') meta;
+
+ /** @relationships */
+ @hasMany('chat-participant', { async: true }) participants;
+ @hasMany('chat-message', { async: true }) messages;
+ @hasMany('chat-attachment', { async: true }) attachments;
+ @hasMany('chat-presence', { async: true }) presences;
+
+ /** @dates */
+ @attr('date') created_at;
+ @attr('date') updated_at;
+ @attr('date') deleted_at;
+
+ /** @computed */
+ @computed('updated_at') get updatedAgo() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.updated_at);
+ }
+
+ @computed('updated_at') get updatedAt() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+
+ return formatDate(this.updated_at, 'PP HH:mm');
+ }
+
+ @computed('created_at') get createdAgo() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.created_at);
+ }
+
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDate(this.created_at, 'PP HH:mm');
+ }
}