Skip to content

Commit

Permalink
Revert "[BREAK] use urlParams on omnichannel/agent/extension/" (#25980)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Jun 23, 2022
1 parent 14ac8ef commit d69caf1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
73 changes: 34 additions & 39 deletions apps/meteor/app/api/server/v1/voip/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ 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 @@ -89,55 +121,18 @@ 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.urlParams,
this.requestParams(),
Match.ObjectIncluding({
username: String,
}),
);
const { username } = this.urlParams;
const { username } = this.requestParams();
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/${username}`);
const removeAgent = useEndpoint('DELETE', '/v1/omnichannel/agent/extension');
const setModal = useSetModal();
const dispatchToastMessage = useToastMessageDispatch();
const t = useTranslation();

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

0 comments on commit d69caf1

Please sign in to comment.