Skip to content

Commit 6e36166

Browse files
authored
Merge pull request RyanCNP#94 from RyanCNP/refactor/feedback
Refactor/feedback
2 parents 96901d4 + 31840f6 commit 6e36166

10 files changed

Lines changed: 288 additions & 204 deletions

File tree

app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import locationRoutes from "./src/routes/location.routes"
99
import { authRoutes } from "./src/routes/auth.routes";
1010
import graphRoutes from "./src/routes/graph.routes";
1111
import uploadRoutes from "./src/routes/upload.routes";
12-
//import feedbackRoutes from "./src/routes/feedback.routes";
12+
import feedbackRoutes from "./src/routes/feedback.routes";
1313
import registroRoutes from "./src/routes/registro.routes";
1414
import { setupSwagger } from "./src/swagger/swagger";
1515
import { errorHandler } from "./src/middlewares/errorHandler.middleware";
@@ -40,8 +40,7 @@ app.use('/upload',uploadRoutes);
4040
app.use("/location",locationRoutes);
4141
app.use('/visitas', VisitasRoutes);
4242
app.use('/api/stripe', stripeRoutes);
43-
//app.use("/feedback", feedbackRoutes);
44-
app.use("/comentario", comentarioRoutes);
43+
app.use("/feedback", feedbackRoutes);
4544
app.use("/registro", registroRoutes);
4645

4746
// Acesso público às imagens

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controllers/denuncia.controller.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { createCategoryDenuncia, updateCategoryDenuncia } from "../services/cate
1515
import { getImagesByComplaintId } from "../services/imagem-denuncia.service"
1616
import { removeFiles } from "../config/multer.config"
1717
import { UploadSubfolder } from "../enums/UploadSubFolder.enum"
18+
import { findDenunciaFeedbackById, deleteDenunciaFeedback } from "../services/feedback.service"
1819

