Skip to content

Commit 2394f82

Browse files
authored
refactor: renomeando tabelas, arquivos e subtituição de reclamacao por denuncia
Renomeando tabelas, métodos, variáveis e nomes de arquivos, substituindo "reclamacao" por "denuncias", seguindo as sugestões após card sorting. Padronização para nomes de arquivos e tabelas
2 parents bcb9280 + a9ef400 commit 2394f82

36 files changed

Lines changed: 198 additions & 200 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ O backend do SaneaSP foi hospedado na plataforma Render com conexão ao banco de
1515
- https://backend-saneasp.onrender.com/api-docs
1616

1717
### Endpoints do projeto:
18-
- https://backend-saneasp.onrender.com/reclamacao
18+
- https://backend-saneasp.onrender.com/denuncia
1919
- https://backend-saneasp.onrender.com/tag
2020
- https://backend-saneasp.onrender.com/user
2121

app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from "express";
22
import cors from 'cors'
33
import categoriaRoutes from "./src/routes/categoria.routes";
4-
import reclamacaoRoutes from "./src/routes/reclamacao.routes";
4+
import denunciaRoutes from "./src/routes/denuncia.routes";
55
import userRoutes from "./src/routes/user.routes";
66
import { authRoutes } from "./src/routes/auth.routes";
77
import { setupSwagger } from "./src/swagger/swagger";
@@ -15,7 +15,7 @@ app.use(cors()) //Habilita o CORS Cross-Origin resource sharing
1515
app.use(express.json());
1616

1717
app.use("/categoria", categoriaRoutes);
18-
app.use("/reclamacao", reclamacaoRoutes);
18+
app.use("/denuncia", denunciaRoutes);
1919
app.use("/user", userRoutes)
2020
app.use("/auth", authRoutes)
2121

