Skip to content
Open
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
Binary file added MER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions back/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/create-curso\\index.js"
}
]
}
21 changes: 21 additions & 0 deletions back/create-curso/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Only project- and language-specific ignores in here. Use global .gitignore for editors etc

# Vagrant
.vagrant/

# node.js
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
24 changes: 24 additions & 0 deletions back/create-curso/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"development": {
"username": "root",
"password": "123456789",
"database": "netothCursos",
"host": "db-cursos.cxxk5fjz6okp.us-east-1.rds.amazonaws.com",
"dialect": "mysql",
"port":"3306"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
25 changes: 25 additions & 0 deletions back/create-curso/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let db = require('./models/index');

module.exports.create = (event, context, callback) => {

context.callbackWaitsForEmptyEventLoop = false;

const response = {}
response.headers = {}

return db.sequelize.transaction(transaction => {
return db.sequelize.models.Cursos.create(event, transaction)
.then(data => {
return Promise.all([
data.setProfessores(event.idProfessores, { transaction }),
data.setSalas(event.idSalas, { transaction })
]).then(_ => Promise.resolve(data))
})
})
.then(data => {
response.body = JSON.stringify(data.dataValues)
response.statusCode = 200
callback(null, response)
})
.catch(erro => callback(JSON.stringify(erro) == {} ? erro : JSON.stringify(erro), null))
}
36 changes: 36 additions & 0 deletions back/create-curso/models/curso.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = function (sequelize, DataTypes) {
const Cursos = sequelize.define('Cursos', {
nome: {
type: DataTypes.STRING,
unique: true,
allowNull: false
},
horaInicio: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
field: "HORA_INICIO"
},
horaFim: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
field: "HORA_FIM"
},
},{
freezeTableName: true,
tableName: 'CURSOS'
})

Cursos.associate = models => {
Cursos.belongsToMany(models.Professores, {through: "CURSOS_PROFESSORES", as: "Professores", foreignKey: "ID_CURSO"})
Cursos.belongsToMany(models.Salas, {through: "CURSOS_SALAS", as: "Salas", foreignKey: "ID_CURSO"})
}

// Cursos.associate = models => {

// }

return Cursos

};
44 changes: 44 additions & 0 deletions back/create-curso/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fs = require("fs");
const path = require("path");
const CLASSMETHODS = 'classMethods';
const ASSOCIATE = 'associate';
const Sequelize = require('sequelize');
var db_ambient = process.env.NODE_ENV || 'development';
let env = require('../config/config.json')[db_ambient];
var db = {};

const sequelize = new Sequelize(env.database, env.username, env.password, {
host: env.host,
port: env.port,
logging: true,
dialect: env.dialect,
define: {
timestamps: false
},
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 20000,
idle: 10000
}
});


fs.readdirSync(__dirname).filter(function (file) {
return (file.indexOf('.') !== 0) && (file !== 'index.js');
}).forEach(function (file) {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(function(modelName) {
if ('associate' in db[modelName]) {
db[modelName].associate(db);
}
});

module.exports = {
'Sequelize': Sequelize,
'sequelize': sequelize
};
20 changes: 20 additions & 0 deletions back/create-curso/models/professor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

module.exports = function (sequelize, DataTypes) {
const Professores = sequelize.define('Professores', {
nome: {
type: DataTypes.STRING,
unique: true,
allowNull: false
},
},{
freezeTableName: true,
tableName: 'PROFESSORES'
})


Professores.associate = models => {
Professores.belongsToMany(models.Cursos, {through: "CURSOS_PROFESSORES", as: "Cursos", foreignKey: "ID_PROFESSOR"})
}

return Professores
};
20 changes: 20 additions & 0 deletions back/create-curso/models/sala.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

module.exports = function (sequelize, DataTypes) {
const Salas = sequelize.define('Salas', {
nome: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
field: "DESCRICAO"
},
},{
freezeTableName: true,
tableName: 'SALAS'
})

Salas.associate = models => {
Salas.belongsToMany(models.Cursos, {through: "CURSOS_SALAS", as: "Cursos", foreignKey: "ID_SALA"})
}

return Salas
};
Loading