-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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] Add Livechat inquiries endpoints #14779
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
import { API } from '../../../../api'; | ||
import { hasPermission } from '../../../../authorization'; | ||
import { Users } from '../../../../models'; | ||
import { LivechatInquiry } from '../../../lib/LivechatInquiry'; | ||
|
||
API.v1.addRoute('livechat/inquiries', { authRequired: true }, { | ||
get() { | ||
if (!hasPermission(this.userId, 'view-livechat-manager')) { | ||
return API.v1.unauthorized(); | ||
} | ||
const { offset, count } = this.getPaginationItems(); | ||
const { sort } = this.parseJsonQuery(); | ||
const cursor = LivechatInquiry.find({ status: 'open' }, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we decided to return the entire inquiry object, but due to the large number of agents available, it would be better to return only a few fields, such as:
|
||
sort: sort || { ts: -1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
const totalCount = cursor.count(); | ||
const inquiries = cursor.fetch(); | ||
|
||
|
||
return API.v1.success({ | ||
inquiries, | ||
offset, | ||
count: inquiries.length, | ||
total: totalCount, | ||
}); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('livechat/inquiry.take', { authRequired: true }, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better renaming this route to |
||
post() { | ||
if (!hasPermission(this.userId, 'view-livechat-manager')) { | ||
return API.v1.unauthorized(); | ||
} | ||
const { inquiryId, userId } = this.bodyParams; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using the
|
||
if (!inquiryId) { | ||
return API.v1.failure('The bodyParam "inquiryId" is required'); | ||
} | ||
if (userId && !Users.findOneById(userId, { fields: { _id: 1 } })) { | ||
return API.v1.failure('The user is invalid'); | ||
} | ||
return API.v1.success({ | ||
inquiry: Meteor.runAsUser(userId || this.userId, () => Meteor.call('livechat:takeInquiry', inquiryId)), | ||
}); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better renaming this route to
livechat/inquiries.list
, ok?