From 5de3c7d4efaabef98828a08ef077887bbf8d5925 Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Mon, 23 Mar 2026 22:02:10 -0300 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20adicionando=20novos=20campos=20de?= =?UTF-8?q?=20filtragem=20na=20listagem=20de=20tombos=20por=20coletor=20e?= =?UTF-8?q?=20n=C3=BAmero=20da=20coleta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/tombos-controller.js | 8 ++++++++ src/validators/tombo-listagem.js | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/controllers/tombos-controller.js b/src/controllers/tombos-controller.js index 552831c6..de48bd89 100644 --- a/src/controllers/tombos-controller.js +++ b/src/controllers/tombos-controller.js @@ -687,6 +687,8 @@ export const listagem = (request, response, next) => { nome_popular: nomePopular, situacao, codigo_barra_foto, + coletor_id: coletorId, + numero_coleta: numeroColeta, } = request.query; let where = { @@ -708,6 +710,12 @@ export const listagem = (request, response, next) => { if (situacao) { where.situacao = situacao; } + if (coletorId) { + where.coletor_id = coletorId; + } + if (numeroColeta) { + where.numero_coleta = numeroColeta; + } let include = [ { diff --git a/src/validators/tombo-listagem.js b/src/validators/tombo-listagem.js index 3d6a88c0..80d39a00 100644 --- a/src/validators/tombo-listagem.js +++ b/src/validators/tombo-listagem.js @@ -40,6 +40,11 @@ export default { isInt: true, optional: true, }, + codigo_barra_foto: { + in: 'query', + isString: true, + optional: true, + }, limite: { in: 'query', isInt: true, @@ -50,4 +55,14 @@ export default { isInt: true, optional: true, }, + coletor_id: { + in: 'query', + isInt: true, + optional: true, + }, + numero_coleta: { + in: 'query', + isInt: true, + optional: true, + }, }; From 9fda80203ad64c119e3eed392c9566191db29deb Mon Sep 17 00:00:00 2001 From: Lucas Vaz Date: Tue, 24 Mar 2026 20:38:51 -0300 Subject: [PATCH 2/2] Feat: adicionando rota de busca de numeros de coleta de um coletor. --- src/controllers/coletor-controller.js | 31 +++++++++++++++++++++ src/routes/coletor.js | 40 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/controllers/coletor-controller.js b/src/controllers/coletor-controller.js index a8834f21..6af403ce 100644 --- a/src/controllers/coletor-controller.js +++ b/src/controllers/coletor-controller.js @@ -117,3 +117,34 @@ export const desativaColetor = async (req, res, next) => { next(error); } }; + +export const listaNumerosColetaPorColetor = async (req, res, next) => { + try { + const { coletorId } = req.params; + const { Tombo } = models; + const coletor = await Coletor.findByPk(coletorId); + if (!coletor) { + return res.status(404).json({ mensagem: 'Coletor não encontrado.' }); + } + const numerosColeta = await Tombo.findAll({ + attributes: ['numero_coleta'], + where: { + coletor_id: coletorId, + rascunho: false, + numero_coleta: { [Op.not]: null }, + }, + raw: true, + order: [['numero_coleta', 'ASC']], + }); + const numerosUnicos = [...new Set(numerosColeta.map(item => item.numero_coleta))].map((numero, index) => ({ + id: index, + numero, + })); + + res.status(200).json({ + numerosColeta: numerosUnicos, + }); + } catch (error) { + next(error); + } +}; diff --git a/src/routes/coletor.js b/src/routes/coletor.js index 3dbd0056..d3b2a336 100644 --- a/src/routes/coletor.js +++ b/src/routes/coletor.js @@ -303,4 +303,44 @@ export default app => { validacoesMiddleware(desativarColetorEsquema), coletoresController.desativaColetor, ]); + + /** + * @swagger + * /coletores/{coletorId}/numeros-coleta: + * get: + * summary: Lista números de coleta de um coletor + * tags: [Coletores] + * description: Retorna uma lista dos números de coleta cadastrados para um coletor específico. + * parameters: + * - in: path + * name: coletorId + * required: true + * schema: + * type: integer + * description: ID do coletor + * responses: + * 200: + * description: Lista de números de coleta do coletor + * content: + * application/json: + * schema: + * type: object + * properties: + * numerosColeta: + * type: array + * items: + * type: object + * properties: + * id: + * type: integer + * numero: + * type: integer + * '404': + * $ref: '#/components/responses/NotFound' + * '500': + * $ref: '#/components/responses/InternalServerError' + */ + app.route('/coletores/:coletorId/numeros-coleta').get([ + coletoresController.listaNumerosColetaPorColetor, + ]); };