|
| 1 | +import { |
| 2 | + isPOSTLivechatTagsRemoveParams, |
| 3 | + POSTLivechatTagsRemoveSuccessResponse, |
| 4 | + validateBadRequestErrorResponse, |
| 5 | + validateForbiddenErrorResponse, |
| 6 | + validateUnauthorizedErrorResponse, |
| 7 | +} from '@rocket.chat/rest-typings'; |
| 8 | + |
1 | 9 | import { findTags, findTagById } from './lib/tags'; |
2 | 10 | import { API } from '../../../../../app/api/server'; |
| 11 | +import type { ExtractRoutesFromAPI } from '../../../../../app/api/server/ApiClass'; |
3 | 12 | import { getPaginationItems } from '../../../../../app/api/server/helpers/getPaginationItems'; |
| 13 | +import { LivechatEnterprise } from '../lib/LivechatEnterprise'; |
4 | 14 |
|
5 | 15 | API.v1.addRoute( |
6 | 16 | 'livechat/tags', |
@@ -56,3 +66,40 @@ API.v1.addRoute( |
56 | 66 | }, |
57 | 67 | }, |
58 | 68 | ); |
| 69 | + |
| 70 | +const livechatTagsEndpoints = API.v1.post( |
| 71 | + 'livechat/tags.delete', |
| 72 | + { |
| 73 | + response: { |
| 74 | + 200: POSTLivechatTagsRemoveSuccessResponse, |
| 75 | + 400: validateBadRequestErrorResponse, |
| 76 | + 401: validateUnauthorizedErrorResponse, |
| 77 | + 403: validateForbiddenErrorResponse, |
| 78 | + }, |
| 79 | + authRequired: true, |
| 80 | + permissions: ['manage-livechat-tags'], |
| 81 | + license: ['livechat-enterprise'], |
| 82 | + body: isPOSTLivechatTagsRemoveParams, |
| 83 | + }, |
| 84 | + async function action() { |
| 85 | + const { id } = this.bodyParams; |
| 86 | + try { |
| 87 | + await LivechatEnterprise.removeTag(id); |
| 88 | + |
| 89 | + return API.v1.success(); |
| 90 | + } catch (error: unknown) { |
| 91 | + if (error instanceof Meteor.Error) { |
| 92 | + return API.v1.failure(error.reason); |
| 93 | + } |
| 94 | + |
| 95 | + return API.v1.failure('error-removing-tag'); |
| 96 | + } |
| 97 | + }, |
| 98 | +); |
| 99 | + |
| 100 | +type LivechatTagsEndpoints = ExtractRoutesFromAPI<typeof livechatTagsEndpoints>; |
| 101 | + |
| 102 | +declare module '@rocket.chat/rest-typings' { |
| 103 | + // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface |
| 104 | + interface Endpoints extends LivechatTagsEndpoints {} |
| 105 | +} |
0 commit comments