From 51a7bac24cb673fbc1e50b13c164e81cc8479f0a Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Thu, 11 Nov 2021 21:23:12 -0300 Subject: [PATCH 01/13] change filter to case-insensitive fga-eps-mds/2021.1-Oraculo#218 --- src/Controller/RecordController.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index fac7c32..3ae941b 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -4,7 +4,6 @@ const History = require("../Model/History"); const { User } = require("../Model/User"); const { Situation } = require("../Model/Situation"); const { Tag } = require("../Model/Tag"); - const { ERR_RECORD_NOT_FOUND, ERR_NO_ERROR, @@ -157,14 +156,14 @@ async function getRecordsByPage(req, res) { Object.entries(_where).forEach(([key, value]) => { filters[key] = { - [Op.like]: "%" + value + "%" + [Op.iLike]: "%" + value + "%" } }); if(history) { historyFields.forEach((item) => { historyFilters.push({[item]: { - [Op.like]: "%" + history + "%" + [Op.iLike]: "%" + history + "%" }}) }); } From 064c2f822253a820cd4e94deef7853385db8a5a6 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Thu, 11 Nov 2021 23:12:51 -0300 Subject: [PATCH 02/13] add tag filter fga-eps-mds/2021.1-Oraculo#223 --- src/Controller/RecordController.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 3ae941b..f5b4686 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -149,10 +149,16 @@ async function getRecordsByPage(req, res) { 'reason' ] - const { exact = {}, history, ..._where } = where || {}; + const tagFields = [ + 'name', + 'color' + ] + + const { history, tag, ..._where } = where || {}; let filters = {}; const historyFilters = []; + const tagFilters = []; Object.entries(_where).forEach(([key, value]) => { filters[key] = { @@ -168,11 +174,18 @@ async function getRecordsByPage(req, res) { }); } - filters = { ...exact, ...filters }; + if(tag) { + tagFields.forEach((item) => { + tagFilters.push({[item]: { + [Op.iLike]: "%" + tag + "%" + }}) + }); + } const { rows, count } = await Record.findAndCountAll({ include: [{ model: History, as: 'histories', ...(history && { where: { [Op.or]: historyFilters }})}, - { model: Department, as: 'departments', ...(department_id && { where: { id: department_id}})}], + { model: Tag, as: 'tags', ...(tag && { where: { [Op.or]: tagFilters }})}, + { model: Department, as: 'departments', ...(department_id && { where: { id: department_id}})}], where: filters, limit: itemsPerPage, order: [['register_number', 'ASC']], From 59b39bf959b19bf41d1207f6e43db83c81a5023e Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 00:45:43 -0300 Subject: [PATCH 03/13] add tag to body of create record fga-eps-mds/2021.1-Oraculo#37 Co-authored-by: ericoBandeira --- src/Controller/RecordController.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 3ae941b..45c082b 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -78,6 +78,7 @@ async function createRecord(req, res) { receipt_form, contact_info, created_by, + tags = [] } = req.body); try { @@ -119,7 +120,7 @@ async function createRecord(req, res) { const tag = await Tag.findOne({ where: { name: "Tramitar" } }); await createdRecord.setDepartments([department]); - await createdRecord.setTags([tag]); + await createdRecord.setTags([tag, ...tags]); await History.create(history); From e815cc7787a6a855a6698f7657d53eac453ad16d Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:33:50 -0300 Subject: [PATCH 04/13] fix code smells fga-eps-mds/2021.1-Oraculo#223 --- src/Controller/RecordController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index f5b4686..858bdb8 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -162,14 +162,14 @@ async function getRecordsByPage(req, res) { Object.entries(_where).forEach(([key, value]) => { filters[key] = { - [Op.iLike]: "%" + value + "%" + [Op.iLike]: `%${value}%` } }); - + `%${tag}%` if(history) { historyFields.forEach((item) => { historyFilters.push({[item]: { - [Op.iLike]: "%" + history + "%" + [Op.iLike]: `%${history}%` }}) }); } @@ -177,7 +177,7 @@ async function getRecordsByPage(req, res) { if(tag) { tagFields.forEach((item) => { tagFilters.push({[item]: { - [Op.iLike]: "%" + tag + "%" + [Op.iLike]: `%${tag}%` }}) }); } From 0a050f38ae3398df0681b4a01d179e8ed589adcd Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:37:08 -0300 Subject: [PATCH 05/13] solve code smells fga-eps-mds/2021.1-Oraculo#37 --- src/Controller/RecordController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 45c082b..871afa4 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -78,7 +78,7 @@ async function createRecord(req, res) { receipt_form, contact_info, created_by, - tags = [] + tags } = req.body); try { From 4d46230bd130e88ffa17de446a6ea271e46153e1 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:41:01 -0300 Subject: [PATCH 06/13] fix bug fga-eps-mds/2021.1-Oraculo#223 --- src/Controller/RecordController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 858bdb8..9c74294 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -165,7 +165,7 @@ async function getRecordsByPage(req, res) { [Op.iLike]: `%${value}%` } }); - `%${tag}%` + if(history) { historyFields.forEach((item) => { historyFilters.push({[item]: { From 6d4dd7cbc0f43bb4950e1cb517f392bb05944a0f Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:45:04 -0300 Subject: [PATCH 07/13] fix createRecord tests fga-eps-mds/2021.1-Oraculo#37 --- tests/index.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/index.test.js b/tests/index.test.js index 57f909c..ec429e1 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -14,6 +14,7 @@ const validRecord1 = { receipt_form: "form", contact_info: "info@gmail.com", created_by: "william@pcgo.com", + tags: [] }; const validRecord2 = { @@ -29,6 +30,7 @@ const validRecord2 = { contact_info: "info@gmail.com", situation: 2, created_by: "william@pcgo.com", + tags: [] }; const invalidRecord1 = { From 69c44f96f7f602f826621feb4ff0a7784c17ac68 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:56:11 -0300 Subject: [PATCH 08/13] fix code smells fga-eps-mds/2021.1-Oraculo#223 --- src/Controller/RecordController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 9c74294..6adff7b 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -156,7 +156,7 @@ async function getRecordsByPage(req, res) { const { history, tag, ..._where } = where || {}; - let filters = {}; + const filters = {}; const historyFilters = []; const tagFilters = []; From bdfafb874b140b13d78ee6edc81a77ac11d19ef6 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 01:52:28 -0300 Subject: [PATCH 09/13] add tag to edit record fga-eps-mds/2021.1-Oraculo#229 --- src/Controller/RecordController.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 5e1ee28..0999499 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -442,6 +442,7 @@ async function editRecord(req, res) { sei_number, receipt_form, contact_info, + tags } = req.body); try { @@ -465,6 +466,7 @@ async function editRecord(req, res) { await record.save(); const editedRecord = await Record.findByPk(recordID); + await editedRecord.setTags(tags); return res.status(200).json(editedRecord); } catch (err) { From a9e2be3dbe6c3966d4a4c975f3d114ecab1183a1 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 02:09:12 -0300 Subject: [PATCH 10/13] remove default tag from createRecord fga-eps-mds/2021.1-Oraculo#229 --- src/Controller/RecordController.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Controller/RecordController.js b/src/Controller/RecordController.js index 0999499..6a1eb53 100644 --- a/src/Controller/RecordController.js +++ b/src/Controller/RecordController.js @@ -118,9 +118,8 @@ async function createRecord(req, res) { record_id: createdRecord.id, }; - const tag = await Tag.findOne({ where: { name: "Tramitar" } }); await createdRecord.setDepartments([department]); - await createdRecord.setTags([tag, ...tags]); + await createdRecord.setTags(tags); await History.create(history); From 6a0b73249f8dad5865ef5767fdb7bf72d5b6d941 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 02:39:01 -0300 Subject: [PATCH 11/13] fix editRecord tests fga-eps-mds/2021.1-Oraculo#229 --- tests/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/index.test.js b/tests/index.test.js index ec429e1..d2b2336 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -356,7 +356,7 @@ describe("Main test", () => { it("POST /records/:id/edit - should edit a record", async () => { const res = await request(app) .post("/records/1/edit") - .send({ city: "Goiania" }); + .send({ city: "Goiania", tags: [] }); expect(res.statusCode).toEqual(200); expect(res.body).toBeDefined(); }); From 50761ddca80879f2b2013949f49f78896241ac86 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 02:52:51 -0300 Subject: [PATCH 12/13] fix getRecordTags tests fga-eps-mds/2021.1-Oraculo#229 Co-authored-by: ericoBandeira --- tests/index.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/index.test.js b/tests/index.test.js index d2b2336..054d61d 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -104,7 +104,10 @@ describe("Main test", () => { const res1 = await request(app).post("/records").send(validRecord1); expect(res1.statusCode).toEqual(200); - const res = await request(app).get("/records/1/tags"); + const res2 = await request(app).post(`/records/${res1.body.id}/add-tag`).send({ tag_id: 1 }); + expect(res2.statusCode).toEqual(200); + + const res = await request(app).get(`/records/${res1.body.id}/tags`); expect(res.statusCode).toEqual(200); }); @@ -326,7 +329,7 @@ describe("Main test", () => { it("GET /records/1/tags - should list tags of a record (empty tags)", async () => { const res = await request(app).get("/records/1/tags"); - expect(res.statusCode).toEqual(200); + expect(res.statusCode).toEqual(204); }); it("POST /records/:id/add-tag - should add tag 1 to record 1", async () => { From 898f3139f8d589e566464b397d398915f8ad1bb2 Mon Sep 17 00:00:00 2001 From: joao vitor silva Date: Fri, 12 Nov 2021 02:56:13 -0300 Subject: [PATCH 13/13] fix getRecordTags tests fga-eps-mds/2021.1-Oraculo#229 Co-authored-by: ericoBandeira --- tests/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/index.test.js b/tests/index.test.js index 054d61d..897d180 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -327,9 +327,9 @@ describe("Main test", () => { expect(res.body.message).toBeDefined(); }); - it("GET /records/1/tags - should list tags of a record (empty tags)", async () => { + it("GET /records/:id/tags - should list tags of a record (empty tags)", async () => { const res = await request(app).get("/records/1/tags"); - expect(res.statusCode).toEqual(204); + expect(res.statusCode).toEqual(200); }); it("POST /records/:id/add-tag - should add tag 1 to record 1", async () => {