This repository has been archived by the owner on May 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
18 changed files
with
545 additions
and
7 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
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,33 @@ | ||
const express = require("express") | ||
const app = express() | ||
const mongoose = require("mongoose") | ||
|
||
// Conexão a DB | ||
const LINKDB = "mongodb+srv://admin:[email protected]/escola2?retryWrites=true&w=majority" | ||
|
||
mongoose.connect(LINKDB, { useUnifiedTopology: true, useNewUrlParser: true }, (err, client) => { | ||
if (err) return console.log(err); | ||
|
||
db = mongoose.connection; | ||
console.log("BD Conectado"); | ||
}); | ||
|
||
|
||
// Middlewares | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
// configura a view | ||
app.set("view engine", "ejs"); | ||
|
||
// Importa as Routes | ||
const Router = require('./routes/index'); | ||
app.use('/', Router); | ||
|
||
|
||
// Iniciamos o servidor | ||
const PORTA = 3000; | ||
|
||
app.listen(PORTA, () => { | ||
console.log("Servidor ativado na porta " + PORTA); | ||
}); |
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,11 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const LINKDB = "mongodb+srv://admin:[email protected]/escola2?retryWrites=true&w=majority" | ||
|
||
async function conectarDB(){ | ||
await mongoose.connect(LINKDB, { useNewUrlParser: true, useUnifiedTopology: true }); | ||
console.log("DB conectada") | ||
return client.db("escola2") | ||
} | ||
|
||
module.exports = conectarDB() |
Empty file.
45 changes: 45 additions & 0 deletions
45
Dia 64 - Node - Projeto Escola/controllers/disciplinasController.js
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,45 @@ | ||
const Disciplina = require("../models/disciplina"); | ||
const async = require("async"); | ||
|
||
// Listar | ||
exports.listar = (req, res) => { | ||
Disciplina.find((err, resultado) => { | ||
if (err) return console.log(err); | ||
|
||
res.render("disciplinas.ejs", { dados: resultado }); | ||
}); | ||
}; | ||
|
||
// Cadastrar | ||
exports.cadastrar = (req, res) => { | ||
res.render("disciplinasnova.ejs"); | ||
}; | ||
|
||
exports.cadastrarPost = async (req, res) => { | ||
try { | ||
const disciplina = new Disciplina({ | ||
nome: req.body.nome, | ||
cargahoraria: req.body.cargahoraria, | ||
}); | ||
await disciplina.save(); | ||
res.redirect("../disciplinas"); | ||
} catch (err) { | ||
res.send(err); | ||
} | ||
}; | ||
|
||
// Editar | ||
exports.editar = (req, res) => { | ||
res.render("disciplinaseditar.ejs"); | ||
}; | ||
|
||
// Apagar | ||
exports.apagar = async (req, res) => { | ||
try { | ||
const id = req.params.id; | ||
await Disciplina.findByIdAndDelete(id); | ||
res.redirect("/disciplinas"); | ||
} catch (err) { | ||
res.send(err); | ||
} | ||
}; |
Empty file.
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,36 @@ | ||
let mongoose = require("mongoose"); | ||
|
||
let alunoSchema = new mongoose.Schema({ | ||
matricula: { | ||
type: String, | ||
required: true, | ||
maxLenght: 15, | ||
}, | ||
nome: { | ||
type: String, | ||
required: true, | ||
maxLenght: 80, | ||
}, | ||
cpf: { | ||
type: String, | ||
required: true, | ||
maxLenght: 14, | ||
}, | ||
rg: { | ||
type: String, | ||
required: true, | ||
maxLenght: 25, | ||
}, | ||
endereco: { | ||
type: String, | ||
required: true, | ||
maxLenght: 200, | ||
}, | ||
telefone: { | ||
type: String, | ||
required: true, | ||
maxLenght: 20, | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model("aluno", alunoSchema) |
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,16 @@ | ||
let mongoose = require("mongoose"); | ||
|
||
let disciplinaSchema = new mongoose.Schema({ | ||
nome: { | ||
type: String, | ||
required: true, | ||
maxLenght: 80, | ||
}, | ||
cargahoraria: { | ||
type: String, | ||
required: true, | ||
maxLenght: 4, | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model("disciplina", disciplinaSchema) |
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,31 @@ | ||
let mongoose = require("mongoose"); | ||
|
||
let professorSchema = new mongoose.Schema({ | ||
nome: { | ||
type: String, | ||
required: true, | ||
maxLenght: 80, | ||
}, | ||
cpf: { | ||
type: String, | ||
required: true, | ||
maxLenght: 14, | ||
}, | ||
rg: { | ||
type: String, | ||
required: true, | ||
maxLenght: 25, | ||
}, | ||
endereco: { | ||
type: String, | ||
required: true, | ||
maxLenght: 200, | ||
}, | ||
telefone: { | ||
type: String, | ||
required: true, | ||
maxLenght: 20, | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model("professor", professorSchema) |
Oops, something went wrong.