From 4a5563a78a7af64125c526d5438fcd9b1e458e13 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 24 Jan 2025 12:11:27 -0300 Subject: [PATCH 1/4] fix tags endpoint results --- .../app/livechat-enterprise/server/api/tags.ts | 16 ++++++++++------ .../tests/end-to-end/api/livechat/13-tags.ts | 3 +-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts b/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts index eb1d190977b3..ab40e42aaf82 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts @@ -35,12 +35,16 @@ API.v1.addRoute( async get() { const { tagId } = this.urlParams; - return API.v1.success( - await findTagById({ - userId: this.userId, - tagId, - }), - ); + const tag = await findTagById({ + userId: this.userId, + tagId, + }); + + if (!tag) { + return API.v1.notFound('Tag not found'); + } + + return API.v1.success(tag); }, }, ); diff --git a/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts b/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts index 7953e772c016..4ebd4ccc2aee 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/13-tags.ts @@ -235,8 +235,7 @@ import { IS_EE } from '../../../e2e/config/constants'; it('should return null when the tag does not exist', async () => { await updatePermission('manage-livechat-tags', ['admin']); await updatePermission('view-l-room', ['livechat-agent']); - const response = await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(200); - expect(response.body.body).to.be.null; + await request.get(api('livechat/tags/123')).set(credentials).expect('Content-Type', 'application/json').expect(404); }); it('should return a tag', async () => { const tag = await saveTags(); From 654ed328bbd204d68fda3d9d6e72e5627616b3bc Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 24 Jan 2025 10:22:45 -0500 Subject: [PATCH 2/4] Create three-insects-roll.md --- .changeset/three-insects-roll.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .changeset/three-insects-roll.md diff --git a/.changeset/three-insects-roll.md b/.changeset/three-insects-roll.md new file mode 100644 index 000000000000..bcfcf0373385 --- /dev/null +++ b/.changeset/three-insects-roll.md @@ -0,0 +1,16 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes a missconception about `/v1/livechat/tags/:tagId` + +the type definition doesnt consider null/empty results +``` +'/v1/livechat/tags/:tagId': { + GET: () => ILivechatTag; + }; +``` + +the code returns `ILivechatTag | { body: null }` witch is weird/wrong. + +now if we cannot find the tag returns a 404 result From 633edec0bb355659c4a822dc94641a6cf77d95b9 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 24 Jan 2025 10:29:19 -0500 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Kevin Aleman --- .changeset/three-insects-roll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/three-insects-roll.md b/.changeset/three-insects-roll.md index bcfcf0373385..bab43087e6d5 100644 --- a/.changeset/three-insects-roll.md +++ b/.changeset/three-insects-roll.md @@ -11,6 +11,6 @@ the type definition doesnt consider null/empty results }; ``` -the code returns `ILivechatTag | { body: null }` witch is weird/wrong. +the code returns `ILivechatTag | { body: null }` which is weird/wrong. now if we cannot find the tag returns a 404 result From 65069f9ea3b3d04c98601f788e0b914430a46ea8 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 24 Jan 2025 12:33:37 -0500 Subject: [PATCH 4/4] Update three-insects-roll.md --- .changeset/three-insects-roll.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.changeset/three-insects-roll.md b/.changeset/three-insects-roll.md index bab43087e6d5..ae4f206dd83e 100644 --- a/.changeset/three-insects-roll.md +++ b/.changeset/three-insects-roll.md @@ -2,15 +2,4 @@ "@rocket.chat/meteor": patch --- -Fixes a missconception about `/v1/livechat/tags/:tagId` - -the type definition doesnt consider null/empty results -``` -'/v1/livechat/tags/:tagId': { - GET: () => ILivechatTag; - }; -``` - -the code returns `ILivechatTag | { body: null }` which is weird/wrong. - -now if we cannot find the tag returns a 404 result +Fixes a missconception about `/v1/livechat/tags/:tagId` returning 404 if tag is not found