Skip to content

Commit

Permalink
feat: Added routes to manage labels
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 19, 2022
1 parent c77d6b6 commit 25f21c0
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 3 deletions.
57 changes: 57 additions & 0 deletions 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.' });
}
}
8 changes: 8 additions & 0 deletions src/routes/index.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
245 changes: 242 additions & 3 deletions src/swagger.json
Expand Up @@ -6460,7 +6460,7 @@
},
"/send-image-storie": {
"post": {
"tags": ["Status"],
"tags": ["Status Stories"],
"summary": "Send Image Storie ",
"description": "Send Image Storie",
"operationId": "SendImageStorie",
Expand Down Expand Up @@ -6571,7 +6571,7 @@
},
"/send-video-storie": {
"post": {
"tags": ["Status"],
"tags": ["Status Stories"],
"summary": "Send Video Storie ",
"description": "Send Video Storie",
"operationId": "SendVideoStorie",
Expand Down Expand Up @@ -6682,7 +6682,7 @@
},
"/send-text-storie": {
"post": {
"tags": ["Status"],
"tags": ["Status Stories"],
"summary": "Send Text Storie ",
"description": "Send Text Storie",
"operationId": "SendTextStorie",
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -19314,6 +19549,10 @@
"name": "Status Stories",
"description": "Status Stories Methods"
},
{
"name": "Labels",
"description": "Labels Methods"
},
{
"name": "Contact",
"description": "Contact Methods"
Expand Down

0 comments on commit 25f21c0

Please sign in to comment.