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

[BREAK] use urlParams on omnichannel/agent/extension/ #25874

Merged
merged 1 commit into from
Jun 23, 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
73 changes: 39 additions & 34 deletions apps/meteor/app/api/server/v1/voip/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ API.v1.addRoute(
'omnichannel/agent/extension',
{ authRequired: true },
{
// Get the extensions associated with the agent passed as request params.
async get() {
if (!hasPermission(this.userId, 'view-agent-extension-association')) {
return API.v1.unauthorized();
}
check(
this.requestParams(),
Match.ObjectIncluding({
username: String,
}),
);
const { username } = this.requestParams();
const user = await Users.findOneByAgentUsername(username, {
projection: { _id: 1 },
});
if (!user) {
return API.v1.notFound('User not found');
}
const extension = await Users.getVoipExtensionByUserId(user._id, {
projection: {
_id: 1,
username: 1,
extension: 1,
},
});
if (!extension) {
return API.v1.notFound('Extension not found');
}
return API.v1.success({ extension });
},

// Create agent-extension association.
async post() {
if (!hasPermission(this.userId, 'manage-agent-extension-association')) {
return API.v1.unauthorized();
Expand Down Expand Up @@ -121,18 +89,55 @@ API.v1.addRoute(
return API.v1.failure(`extension already in use ${extension}`);
}
},
},
);

API.v1.addRoute(
'omnichannel/agent/extension/:username',
{ authRequired: true },
{
// Get the extensions associated with the agent passed as request params.
async get() {
if (!hasPermission(this.userId, 'view-agent-extension-association')) {
return API.v1.unauthorized();
}
check(
this.urlParams,
Match.ObjectIncluding({
username: String,
}),
);
const { username } = this.urlParams;
const user = await Users.findOneByAgentUsername(username, {
projection: { _id: 1 },
});
if (!user) {
return API.v1.notFound('User not found');
}
const extension = await Users.getVoipExtensionByUserId(user._id, {
projection: {
_id: 1,
username: 1,
extension: 1,
},
});
if (!extension) {
return API.v1.notFound('Extension not found');
}
return API.v1.success({ extension });
},

async delete() {
if (!hasPermission(this.userId, 'manage-agent-extension-association')) {
return API.v1.unauthorized();
}
check(
this.requestParams(),
this.urlParams,
Match.ObjectIncluding({
username: String,
}),
);
const { username } = this.requestParams();
const { username } = this.urlParams;
const user = await Users.findOneByAgentUsername(username, {
projection: {
_id: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import React, { FC } from 'react';
import GenericModal from '../../../../../components/GenericModal';

const RemoveAgentButton: FC<{ username: string; reload: () => void }> = ({ username, reload }) => {
const removeAgent = useEndpoint('DELETE', '/v1/omnichannel/agent/extension');
const removeAgent = useEndpoint('DELETE', `/v1/omnichannel/agent/extension/${username}`);
const setModal = useSetModal();
const dispatchToastMessage = useToastMessageDispatch();
const t = useTranslation();

const handleRemoveClick = useMutableCallback(async () => {
try {
await removeAgent({ username });
await removeAgent();
} catch (error: any) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
6 changes: 4 additions & 2 deletions packages/rest-typings/src/v1/voip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ export type VoipEndpoints = {
};
};
'/v1/omnichannel/agent/extension': {
GET: (params: OmnichannelAgentExtensionGET) => { extension: Pick<IUser, '_id' | 'username' | 'extension'> };
POST: (params: OmnichannelAgentExtensionPOST) => void;
DELETE: (params: OmnichannelAgentExtensionDELETE) => void;
};
'/v1/omnichannel/agent/extension/:username': {
GET: () => { extension: Pick<IUser, '_id' | 'username' | 'extension'> };
DELETE: () => void;
};
'/v1/omnichannel/agents/available': {
GET: (params: OmnichannelAgentsAvailable) => PaginatedResult<{ agents: ILivechatAgent[] }>;
Expand Down