Skip to content

Commit 8d2fb27

Browse files
committed
Manipulando requisições e banco de dados MongoDB
1 parent 5b14942 commit 8d2fb27

File tree

13 files changed

+109
-155
lines changed

13 files changed

+109
-155
lines changed

backend/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const Paciente = require('./models/paciente');
1616
const Familiar = require('./models/familiar');
1717
const Status = require('./models/status')
1818

19+
// Importando as rotas definidas para o paciente
20+
const pacienteRoutes = require('./routes/paciente');
21+
1922
const mongoose = require('mongoose');
2023
mongoose.connect(`mongodb+srv://${dbUser}:${dbPassword}@${dbCluster}.vhzwx.mongodb.net/${dbName}?retryWrites=true&w=majority`)
2124
.then(() => {
@@ -24,3 +27,11 @@ mongoose.connect(`mongodb+srv://${dbUser}:${dbPassword}@${dbCluster}.vhzwx.mongo
2427
console.log('Conexão NOK');
2528
})
2629

30+
app.use ((req, res, next) => {
31+
res.setHeader('Access-Control-Allow-Origin', "*");
32+
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type,Accept');
33+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE,OPTIONS');
34+
next();
35+
});
36+
37+
app.use('/pacientes/', pacienteRoutes);

backend/config/config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

backend/controllers/error.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

backend/controllers/paciente.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

backend/dbOld/paciente.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

backend/index.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

backend/models/paciente.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
const db = require('../util/database');
1+
const mongoose = require('mongoose');
22

3-
module.exports = class Grocery {
4-
constructor(idPaciente, nomePaciente, cpfPaciente, leito, data_internacao, data_alta) {
5-
this.idPaciente = idPaciente;
6-
this.nomePaciente = nomePaciente;
7-
this.cpfPaciente = cpfPaciente;
8-
this.leito = leito;
9-
this.data_internacao = data_internacao;
10-
this.data_alta = data_alta;
11-
}
3+
const pacienteSchema = mongoose.Schema({
4+
nome: { type: String, required: true },
5+
cpf: { type: String, required: true },
6+
leito: { type: String, required: true },
7+
data_internacao: { type: Date, required: true },
8+
data_alta: { type: Date, required: false }
9+
})
1210

13-
static fetchAll() {
14-
return db.execute('SELECT * FROM pacientes')
15-
}
16-
17-
static post(nomePaciente, cpfPaciente, leito, data_internacao, data_alta) {
18-
return db.execute('INSERT INTO pacientes (nomePaciente, cpfPaciente, leito, data_internacao, data_alta) VALUES (?,?,?,?,?)', [nomePaciente, cpfPaciente, leito, data_internacao, data_alta]);
19-
}
20-
21-
static update(idPaciente, nomePaciente, cpfPaciente, leito, data_internacao, data_alta) {
22-
return db.execute('UPDATE pacientes SET nomePaciente=?, cpfPaciente=?, leito=?, data_internacao=?, data_alta=? WHERE idPaciente=?', [nomePaciente, cpfPaciente, leito, data_internacao, data_alta, idPaciente]);
23-
}
24-
25-
static delete(idPaciente) {
26-
return db.execute('DELETE FROM pacientes WHERE idPaciente=?', [idPaciente]);
27-
}
28-
};
11+
module.exports = mongoose.model('Paciente', pacienteSchema);

0 commit comments

Comments
 (0)