mirror of
https://github.com/fleetbase/fleetbase.git
synced 2026-01-08 07:16:49 +00:00
added chat log model and serializer
This commit is contained in:
@@ -3,14 +3,16 @@ import { computed } from '@ember/object';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
|
||||
|
||||
export default class ChatChannel extends Model {
|
||||
export default class ChatChannelModel extends Model {
|
||||
/** @ids */
|
||||
@attr('string') public_id;
|
||||
@attr('string') company_uuid;
|
||||
|
||||
/** @attributes */
|
||||
@attr('string') name;
|
||||
@attr('string') title;
|
||||
@attr('string') slug;
|
||||
@attr('array') feed;
|
||||
@attr('array') meta;
|
||||
|
||||
/** @relationships */
|
||||
@@ -18,7 +20,7 @@ export default class ChatChannel extends Model {
|
||||
@hasMany('chat-message', { async: false }) messages;
|
||||
@hasMany('chat-attachment', { async: true }) attachments;
|
||||
@hasMany('chat-presence', { async: true }) presences;
|
||||
@belongsTo('chat-message', { async: false }) lastMessage;
|
||||
@belongsTo('chat-message', { async: false }) last_message;
|
||||
|
||||
/** @dates */
|
||||
@attr('date') created_at;
|
||||
@@ -64,7 +66,7 @@ export default class ChatChannel extends Model {
|
||||
|
||||
return store.query('chat-participant', { chat_channel_uuid: this.id }).then((participants) => {
|
||||
this.set('participants', participants);
|
||||
return participants
|
||||
return participants;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,7 +76,7 @@ export default class ChatChannel extends Model {
|
||||
|
||||
return store.query('chat-message', { chat_channel_uuid: this.id }).then((messages) => {
|
||||
this.set('messages', messages);
|
||||
return messages
|
||||
return messages;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ export default class ChatChannel extends Model {
|
||||
|
||||
return store.query('chat-attachment', { chat_channel_uuid: this.id }).then((attachments) => {
|
||||
this.set('attachments', attachments);
|
||||
return attachments
|
||||
return attachments;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
55
console/app/models/chat-log.js
Normal file
55
console/app/models/chat-log.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import Model, { belongsTo } from '@ember-data/model';
|
||||
import { computed } from '@ember/object';
|
||||
import { getOwner } from '@ember/application';
|
||||
import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
|
||||
|
||||
export default class ChatLogModel extends Model {
|
||||
/** @ids */
|
||||
@attr('string') company_uuid;
|
||||
@attr('string') chat_channel_uuid;
|
||||
@attr('string') initiator_uuid;
|
||||
|
||||
/** @attributes */
|
||||
@attr('string') content;
|
||||
@attr('string') resolved_content;
|
||||
@attr('string') event_type;
|
||||
@attr('string') status;
|
||||
@attr('array') meta;
|
||||
|
||||
/** @dates */
|
||||
@attr('date') created_at;
|
||||
@attr('date') updated_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');
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export default class ChatChannelSerializer extends ApplicationSerializer.extend(
|
||||
return {
|
||||
participants: { embedded: 'always' },
|
||||
messages: { embedded: 'always' },
|
||||
last_message: { embedded: 'always' },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
14
console/tests/unit/models/chat-log-test.js
Normal file
14
console/tests/unit/models/chat-log-test.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
import { setupTest } from '@fleetbase/console/tests/helpers';
|
||||
|
||||
module('Unit | Model | chat log', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('chat-log', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user