1- import { ICreateReclamacao , IFilterListReclamacao , IReclamacao } from "../interfaces/IReclamacao.interface " ;
1+ import { ICreateDenuncia , IFilterListDenuncia , IDenuncia } from "../interfaces/denuncia " ;
22import { 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" ;
66import { ApiError } from "../errors/ApiError.error" ;
77import { 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}
8888export 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}
119119export 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