-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,740 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
# PARA USAR PRECISA DA EXTENSÃO DO VS CODE "REST Client" | ||
|
||
#Variaveis | ||
@baseUrl = http://localhost:4000 | ||
@token = a3031d64-7423-4bfc-b43e-6b6f2ab24160 | ||
@baseUrl = http://localhost:8080 | ||
@token = 6175c0d0-acd5-4776-95a9-592c795da986 | ||
@token2 = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IlByZXNzLVRpY2tldCIsInByb2ZpbGUiOiJhZG1pbiIsImlkIjoxLCJpYXQiOjE3MzEzNzIwNDksImV4cCI6MTczMTM3NTY0OX0.QwidYXoxONiHC7fsTF87IxLJ-nJ-aNrMFCK4habN2yQ | ||
|
||
# (Enviar Mensagem) Teste da Rota POST /api/messages/send | ||
### (Login) Teste da Rota POST /auth/login | ||
POST {{baseUrl}}/auth/login | ||
Content-Type: application/json | ||
|
||
{ | ||
"email": "[email protected]", | ||
"password": "admin" | ||
} | ||
|
||
### (Enviar Mensagem) Teste da Rota POST /api/messages/send | ||
POST {{baseUrl}}/api/messages/send | ||
Authorization: Bearer {{token}} | ||
Content-Type: application/json | ||
|
@@ -17,4 +27,28 @@ Content-Type: application/json | |
"whatsappId": "1" | ||
} | ||
|
||
### | ||
### (Listar Personalizações) Teste da Rota GET /personalizations | ||
GET {{baseUrl}}/personalizations | ||
Content-Type: application/json | ||
|
||
### (Criar ou Atualizar Personalização) Teste da Rota PUT /personalizations/:theme | ||
PUT {{baseUrl}}/personalizations/light | ||
Authorization: Bearer {{token2}} | ||
Content-Type: application/json | ||
|
||
{ | ||
"company": "Press Ticket", | ||
"url": "https://pressticket.com.br", | ||
"primaryColor": "#ffffff", | ||
"secondaryColor": "#0000ff", | ||
"backgroundDefault": "#ff00ff", | ||
"backgroundPaper": "#00ff00", | ||
"favico": "teste.ico", | ||
"logo": null, | ||
"logoTicket": null | ||
} | ||
|
||
### (Remover Personalização) Teste da Rota DELETE /personalizations/:theme | ||
DELETE {{baseUrl}}/personalizations/light | ||
Authorization: Bearer {{token2}} | ||
Content-Type: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export default { | ||
secret: process.env.JWT_SECRET || "mysecret", | ||
expiresIn: "15m", | ||
expiresIn: "1h", | ||
refreshSecret: process.env.JWT_REFRESH_SECRET || "myanothersecret", | ||
refreshExpiresIn: "7d" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Request } from "express"; | ||
import fs from "fs"; | ||
import multer, { FileFilterCallback } from "multer"; | ||
import path from "path"; | ||
|
||
const deleteIfExists = (filePath: string) => { | ||
if (fs.existsSync(filePath)) { | ||
fs.unlinkSync(filePath); | ||
console.log(`Arquivo ${filePath} deletado com sucesso.`); | ||
} else { | ||
console.log(`Arquivo ${filePath} não encontrado para exclusão.`); | ||
} | ||
}; | ||
|
||
const storage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
const dest = path.resolve( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"frontend", | ||
"public", | ||
"assets" | ||
); | ||
console.log(`Destino do upload: ${dest}`); | ||
cb(null, dest); | ||
}, | ||
filename: (req: Request, file, cb) => { | ||
const { theme } = req.params; | ||
console.log(`Tema recebido: ${theme}`); | ||
let fileName = ""; | ||
|
||
if (theme === "light") { | ||
if (file.fieldname === "favico") { | ||
fileName = "favico.ico"; | ||
} else if (file.fieldname === "logo") { | ||
fileName = "logo.jpg"; | ||
} else if (file.fieldname === "logoTicket") { | ||
fileName = "logoTicket.jpg"; | ||
} | ||
} else if (theme === "dark") { | ||
if (file.fieldname === "favico") { | ||
fileName = "favicoDark.ico"; | ||
} else if (file.fieldname === "logo") { | ||
fileName = "logoDark.jpg"; | ||
} else if (file.fieldname === "logoTicket") { | ||
fileName = "logoTicketDark.jpg"; | ||
} | ||
} | ||
|
||
const filePath = path.resolve( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"frontend", | ||
"public", | ||
"assets", | ||
fileName | ||
); | ||
console.log(`Nome do arquivo gerado: ${fileName}`); | ||
deleteIfExists(filePath); | ||
cb(null, fileName); | ||
} | ||
}); | ||
|
||
const fileFilter = ( | ||
req: Request, | ||
file: Express.Multer.File, | ||
cb: FileFilterCallback | ||
) => { | ||
const allowedMimeTypes = ["image/jpeg", "image/png", "image/x-icon"]; | ||
if (allowedMimeTypes.includes(file.mimetype)) { | ||
cb(null, true); | ||
} else { | ||
cb( | ||
new Error( | ||
"Formato de arquivo inválido. Apenas .jpg, .png e .ico são permitidos." | ||
) | ||
); | ||
} | ||
}; | ||
|
||
const uploadConfig = multer({ | ||
storage, | ||
fileFilter | ||
}); | ||
|
||
export default uploadConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Request, Response } from "express"; | ||
import path from "path"; | ||
import { getIO } from "../libs/socket"; | ||
import createOrUpdatePersonalization from "../services/PersonalizationServices/CreateOrUpdatePersonalizationService"; | ||
import deletePersonalization from "../services/PersonalizationServices/DeletePersonalizationService"; | ||
import listPersonalizations from "../services/PersonalizationServices/ListPersonalizationsService"; | ||
|
||
interface PersonalizationData { | ||
theme: string; | ||
company?: string; | ||
url?: string; | ||
primaryColor: string; | ||
secondaryColor: string; | ||
backgroundDefault: string; | ||
backgroundPaper: string; | ||
favico?: string | null; | ||
logo?: string | null; | ||
logoTicket?: string | null; | ||
} | ||
|
||
export const createOrUpdate = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response> => { | ||
try { | ||
const personalizationData: PersonalizationData = req.body; | ||
const { theme } = req.params; | ||
|
||
if (req.files) { | ||
const files = req.files as { | ||
[fieldname: string]: Express.Multer.File[]; | ||
}; | ||
|
||
if (files.favico && files.favico.length > 0) { | ||
personalizationData.favico = path.basename(files.favico[0].path); | ||
} | ||
if (files.logo && files.logo.length > 0) { | ||
personalizationData.logo = path.basename(files.logo[0].path); | ||
} | ||
if (files.logoTicket && files.logoTicket.length > 0) { | ||
personalizationData.logoTicket = path.basename( | ||
files.logoTicket[0].path | ||
); | ||
} | ||
} | ||
|
||
const personalization = await createOrUpdatePersonalization({ | ||
personalizationData, | ||
theme | ||
}); | ||
|
||
const io = getIO(); | ||
io.emit("personalization", { | ||
action: personalization.isNew ? "create" : "update", | ||
personalization: personalization.data | ||
}); | ||
|
||
return res.status(200).json(personalization.data); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; | ||
|
||
export const list = async (_req: Request, res: Response): Promise<Response> => { | ||
try { | ||
const personalizations = await listPersonalizations(); | ||
return res.status(200).json(personalizations); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; | ||
|
||
export const remove = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response> => { | ||
try { | ||
const { theme } = req.params; | ||
await deletePersonalization(theme); | ||
const io = getIO(); | ||
io.emit("personalization", { | ||
action: "delete", | ||
theme | ||
}); | ||
return res.status(204).send(); | ||
} catch (error) { | ||
return res.status(404).json({ message: error.message }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
backend/src/database/migrations/20241106170332-create-personalizations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { DataTypes, QueryInterface } from "sequelize"; | ||
|
||
module.exports = { | ||
up: async (queryInterface: QueryInterface) => { | ||
await queryInterface.createTable("Personalizations", { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
allowNull: false | ||
}, | ||
theme: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
company: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
url: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
primaryColor: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
secondaryColor: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
backgroundDefault: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
backgroundPaper: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
favico: { | ||
type: DataTypes.TEXT, | ||
allowNull: true | ||
}, | ||
logo: { | ||
type: DataTypes.TEXT, | ||
allowNull: true | ||
}, | ||
logoTicket: { | ||
type: DataTypes.TEXT, | ||
allowNull: true | ||
}, | ||
createdAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
}, | ||
updatedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}); | ||
}, | ||
|
||
down: async (queryInterface: QueryInterface) => { | ||
await queryInterface.dropTable("Personalizations"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.