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

Chore: use params instead of URL building on livechat endpoints #25810

Merged
merged 1 commit into from
Jun 9, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const updateInquiries = async (inquiries = []) =>
inquiries.forEach((inquiry) => LivechatInquiry.upsert({ _id: inquiry._id }, { ...inquiry, _updatedAt: new Date(inquiry._updatedAt) }));

const getAgentsDepartments = async (userId) => {
const { departments } = await APIClient.get(`/v1/livechat/agents/${userId}/departments?enabledDepartmentsOnly=true`);
const { departments } = await APIClient.get(`/v1/livechat/agents/${userId}/departments`, { enabledDepartmentsOnly: true });
return departments;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ Template.closeRoom.onCreated(async function () {
this.onEnterTag = () => this.invalidTags.set(!validateRoomTags(this.tagsRequired.get(), this.tags.get()));

const { rid } = Template.currentData();
const { room } = await APIClient.get(`/v1/rooms.info?roomId=${rid}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId: rid });
this.tags.set(room?.tags || []);

if (room?.departmentId) {
const { department } = await APIClient.get(`/v1/livechat/department/${room.departmentId}?includeAgents=false`);
const { department } = await APIClient.get(`/v1/livechat/department/${room.departmentId}`, { includeAgents: false });
this.tagsRequired.set(department?.requestTagBeforeClosingChat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Template.livechatReadOnly.events({
event.stopPropagation();

try {
const { success } = (await APIClient.get(`/v1/livechat/room.join?roomId=${this.rid}`)) || {};
const { success } = (await APIClient.get(`/v1/livechat/room.join`, { roomId: this.rid })) || {};
if (!success) {
throw new Meteor.Error('error-join-room', 'Error joining room');
}
Expand Down Expand Up @@ -99,13 +99,13 @@ Template.livechatReadOnly.onCreated(async function () {

this.loadRoomAndInquiry = async (roomId) => {
this.preparing.set(true);
const { inquiry } = await APIClient.get(`/v1/livechat/inquiries.getOne?roomId=${roomId}`);
const { inquiry } = await APIClient.get(`/v1/livechat/inquiries.getOne`, { roomId });
this.inquiry.set(inquiry);
if (inquiry && inquiry._id) {
inquiryDataStream.on(inquiry._id, this.updateInquiry);
}

const { room } = await APIClient.get(`/v1/rooms.info?roomId=${roomId}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId });
this.room.set(room);
if (room && room._id) {
RoomManager.roomStream.on(roomId, (room) => this.room.set(room));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,24 @@ Template.contactChatHistory.onCreated(async function () {
const offset = this.offset.get();
const searchTerm = this.searchTerm.get();

let baseUrl = `/v1/livechat/visitors.searchChats/room/${
currentData.rid
}/visitor/${this.visitorId.get()}?count=${limit}&offset=${offset}&closedChatsOnly=true&servedChatsOnly=true`;
if (searchTerm) {
baseUrl += `&searchText=${searchTerm}`;
}
const baseUrl = `/v1/livechat/visitors.searchChats/room/${currentData.rid}/visitor/${this.visitorId.get()}`;
const params = {
count: limit,
offset,
closedChatsOnly: true,
servedChatsOnly: true,
...(searchTerm && { searchText: searchTerm }),
};

this.isLoading.set(true);
const { history, total } = await APIClient.get(baseUrl);
const { history, total } = await APIClient.get(baseUrl, params);
this.history.set(offset === 0 ? history : this.history.get().concat(history));
this.hasMore.set(total > this.history.get().length);
this.isLoading.set(false);
});

this.autorun(async () => {
const { room } = await APIClient.get(`/v1/rooms.info?roomId=${currentData.rid}`);
const { room } = await APIClient.get(`/v1/rooms.info`, { roomId: currentData.rid });
if (room?.v) {
this.visitorId.set(room.v._id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { APIClient } from '../../../utils/client';

Template.authorize.onCreated(async function () {
this.oauthApp = new ReactiveVar({});
const { oauthApp } = await APIClient.get(`/v1/oauth-apps.get?clientId=${this.data.client_id()}`);
const { oauthApp } = await APIClient.get(`/v1/oauth-apps.get`, { clientId: this.data.client_id() });
this.oauthApp.set(oauthApp);
});

Expand Down