Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] API endpoint to fetch Omnichannel's room transfer history #17694

Merged
merged 4 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/livechat/server/api/lib/transfer.js
@@ -0,0 +1,27 @@
import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { Messages } from '../../../../models/server/raw';

const normalizeTransferHistory = ({ transferData }) => transferData;
export async function findLivechatTransferHistory({ userId, rid, pagination: { offset, count, sort } }) {
if (!await hasPermissionAsync(userId, 'view-livechat-rooms')) {
throw new Error('error-not-authorized');
}

const cursor = await Messages.find({ rid, t: 'livechat_transfer_history' }, {
fields: { transferData: 1 },
sort: sort || { ts: 1 },
skip: offset,
limit: count,
});

const total = await cursor.count();
const messages = await cursor.toArray();
const history = messages.map(normalizeTransferHistory);

return {
history,
count: history.length,
offset,
total,
};
}
1 change: 1 addition & 0 deletions app/livechat/server/api/rest.js
Expand Up @@ -8,3 +8,4 @@ import './v1/message.js';
import './v1/customField.js';
import './v1/room.js';
import './v1/videoCall.js';
import './v1/transfer.js';
36 changes: 36 additions & 0 deletions app/livechat/server/api/v1/transfer.js
@@ -0,0 +1,36 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { LivechatRooms } from '../../../../models';
import { API } from '../../../../api';
import { findLivechatTransferHistory } from '../lib/transfer';

API.v1.addRoute('livechat/transfer.history/:rid', { authRequired: true }, {
get() {
check(this.urlParams, {
rid: String,
});

const { rid } = this.urlParams;

const room = LivechatRooms.findOneById(rid, { _id: 1 });
if (!room) {
throw new Meteor.Error('invalid-room');
}

const { offset, count } = this.getPaginationItems();
const { sort } = this.parseJsonQuery();

const history = Promise.await(findLivechatTransferHistory({
userId: this.userId,
rid,
pagination: {
offset,
count,
sort,
},
}));

return API.v1.success(history);
},
});