diff --git a/src/controller/labelsController.js b/src/controller/labelsController.js new file mode 100644 index 0000000000..07e1f1b79a --- /dev/null +++ b/src/controller/labelsController.js @@ -0,0 +1,57 @@ +export async function addNewLabel(req, res) { + const { name, options } = req.body; + if (!name) + return res.status(401).send({ + message: 'Name was not informed', + }); + + try { + const result = await req.client.addNewLabel(name, options); + res.status(201).json({ status: 'success', response: result }); + } catch (error) { + res.status(500).json({ status: 'Error', message: 'Erro ao adicionar etiqueta.' }); + } +} + +export async function addOrRemoveLabels(req, res) { + const { chatIds, options } = req.body; + if (!chatIds || !options) + return res.status(401).send({ + message: 'chatIds or options was not informed', + }); + + try { + const result = await req.client.addOrRemoveLabels(chatIds, options); + res.status(201).json({ status: 'success', response: result }); + } catch (error) { + res.status(500).json({ status: 'Error', message: 'Erro ao adicionar/deletar etiqueta.' }); + } +} + +export async function getAllLabels(req, res) { + try { + const result = await req.client.getAllLabels(); + res.status(201).json({ status: 'success', response: result }); + } catch (error) { + res.status(500).json({ status: 'Error', message: 'Erro ao buscar etiquetas.' }); + } +} + +export async function deleteAllLabels(req, res) { + try { + const result = await req.client.deleteAllLabels(); + res.status(201).json({ status: 'success', response: result }); + } catch (error) { + res.status(500).json({ status: 'Error', message: 'Erro ao deletar todas as etiquetas.' }); + } +} + +export async function deleteLabel(req, res) { + const { id } = req.paramns; + try { + const result = await req.client.deleteLabel(id); + res.status(201).json({ status: 'success', response: result }); + } catch (error) { + res.status(500).json({ status: 'Error', message: 'Erro ao deletar etiqueta.' }); + } +} diff --git a/src/routes/index.js b/src/routes/index.js index a97da93d8d..aab0ec51fd 100755 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -17,6 +17,7 @@ import { Router } from 'express'; import { encryptSession } from '../controller/encryptController'; import * as MessageController from '../controller/messageController'; import * as StatusController from '../controller/statusController'; +import * as LabelsController from '../controller/labelsController'; import * as GroupController from '../controller/groupController'; import * as DeviceController from '../controller/deviceController'; import * as SessionController from '../controller/sessionController'; @@ -213,6 +214,13 @@ routes.post( StatusController.sendVideoStorie ); +// Labels +routes.post('/api/:session/add-new-label', verifyToken, statusConnection, LabelsController.addNewLabel); +routes.post('/api/:session/add-or-remove-label', verifyToken, statusConnection, LabelsController.addOrRemoveLabels); +routes.get('/api/:session/get-all-labels', verifyToken, statusConnection, LabelsController.getAllLabels); +routes.put('/api/:session/delete-all-labels', verifyToken, statusConnection, LabelsController.deleteAllLabels); +routes.put('/api/:session/delete-label/:id', verifyToken, statusConnection, LabelsController.deleteLabel); + // Contact routes.get( '/api/:session/check-number-status/:phone', diff --git a/src/swagger.json b/src/swagger.json index d97d66583b..382bfeff7e 100644 --- a/src/swagger.json +++ b/src/swagger.json @@ -6460,7 +6460,7 @@ }, "/send-image-storie": { "post": { - "tags": ["Status"], + "tags": ["Status Stories"], "summary": "Send Image Storie ", "description": "Send Image Storie", "operationId": "SendImageStorie", @@ -6571,7 +6571,7 @@ }, "/send-video-storie": { "post": { - "tags": ["Status"], + "tags": ["Status Stories"], "summary": "Send Video Storie ", "description": "Send Video Storie", "operationId": "SendVideoStorie", @@ -6682,7 +6682,7 @@ }, "/send-text-storie": { "post": { - "tags": ["Status"], + "tags": ["Status Stories"], "summary": "Send Text Storie ", "description": "Send Text Storie", "operationId": "SendTextStorie", @@ -6792,6 +6792,204 @@ "deprecated": false } }, + "/add-new-label": { + "post": { + "tags": ["Labels"], + "summary": "Add New Label", + "description": "Cria uma nova etiqueta", + "operationId": "AddNewLabel", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddNewLabelRequest" + }, + "example": { + "name": "Farmacias", + "options": { "labelColor": "#dfaef0" } + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": {} + }, + "400": { + "description": "Bad Request", + "headers": {}, + "content": {} + }, + "401": { + "description": "Unauthorized", + "headers": {}, + "content": {} + } + }, + "deprecated": false + } + }, + "/add-or-remove-label": { + "post": { + "tags": ["Labels"], + "summary": "Add or Remove Labels of chats", + "description": "Edita as etiquetas de seus chats", + "operationId": "AddOrRemoveLabelRequest", + "parameters": [], + "requestBody": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddOrRemoveLabelRequest" + }, + "example": { + "chatIds": ["5521988887878"], + "options": [ + { "labelId": "76", "type": "add" }, + { "labelId": "75", "type": "remove" } + ] + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "OK", + "headers": {}, + "content": {} + }, + "400": { + "description": "Bad Request", + "headers": {}, + "content": {} + }, + "401": { + "description": "Unauthorized", + "headers": {}, + "content": {} + } + }, + "deprecated": false + } + }, + + "/get-all-labels": { + "get": { + "tags": ["Labels"], + "summary": "All Labels", + "description": "Retrieves all labels", + "operationId": "AllLabels", + "parameters": [ + { + "name": "Content-Type", + "in": "header", + "description": "", + "required": true, + "style": "simple", + "schema": { + "type": "string", + "example": "application/json" + } + } + ], + "responses": { + "200": { + "description": "OK", + "headers": { + "X-Powered-By": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Express" + } + } + }, + "Access-Control-Allow-Origin": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "*" + } + } + }, + "Content-Length": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "253700" + } + } + }, + "ETag": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "W/\"3df04-fmRGRGQv4jrWL17uvMt/S9zRjmY\"" + } + } + }, + "Date": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "Thu, 13 May 2021 19:40:25 GMT" + } + } + }, + "Connection": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "keep-alive" + } + } + }, + "Keep-Alive": { + "content": { + "text/plain": { + "schema": { + "type": "string" + }, + "example": "timeout=5" + } + } + } + }, + "content": { + "application/json; charset=utf-8": { + "schema": { + "$ref": "#/components/schemas/AllChats" + }, + "example": { + "status": "success", + "response": [{}] + } + } + } + } + }, + "deprecated": false + } + }, "/subscribe-presence": { "post": { "tags": ["Contact"], @@ -17233,6 +17431,43 @@ "options": { "backgroundColor": "#0275d8", "font": 2 } } }, + "AddNewLabelRequest": { + "title": "AddNewLabelRequest", + "required": ["name"], + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "options": { + "type": "string" + } + }, + "example": { + "name": "Farmácia", + "options": { "labelColor": "#dfaef0" } + } + }, + "AddOrRemoveLabelRequest": { + "title": "AddOrRemoveLabelRequest", + "required": ["name", "options"], + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "options": { + "type": "string" + } + }, + "example": { + "chatIds": ["5521988887878"], + "options": [ + { "labelId": "76", "type": "add" }, + { "labelId": "75", "type": "remove" } + ] + } + }, "SubscribePresenceRequest": { "title": "SubscribePresenceRequest", "required": ["phone"], @@ -19314,6 +19549,10 @@ "name": "Status Stories", "description": "Status Stories Methods" }, + { + "name": "Labels", + "description": "Labels Methods" + }, { "name": "Contact", "description": "Contact Methods"