1920
export const getAllDenuncias = async (req: Request, res: Response) => {
2021
const query: IFilterListDenuncia = req.query
@@ -30,7 +31,7 @@ export const getById = async (req: Request, res: Response) => {
3031

3132
export const getUserComplaint = async (req: Request, res: Response) => {
3233
const idUsuario = req.user.id as number
33-
const filter : IFilterListDenuncia = req.query
34+
const filter: IFilterListDenuncia = req.query
3435
const denuncias = await findUserComplaint(idUsuario, filter)
3536
res.status(200).json(denuncias)
3637
}
@@ -97,7 +98,7 @@ export const putDenuncia = async (req: Request, res: Response) => {
9798
}
9899

99100
if (body.imagens && body.imagens.length > 0) {
100-
let files:string[] = body.imagens;
101+
let files: string[] = body.imagens;
101102
const images = await getImagesByComplaintId(id)
102103
await removeFiles(images.map(img => img.nome), UploadSubfolder.Denuncias);
103104
await createImagemDenuncia(files, id)
@@ -112,14 +113,16 @@ export const deleteDenuncia = async (req: Request, res: Response) => {
112113

113114
const denuncia = await findDenunciaById(idDenuncia)
114115
const imagens = await getImagesByComplaintId(idDenuncia);
116+
const feedback = await findDenunciaFeedbackById(idDenuncia);
115117
await removeFiles(imagens.map(img => img.nome), UploadSubfolder.Denuncias);
116118
await deleteDenunciaById(idDenuncia)
119+
await deleteDenunciaFeedback(feedback.id)
117120

118121
res.status(200).json(denuncia)
119122
}
120123

121-
export const exportExcel = async (req : Request, res : Response) => {
122-
try {
124+
export const exportExcel = async (req: Request, res: Response) => {
125+
try {
123126
const buffer = await exportDenunciasExcel(); // chama a função do controller
124127

125128
res.setHeader(
Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
1-
// import type { Request, Response } from "express"
2-
// import type { ICreateDenunciaFeedback, ICreateInterfaceFeedback } from "../interfaces/feedback"
3-
// import * as feedbackService from "../services/feedback.service"
4-
// import { ApiError } from "../errors/ApiError.error"
5-
// import { HttpCode } from "../enums/HttpCode.enum"
6-
7-
// export const getAllDenunciaFeedbacks = async (req: Request, res: Response) => {
8-
// const feedbacks = await feedbackService.findAllFeedbacks()
9-
// res.status(200).json(feedbacks)
10-
// }
11-
12-
// export const getAllInterfaceFeedbacks = async (req: Request, res: Response) => {
13-
// const feedbacks = await feedbackService.findAllInterfaceFeedbacks()
14-
// res.status(200).json(feedbacks)
15-
// }
16-
17-
// export const postDenunciaFeedback = async (req: Request, res: Response) => {
18-
// const feedback: ICreateDenunciaFeedback = req.body
19-
// const newFeedback = await feedbackService.createDenunciaFeedback(feedback)
20-
// res.status(201).json(newFeedback)
21-
// }
22-
23-
// export const postInterfaceFeedback = async (req: Request, res: Response) => {
24-
// const feedback: ICreateInterfaceFeedback = req.body
25-
// const newFeedback = await feedbackService.createInterfaceFeedback(feedback)
26-
// res.status(201).json(newFeedback)
27-
// }
28-
29-
// export const deleteFeedback = async (req: Request, res: Response) => {
30-
// const { id } = req.params
31-
// const deletedFeedback = await feedbackService.deleteFeedback(Number(id))
32-
// res.status(200).json(deletedFeedback)
33-
// }
1+
import type { Request, Response } from "express"
2+
import type { ICreateInterfaceFeedback, TDenunciaFeedbackCreate } from "../interfaces/feedback"
3+
import * as feedbackService from "../services/feedback.service"
4+
import { FeedbackInterface } from "../enums/FeedbackInterface.enum"
5+
6+
export const getAllDenunciaFeedbacks = async (req: Request, res: Response) => {
7+
try {
8+
const feedbacks = await feedbackService.findAllDenunciaFeedbacks();
9+
res.status(200).json(feedbacks);
10+
} catch (error) {
11+
console.error("Erro ao buscar feedbacks de denúncia:", error);
12+
res.status(500).json({ message: "Erro interno no servidor." });
13+
}
14+
};
15+
16+
export const getDenunciaFeedbackById = async (req: Request, res: Response) => {
17+
const { id } = req.params
18+
const feedback = await feedbackService.findDenunciaFeedbackById(Number(id))
19+
res.status(200).json(feedback)
20+
}
21+
22+
export const getDenunciaFeedbackByDenunciaId = async (req: Request, res: Response) => {
23+
const { id } = req.params
24+
const feedback = await feedbackService.findDenunciaFeedbackByDenunciaId(Number(id))
25+
res.status(200).json(feedback)
26+
}
27+
28+
29+
export const getAllInterfaceFeedbacks = async (req: Request, res: Response) => {
30+
const feedbacks = await feedbackService.findAllInterfaceFeedbacks()
31+
res.status(200).json(feedbacks)
32+
}
33+
34+
export const getInterfaceFeedbacksByTela = async (req: Request, res: Response) => {
35+
const { tela } = req.params
36+
const feedback = await feedbackService.findAllInterfaceFeedbacksByTela(tela as FeedbackInterface)
37+
res.status(200).json(feedback)
38+
}
39+
40+
export const postDenunciaFeedback = async (req: Request, res: Response) => {
41+
const {descricao, fk_denuncia } = req.body as TDenunciaFeedbackCreate
42+
const toCreate : TDenunciaFeedbackCreate = {descricao, fk_denuncia}
43+
const newFeedback = await feedbackService.createDenunciaFeedback(toCreate)
44+
res.status(201).json(newFeedback)
45+
}
46+
47+
export const postInterfaceFeedback = async (req: Request, res: Response) => {
48+
const feedback: ICreateInterfaceFeedback = req.body
49+
const newFeedback = await feedbackService.createInterfaceFeedback(feedback)
50+
res.status(201).json(newFeedback)
51+
}
52+
53+
export const deleteInterfaceFeedback = async (req: Request, res: Response) => {
54+
const { id } = req.params
55+
const deletedFeedback = await feedbackService.deleteInterfaceFeedback(Number(id))
56+
res.status(200).json(deletedFeedback)
57+
}

src/interfaces/feedback.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
// import { FeedbackInterface } from "../enums/FeedbackInterface.enum"
1+
import { FeedbackInterface } from "../enums/FeedbackInterface.enum"
22

3-
// export interface IDenunciaFeedback {
4-
// id: number,
5-
// data_publicacao: Date,
6-
// descricao: string,
7-
// fk_denuncia: number
8-
// }
3+
export interface IDenunciaFeedback {
4+
id: number,
5+
data_publicacao: Date,
6+
descricao: string,
7+
fk_denuncia: number
8+
}
99

10-
// export interface ICreateDenunciaFeedback {
11-
// data_publicacao: Date,
12-
// descricao: string,
13-
// fk_denuncia: number
14-
// }
10+
export type TDenunciaFeedbackCreate = Pick<IDenunciaFeedback, 'descricao' | 'fk_denuncia'>
1511

16-
// export interface IInterfaceFeedback {
17-
// id: number,
18-
// data_publicacao: Date,
19-
// descricao: string,
20-
// tela: FeedbackInterface,
21-
// }
12+
export interface IInterfaceFeedback {
13+
id: number,
14+
data_publicacao: Date,
15+
descricao: string,
16+
tela: FeedbackInterface,
17+
}
2218

23-
// export interface ICreateInterfaceFeedback {
24-
// data_publicacao: Date,
25-
// descricao: string,
26-
// tela: FeedbackInterface,
27-
// }
19+
export interface ICreateInterfaceFeedback {
20+
data_publicacao: Date,
21+
descricao: string,
22+
tela: FeedbackInterface,
23+
}

src/models/denuncia.model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,4 @@ DenunciaModel.init(
9898
sequelize,
9999
timestamps: false
100100
}
101-
);
102-
101+
);

src/models/feedback.model.ts

Lines changed: 82 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,87 @@
1-
// import { DataTypes, Model, Optional } from "sequelize";
2-
// import sequelize from "../config/database.config";
3-
// import { IDenunciaFeedback, IInterfaceFeedback } from "../interfaces/feedback";
4-
// import { FeedbackInterface } from "../enums/FeedbackInterface.enum";
1+
import { DataTypes, Model, Optional } from "sequelize";
2+
import sequelize from "../config/database.config";
3+
import { IDenunciaFeedback, IInterfaceFeedback } from "../interfaces/feedback";
4+
import { FeedbackInterface } from "../enums/FeedbackInterface.enum";
55

6-
// type DenunciaFeedbackCreationalAttributes = Optional<IDenunciaFeedback, "id">
7-
// type InterfaceFeedbackCreationalAttributes = Optional<IInterfaceFeedback, "id">
6+
type DenunciaFeedbackCreationalAttributes = Optional<IDenunciaFeedback, "id" | 'data_publicacao'>
7+
type InterfaceFeedbackCreationalAttributes = Optional<IInterfaceFeedback, "id">
88

9-
// export class DenunciaFeedbackModel extends Model<IDenunciaFeedback, DenunciaFeedbackCreationalAttributes> implements IDenunciaFeedback {
10-
// public id!: number;
11-
// public data_publicacao!: Date;
12-
// public descricao!: string;
13-
// public fk_denuncia!: number;
14-
// }
9+
export class DenunciaFeedbackModel extends Model<IDenunciaFeedback, DenunciaFeedbackCreationalAttributes> implements IDenunciaFeedback {
10+
public id!: number;
11+
public data_publicacao!: Date;
12+
public descricao!: string;
13+
public fk_denuncia!: number;
14+
}
1515

16-
// export class InterfaceFeedbackModel extends Model<IInterfaceFeedback, InterfaceFeedbackCreationalAttributes> implements IInterfaceFeedback {
17-
// public id!: number;
18-
// public data_publicacao!: Date;
19-
// public descricao!: string;
20-
// public tela!: FeedbackInterface;
21-
// }
16+
export class InterfaceFeedbackModel extends Model<IInterfaceFeedback, InterfaceFeedbackCreationalAttributes> implements IInterfaceFeedback {
17+
public id!: number;
18+
public data_publicacao!: Date;
19+
public descricao!: string;
20+
public tela!: FeedbackInterface;
21+
}
2222

23-
// DenunciaFeedbackModel.init({
24-
// id: {
25-
// primaryKey: true,
26-
// type: DataTypes.INTEGER,
27-
// autoIncrement: true,
28-
// allowNull: false,
29-
// field: "id",
30-
// },
31-
// data_publicacao: {
32-
// allowNull: false,
33-
// type: DataTypes.DATE,
34-
// field: "data_publicacao"
35-
// },
36-
// descricao: {
37-
// allowNull: false,
38-
// type: DataTypes.STRING(2048),
39-
// field: "descricao"
40-
// },
41-
// fk_denuncia: {
42-
// allowNull: false,
43-
// type: DataTypes.INTEGER,
44-
// field: "fk_denuncia"
45-
// }
46-
// },{
47-
// tableName: "denuncia-feedback",
48-
// sequelize,
49-
// timestamps: false
50-
// })
23+
DenunciaFeedbackModel.init({
24+
id: {
25+
primaryKey: true,
26+
type: DataTypes.INTEGER,
27+
autoIncrement: true,
28+
allowNull: false,
29+
field: "id",
30+
},
31+
data_publicacao: {
32+
allowNull: false,
33+
type: DataTypes.DATE,
34+
field: "data_publicacao",
35+
defaultValue: DataTypes.NOW
36+
},
37+
descricao: {
38+
allowNull: false,
39+
type: DataTypes.STRING(2048),
40+
field: "descricao"
41+
},
42+
fk_denuncia: {
43+
allowNull: false,
44+
type: DataTypes.INTEGER,
45+
field: "fk_denuncia",
46+
references: {
47+
model: 'denuncia',
48+
key: 'id'
49+
},
50+
onDelete: 'CASCADE',
51+
unique: true
52+
}
53+
},{
54+
tableName: "denuncia-feedback",
55+
sequelize,
56+
timestamps: false
57+
})
5158

52-
// InterfaceFeedbackModel.init({
53-
// id: {
54-
// primaryKey: true,
55-
// type: DataTypes.INTEGER,
56-
// autoIncrement: true,
57-
// allowNull: false,
58-
// field: "id",
59-
// },
60-
// data_publicacao: {
61-
// allowNull: false,
62-
// type: DataTypes.DATE,
63-
// field: "data_publicacao"
64-
// },
65-
// descricao: {
66-
// allowNull: false,
67-
// type: DataTypes.STRING(2048),
68-
// field: "descricao"
69-
// },
70-
// tela: {
71-
// allowNull: false,
72-
// type: DataTypes.INTEGER,
73-
// field: "tela"
74-
// }
75-
// },{
76-
// tableName: "interface-feedback",
77-
// sequelize,
78-
// timestamps: false
79-
// })
59+
InterfaceFeedbackModel.init({
60+
id: {
61+
primaryKey: true,
62+
type: DataTypes.INTEGER,
63+
autoIncrement: true,
64+
allowNull: false,
65+
field: "id",
66+
},
67+
data_publicacao: {
68+
allowNull: false,
69+
type: DataTypes.DATE,
70+
field: "data_publicacao",
71+
defaultValue: DataTypes.NOW
72+
},
73+
descricao: {
74+
allowNull: false,
75+
type: DataTypes.STRING(2048),
76+
field: "descricao"
77+
},
78+
tela: {
79+
allowNull: false,
80+
type: DataTypes.INTEGER,
81+
field: "tela"
82+
}
83+
},{
84+
tableName: "interface-feedback",
85+
sequelize,
86+
timestamps: false
87+
})

0 commit comments

Comments
 (0)