migrations/20250423232245-create-table-reclamacao.js renamed to migrations/20250423232245-create-table-denuncia.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { DataTypes } = require('sequelize');
55
/** @type {import('sequelize-cli').Migration} */
66
module.exports = {
77
async up (queryInterface, Sequelize) {
8-
await queryInterface.createTable('reclamacao',
8+
await queryInterface.createTable('denuncia',
99
{
1010
id:{
1111
primaryKey:true,
@@ -67,6 +67,6 @@ module.exports = {
6767
},
6868

6969
async down (queryInterface, Sequelize) {
70-
await queryInterface.dropTable('reclamacao');
70+
await queryInterface.dropTable('denuncia');
7171
}
7272
};

migrations/20250522155150-create-table-categoriaReclamacao.js renamed to migrations/20250522155150-create-table-categoria-denuncia.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { DataTypes } = require('sequelize');
55
/** @type {import('sequelize-cli').Migration} */
66
module.exports = {
77
async up (queryInterface, Sequelize) {
8-
await queryInterface.createTable('categoriaReclamacao',
8+
await queryInterface.createTable('categoria_denuncia',
99
{
1010
id: {
1111
primaryKey: true,
@@ -19,17 +19,17 @@ module.exports = {
1919
references : {model : 'categoria', key : 'id'},
2020
onDelete : 'CASCADE'
2121
},
22-
id_reclamacao: {
22+
id_denuncia: {
2323
allowNull: false,
2424
type: DataTypes.INTEGER,
25-
references : {model : 'reclamacao', key : 'id'},
25+
references : {model : 'denuncia', key : 'id'},
2626
onDelete : 'CASCADE'
2727
},
2828
});
2929
},
3030

3131
async down (queryInterface, Sequelize) {
32-
await queryInterface.dropTable('categoriaReclamacao');
32+
await queryInterface.dropTable('categoria_denuncia');
3333
}
3434
};
3535

migrations/20250524164653-create-table-imagemReclamacao.js renamed to migrations/20250524164653-create-table-imagem-denuncia.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { DataTypes } = require('sequelize');
55
/** @type {import('sequelize-cli').Migration} */
66
module.exports = {
77
async up (queryInterface, Sequelize) {
8-
await queryInterface.createTable('imagemReclamacao',
8+
await queryInterface.createTable('imagem_denuncia',
99
{
1010
id: {
1111
primaryKey: true,
@@ -17,11 +17,11 @@ module.exports = {
1717
allowNull: false,
1818
type: DataTypes.STRING(100),
1919
},
20-
id_reclamacao: {
20+
id_denuncia: {
2121
allowNull: false,
2222
type: DataTypes.INTEGER,
2323
references: {
24-
model: 'reclamacao',
24+
model: 'denuncia',
2525
key: 'id'
2626
},
2727
onDelete: 'CASCADE'
@@ -30,6 +30,6 @@ module.exports = {
3030
},
3131

3232
async down (queryInterface, Sequelize) {
33-
await queryInterface.dropTable('imagemReclamacao');
33+
await queryInterface.dropTable('imagem_denuncia');
3434
}
3535
};

src/@types/express.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IUser } from '../interfaces/IUsuario.interface';
1+
import { IUser } from '../interfaces/usuario';
22
declare global{
33
namespace Express{
44
export interface Request{

src/controllers/auth.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotenv from "dotenv";
44
import bcrypt from "bcryptjs";
55
import { ApiError } from "../errors/ApiError.error";
66
import { HttpCode } from "../enums/HttpCode.enum";
7-
import { IUser } from "../interfaces/IUsuario.interface";
7+
import { IUser } from "../interfaces/usuario";
88
import { uniqueUserValidator } from "./user.controller";
99
dotenv.config();
1010

src/controllers/categoria-reclamacao.controller.ts renamed to src/controllers/categoria-denuncia.controller.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import { Op } from "sequelize";
2-
import { CategoriaModel, CategoriaReclamacaoModel } from "../models";
2+
import { CategoriaModel, CategoriaDenunciaModel } from "../models";
33
import { ApiError } from "../errors/ApiError.error";
44
import { HttpCode } from "../enums/HttpCode.enum";
55

6-
export const createCategoryReclamacao = async (categorias : number[], id_reclamacao : number) => {
6+
export const createCategoryDenuncia = async (categorias : number[], id_denuncia : number) => {
77
await categoryIdExistsValidator(categorias)
88

9-
await CategoriaReclamacaoModel.bulkCreate(categorias.map(id_categoria => ({
9+
await CategoriaDenunciaModel.bulkCreate(categorias.map(id_categoria => ({
1010
id_categoria,
11-
id_reclamacao,
11+
id_denuncia,
1212
})));
1313
}
1414

15-
export const updateCategoryReclamacao = async (updatedCategoriesIds : number[], id_reclamacao : number) => {
16-
const oldCategories = await CategoriaReclamacaoModel.findAll({where : {id_reclamacao}});
15+
export const updateCategoryDenuncia = async (updatedCategoriesIds : number[], id_denuncia : number) => {
16+
const oldCategories = await CategoriaDenunciaModel.findAll({where : {id_denuncia}});
1717
const oldCategoryIds = oldCategories.map(categorie => categorie.id_categoria);
1818

1919
/* Remove categorias que estavam atreladas e não existem mais no array de ids passados */
2020
const categoriesToRemove = oldCategoryIds.filter(categorie => !updatedCategoriesIds.includes(categorie))
2121
if(categoriesToRemove.length > 0){
22-
await CategoriaReclamacaoModel.destroy({
22+
await CategoriaDenunciaModel.destroy({
2323
where : {
2424
id_categoria : {
2525
[Op.in] : categoriesToRemove
2626
},
27-
id_reclamacao
27+
id_denuncia
2828
}
2929
})
3030
}
@@ -33,7 +33,7 @@ export const updateCategoryReclamacao = async (updatedCategoriesIds : number[],
3333
const categoriesToCreate = updatedCategoriesIds.filter(categorie => !oldCategoryIds.includes(categorie))
3434
/* Cria as novas categorias */
3535
if(categoriesToCreate.length > 0)
36-
await createCategoryReclamacao(categoriesToCreate, id_reclamacao);
36+
await createCategoryDenuncia(categoriesToCreate, id_denuncia);
3737
}
3838

3939
export const categoryIdExistsValidator = async (categories : number[]) => {

src/controllers/categoria.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ICategoria } from "../interfaces/ICategoria.interface";
2-
import { ICategoriaListFilter } from "../interfaces/ICategoriaListFilter.interface";
1+
import { ICategoriaListFilter } from "../interfaces/categoria-list-filter";
32
import { CategoriaModel } from "../models/categoria.model";
43
import { FindOptions, Op } from "sequelize";
54
import { ApiError } from "../errors/ApiError.error";
65
import { HttpCode } from "../enums/HttpCode.enum";
6+
import { ICategoria } from "../interfaces/categoria";
77

88
export const getCategoriaList = async (categoriaFilter : ICategoriaListFilter) : Promise<ICategoria[]> => {
99
const {nome, limit} = categoriaFilter;
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { ICreateReclamacao, IFilterListReclamacao, IReclamacao } from "../interfaces/IReclamacao.interface";
1+
import { ICreateDenuncia, IFilterListDenuncia, IDenuncia } from "../interfaces/denuncia";
22
import { Op} from "sequelize";
3-
import { CategoriaModel, ImagemReclamacaoModel, ReclamacaoModel} from "../models";
4-
import { createCategoryReclamacao, updateCategoryReclamacao } from "./categoria-reclamacao.controller";
5-
import { createImagemReclamacao, updateImagemReclamacao } from "./imagem-reclamacao.controller";
3+
import { CategoriaModel, ImagemDenunciaModel, DenunciaModel} from "../models";
4+
import { createCategoryDenuncia, updateCategoryDenuncia } from "./categoria-denuncia.controller";
5+
import { createImagemDenuncia, updateImagemDenuncia } from "./imagem-denuncia.controller";
66
import { ApiError } from "../errors/ApiError.error";
77
import { HttpCode } from "../enums/HttpCode.enum";
88

9-
const reclamacaoFindIncludes = [
9+
const denunciaFindIncludes = [
1010
{
1111
//Trazer as categorias da reclamação
1212
model: CategoriaModel,
1313
as: 'Categorias',
14-
through: { attributes: [] } //Para dados da tabela associativa CategoriaReclamacoes nao vierem juntos do resultado
14+
through: { attributes: [] } //Para dados da tabela associativa CategoriaDenuncias nao vierem juntos do resultado
1515
},
1616
{
1717
//Trazer as imagens da reclamação
18-
model: ImagemReclamacaoModel,
18+
model: ImagemDenunciaModel,
1919
as: 'Imagens',
20-
attributes: {exclude : ['id_reclamacao']},
20+
attributes: {exclude : ['id_denuncia']},
2121
}
2222
]
2323

24-
export const getAllReclamacoes = async (filtros : IFilterListReclamacao): Promise<IReclamacao[]> =>{
24+
export const getAllDenuncias = async (filtros : IFilterListDenuncia): Promise<IDenuncia[]> =>{
2525
let query: any = {
2626
where : {},
27-
include: reclamacaoFindIncludes
27+
include: denunciaFindIncludes
2828
}
2929
if(filtros){
3030
if (filtros.titulo) {
@@ -69,21 +69,21 @@ export const getAllReclamacoes = async (filtros : IFilterListReclamacao): Promis
6969
}
7070
}
7171
}
72-
const reclamacoes = await ReclamacaoModel.findAll(query);
73-
return reclamacoes
72+
const denuncias = await DenunciaModel.findAll(query);
73+
return denuncias
7474
};
7575

76-
export const getById = async (idReclamacao: number): Promise<IReclamacao | null> =>{
77-
const reclamacao = await ReclamacaoModel.findOne(
76+
export const getById = async (idDenuncia: number): Promise<IDenuncia | null> =>{
77+
const denuncia = await DenunciaModel.findOne(
7878
{
79-
where:{id : idReclamacao},
80-
include: reclamacaoFindIncludes
79+
where:{id : idDenuncia},
80+
include: denunciaFindIncludes
8181
});
8282

83-
if(!reclamacao)
83+
if(!denuncia)
8484
throw new ApiError("Nenhuma reclamação encontrada", HttpCode.NotFound)
8585

86-
return reclamacao;
86+
return denuncia;
8787
}
8888
export const getByCategoria = async(categorias:number[], idUsuario?: number)=>{
8989
let query: any = {
@@ -104,51 +104,51 @@ export const getByCategoria = async(categorias:number[], idUsuario?: number)=>{
104104
},
105105
{
106106
//Trazer as imagens da reclamação
107-
model: ImagemReclamacaoModel,
107+
model: ImagemDenunciaModel,
108108
as: 'Imagens',
109-
attributes: {exclude : ['id_reclamacao']},
109+
attributes: {exclude : ['id_denuncia']},
110110
}
111111
]
112112
};
113113
if(idUsuario){
114114
query.where.idUsuario = idUsuario
115115
}
116-
const reclamacoes = await ReclamacaoModel.findAll(query);
117-
return reclamacoes
116+
const denuncias = await DenunciaModel.findAll(query);
117+
return denuncias
118118
}
119119
export const getByUsuario = async(fkUsuario: number)=>{
120-
const reclamacoes = await ReclamacaoModel.findAll({
120+
const denuncias = await DenunciaModel.findAll({
121121
where:{idUsuario:fkUsuario},
122-
include: reclamacaoFindIncludes
122+
include: denunciaFindIncludes
123123
})
124-
return reclamacoes;
124+
return denuncias;
125125
}
126-
export const postReclamacao = async (body : ICreateReclamacao):Promise<IReclamacao | null> => {
127-
const {Categorias, Imagens, ...reclamacaoBody} = body;
126+
export const postDenuncia = async (body : ICreateDenuncia):Promise<IDenuncia | null> => {
127+
const {Categorias, Imagens, ...denunciaBody} = body;
128128

129129
const pontuacao = gerarPontuacao(body);
130130

131-
const newReclamacao = {
131+
const newDenuncia = {
132132
status: 0,
133133
pontuacao,
134134
data: new Date(),
135-
...reclamacaoBody
135+
...denunciaBody
136136
};
137137

138138
//Cria reclamação
139-
const reclamacao = await ReclamacaoModel.create(newReclamacao);
139+
const denuncia = await DenunciaModel.create(newDenuncia);
140140

141141
if(Imagens && Imagens.length > 0){
142-
await createImagemReclamacao(Imagens, reclamacao.id);
142+
await createImagemDenuncia(Imagens, denuncia.id);
143143
}
144144

145145
// Criando registro de associação
146146
if(Categorias && Categorias.length > 0)
147-
await createCategoryReclamacao(Categorias, reclamacao.id)
147+
await createCategoryDenuncia(Categorias, denuncia.id)
148148

149-
const response = await ReclamacaoModel.findByPk(reclamacao.id,
149+
const response = await DenunciaModel.findByPk(denuncia.id,
150150
{
151-
include: reclamacaoFindIncludes
151+
include: denunciaFindIncludes
152152
})
153153

154154
if(!response)
@@ -157,24 +157,24 @@ export const postReclamacao = async (body : ICreateReclamacao):Promise<IReclamac
157157
return response
158158
}
159159

160-
export const putReclamacao = async(idReclamacao : number, body: IReclamacao):Promise<IReclamacao> => {
160+
export const putDenuncia = async(idDenuncia : number, body: IDenuncia):Promise<IDenuncia> => {
161161
body.pontuacao = gerarPontuacao(body);
162162

163-
await ReclamacaoModel.update(body, {
163+
await DenunciaModel.update(body, {
164164
where :{
165-
id: idReclamacao
165+
id: idDenuncia
166166
}
167167
})
168168

169169
if(body.Categorias)
170-
await updateCategoryReclamacao(body.Categorias, idReclamacao);
170+
await updateCategoryDenuncia(body.Categorias, idDenuncia);
171171

172172
if(body.Imagens){
173-
await updateImagemReclamacao(body.Imagens, idReclamacao)
173+
await updateImagemDenuncia(body.Imagens, idDenuncia)
174174
}
175175

176-
const response = await ReclamacaoModel.findByPk(idReclamacao, {
177-
include: reclamacaoFindIncludes
176+
const response = await DenunciaModel.findByPk(idDenuncia, {
177+
include: denunciaFindIncludes
178178
})
179179

180180
if(!response){
@@ -184,22 +184,22 @@ export const putReclamacao = async(idReclamacao : number, body: IReclamacao):Pro
184184
return response
185185
}
186186

187-
export const deleteReclamacao = async(idReclamacao : number): Promise<IReclamacao> => {
188-
const reclamacao = await ReclamacaoModel.findByPk(idReclamacao, {
189-
include: reclamacaoFindIncludes
187+
export const deleteDenuncia = async(idDenuncia : number): Promise<IDenuncia> => {
188+
const denuncia = await DenunciaModel.findByPk(idDenuncia, {
189+
include: denunciaFindIncludes
190190
});
191191

192-
if(!reclamacao){
192+
if(!denuncia){
193193
throw new ApiError("Reclamação não encontrada", HttpCode.NotFound)
194194
}
195195

196196
//Associações com categorias e reclamações são excluidas com cascade
197-
await reclamacao.destroy();
197+
await denuncia.destroy();
198198

199-
return reclamacao
199+
return denuncia
200200
}
201201

202-
function gerarPontuacao(bodyRequest : ICreateReclamacao | IReclamacao): number {
202+
function gerarPontuacao(bodyRequest : ICreateDenuncia | IDenuncia): number {
203203
let pontuacao = 0;
204204
// por enquanto a pontuação de categoria vai ser pela quantidade de categorias adicionadas nas reclamações
205205
if(bodyRequest.Imagens && bodyRequest.Imagens?.length > 0){

0 commit comments

Comments
 (0)