Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Corrige o workflow #64

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: 22
node-version: 22.1.0

- name: Instalar dependências do Monorepo
run: yarn
Expand All @@ -47,7 +47,8 @@ jobs:
- name: Iniciar backend
run: |
cd backend
nohup yarn api &
yarn build
nohup yarn start &
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:
- name: Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: 22
node-version: 22.1.0

- name: Instalar dependências do Monorepo
run: yarn
Expand All @@ -116,7 +117,8 @@ jobs:
- name: Iniciar backend
run: |
cd backend
nohup yarn api &
yarn build
nohup yarn start &
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
Expand Down Expand Up @@ -177,7 +179,7 @@ jobs:
- name: Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: 22
node-version: 22.1.0

- name: Configurar Python
uses: actions/[email protected]
Expand All @@ -197,7 +199,8 @@ jobs:
- name: Iniciar backend
run: |
cd backend
nohup yarn api &
yarn build
nohup yarn start &
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npx --no -- commitlint --edit $1
yarn commitlint --edit "$1"
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn format:all
yarn linter:all
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# qa-solar

## 2.4.2

### Patch Changes

- 8f35ad9: chore: ajusta o workflow para o novo modelo do backend
- 9cda398: chore: ajust a configuracao do commitlint com husky
- abe1ffc: chore: instala pacotes para o projeto backend

## 2.4.1

### Patch Changes
Expand Down
5 changes: 4 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Folders
node_modules
# Keep environment variables out of version control
dist

# Environment Variables
.env
35 changes: 35 additions & 0 deletions backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# backend

## 2.0.0

### Major Changes

- abe1ffc: feat: migra o projeto de JavaScript para TypeScript

BREAKING CHANGE:

### O que mudou:

- Todo o código do backend foi reescrito de JavaScript para TypeScript.
- Foram adicionados tipos para garantir maior segurança e previsibilidade no código.
- Algumas estruturas e middlewares foram refatorados para aderir às melhores práticas do TypeScript.

### Por que a mudança foi feita:

- Para melhorar a qualidade do código e reduzir erros em tempo de execução.
- Para facilitar a manutenção do projeto e a escalabilidade futura.
- Para alinhar o projeto com padrões modernos de desenvolvimento.

### Como atualizar seu código:

1. Certifique-se de ter o TypeScript instalado no seu ambiente de desenvolvimento.
2. Atualize os comandos de execução do projeto para usar `ts-node` ou compile os arquivos com `tsc`.
3. Verifique suas integrações externas para ajustar chamadas e tipos, se necessário.
4. Revise os exemplos no `README.md` (se aplicável) para garantir compatibilidade com o novo código.

### Minor Changes

- 8f35ad9: feat: finaliza a configuração do eslint no projeto backend

### Patch Changes

- 9cda398: chore: correcao de codigo e configuracao

## 1.4.0

### Minor Changes
Expand Down
38 changes: 38 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import globals from 'globals';

/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
{
files: ['**/*.{js,mjs,cjs,ts}'],
languageOptions: {
parser: tsParser,
ecmaVersion: 2020,
sourceType: 'module',
globals: {
...globals.node,
},
},
rules: {
'no-console': 'warn', // Alerta para `console.log`
'no-unused-vars': 'off', // Substituído pela regra do TypeScript
},
},
{
files: ['**/*.ts'],
plugins: {
'@typescript-eslint': tsPlugin,
},
rules: {
...tsPlugin.configs.recommended.rules, // Adicionar regras recomendadas do TypeScript
'@typescript-eslint/no-explicit-any': 'off', // Permitir `any` explícito
'@typescript-eslint/no-inferrable-types': 'warn', // Alerta para tipos desnecessários
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' }, // Ignorar variáveis prefixadas com '_'
],
'@typescript-eslint/explicit-module-boundary-types': 'off', // Não exigir tipos explícitos
},
},
];
28 changes: 20 additions & 8 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
{
"name": "backend",
"version": "1.4.0",
"version": "2.0.0",
"description": "backend for QA Solar Project",
"author": "Leonardo Paixao <[email protected]>",
"license": "MIT",
"type": "module",
"private": false,
"scripts": {
"api": "ts-node src/server.js",
"format": "prettier --write src/",
"prisma:seed": "ts-node prisma/seeders/*.js"
"build": "rimraf disc && tsc",
"start": "node dist/server.js",
"dev": "yarn build && yarn start",
"format": "prettier --write src/*{.ts,.json}",
"lint": "eslint 'src/'"
},
"dependencies": {
"@faker-js/faker": "^9.2.0",
"@prisma/client": "^5.22.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.3",
"chalk": "^5.3.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"jsonwebtoken": "^9.0.2",
"prettier": "^3.3.3",
"prisma": "^5.22.0"
"prisma": "^5.22.0",
"winston": "^3.17.0"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.0",
"@eslint/js": "^9.16.0",
"@types/bcryptjs": "^2.4.6",
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/jsonwebtoken": "^9.0.7",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"eslint": "^9.16.0",
"globals": "^15.12.0",
"prettier": "^3.4.1",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
Expand Down
3 changes: 1 addition & 2 deletions backend/prisma/seeders/genericUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ async function main() {

main()
.catch((error) => {
console.error('Erro ao executar o seeder:', error.message);
throw new Error('Não foi possivel criar o usuário genérico', + error.message)
})
.finally(async () => {
console.log('Desconectando o Prisma...');
await prisma.$disconnect();
});
2 changes: 1 addition & 1 deletion backend/src/app.js → backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bodyParser from 'body-parser';
import cors from 'cors';
import express from 'express';
import router from './routes/routes.js';
import router from './routes/routes.ts';

const app = express();

Expand Down
9 changes: 9 additions & 0 deletions backend/src/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dotenv from 'dotenv';

dotenv.config();

if (!process.env.JWT_SECRET) {
throw new Error('JWT_SECRET não definido no arquivo .env');
}

export const JWT_SECRET = process.env.JWT_SECRET;
File renamed without changes.
28 changes: 0 additions & 28 deletions backend/src/controllers/deleteUser.js

This file was deleted.

26 changes: 26 additions & 0 deletions backend/src/controllers/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PrismaClient } from '@prisma/client';
import { Request, Response } from 'express';

const prisma = new PrismaClient();

export async function deleteUser(req: Request, res: Response): Promise<void> {
const { ids } = req.body;

if (ids.includes(req.userId)) {
res.status(400).json({ message: 'Você não pode excluir o usuário logado.' });
return
}

const deletedUsers = await prisma.user.deleteMany({
where: {
id: { in: ids },
},
});

if (deletedUsers.count === 0) {
res.status(404).json({ message: 'Nenhum usuário encontrado para excluir.' });
return
}

res.status(200).json({ message: `${deletedUsers.count} usuário(s) excluído(s) com sucesso!` });
}
33 changes: 0 additions & 33 deletions backend/src/controllers/getAllUsers.js

This file was deleted.

31 changes: 31 additions & 0 deletions backend/src/controllers/getAllUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PrismaClient } from '@prisma/client';
import { Request, Response } from 'express';
import { formatDateTime } from '../utils/formatDate.js';

const prisma = new PrismaClient();

export async function getAllUsers(req: Request, res: Response): Promise<void> {
const users = await prisma.user.findMany({
select: {
id: true,
full_name: true,
social_name: true,
email: true,
phone: true,
document: true,
created_at: true,
},
});

if (users.length === 0) {
res.status(404).json({ message: 'Nenhum usuário encontrado.' });
return
}

const formattedUsers = users.map((user) => ({
...user,
created_at: formatDateTime(user.created_at),
}));

res.status(200).json(formattedUsers);
}
22 changes: 0 additions & 22 deletions backend/src/controllers/getEmailUser.js

This file was deleted.

Loading
Loading