Commit a46eaf0e authored by Rafael S Castilho's avatar Rafael S Castilho

Merge branch '40-atualiza-pesquisa-de-disciplina' into 'development'

Resolve "Atualiza pesquisa de disciplina"

Closes #40

See merge request !50
parents 7504ca69 90407e34
......@@ -9,6 +9,8 @@ var old_db = require(path.resolve(__dirname, '../bin/load-old-database'));
var ds = app.datasources.ensalamento;
var lbTables = models.models;
//lbTables.splice(31,2)
console.log(lbTables)
var LOG_CREATE = false;
......@@ -34,7 +36,6 @@ ds.automigrate(lbTables, function(err) {
loadModelFromOldDB(old_db.get_disciplinas, app.models.Disciplina, LOG_CREATE),
loadModelFromOldDB(old_db.get_equivalenciasDisciplinas, app.models.Equivalenciadisciplina, LOG_CREATE),
loadModelFromOldDB(old_db.get_cursos, app.models.Curso, LOG_CREATE),
loadRelationsFromOldDB(old_db.get_cursoDisciplina, app.models.Curso, "disciplinas", LOG_CREATE),
],
function(err) {
......@@ -70,9 +71,7 @@ function addRelationBetweenModels(model, modelRelationName,
var query = {where: {}};
query.where[relationInstance.pkey_name] = relationInstance.pkeys[0];
console.log(query)
model.findOne(query, (err,data) => {
console.log("Data:",data)
if (err ) throw err;
if(data)
data[modelRelationName].add(relationInstance.pkeys[1], (err,data) => {
......@@ -265,7 +264,7 @@ function criaSecretario(cb){
if (err && !user ) throw err;
user.updateAttribute("secretarioCod",s.id,(err)=>{
if (err) throw err;
if(LOG_CREATE) console.log('Created Secretario:', secre);
if(LOG_CREATE) console.log('Created Secretario:', secretario);
callback(err);
})
......
Subproject commit 0ca16e519402a63fd85c8809a1133a20ab44d99a
Subproject commit 0218b69b045f5b0c11e1eb695d93735a314be66f
This diff is collapsed.
This diff is collapsed.
......@@ -8,14 +8,40 @@ module.exports = function(Curso) {
//todas as turmas de todo o curso.
//como o é utilizado somente o código da sala, não precisa incluir a
//relacao sala
var _include = {turmas:["professor","disciplina","horarios"]}
var _include = {
"relation": "turmas",
"scope": {
"where": {"merged": false},
"include": [{
"relation": "disciplina",
"scope": {
"fields": ["nome","codigo"]
}
},{
"relation": "horarios",
"scope": {
"where": {"visible":true},
"fields": ["dia","horario_final","horario_inicial","salaCode"]
}
},{
"relation": "professores",
"scope": {
"fields": ["nome","codigo"]
}
}, {
"relation": "cursos",
"scope": {
"fields": ["nome"]
}
}
]
}
}
var cursos = await app.models.Curso.find({where:
{or: [{nome: _query},
{codigo: _query}]}, include:_include})
// for(var i = 0; i < cursos.length; i++) {
//
// }
return cursos;
return Object.values(cursos);
};
......
......@@ -37,9 +37,8 @@
"model": "Disciplina"
},
"turmas": {
"type": "hasMany",
"model": "Turma",
"foreignKey": "cursoCod"
"type": "hasAndBelongsToMany",
"model": "Turma"
}
},
"acls": [
......@@ -73,7 +72,6 @@
"principalId": "$everyone",
"permission": "ALLOW",
"property": "search"
}
],
"methods": {
......
......@@ -7,10 +7,21 @@ module.exports = function(Departamento) {
//como o é utilizado somente o código da sala, não precisa incluir a
//relacao sala
var _include = {
"relation": "turmas",
"relation": "disciplinas",
"scope": {
"where": {"merged": false},
"include": ["professores","disciplina","cursos","horarios"]
"include": {
"relation":"turmas",
"scope": {
"where": {"merged": false},
"include": ["professores","cursos",{
"relation": "horarios",
"scope": {
"where": {"visible": true},
}
}]
}
}
}
}
//var _include = {turmas:["professor","disciplina","cursos",{horarios:["sala"]}]}
......@@ -18,7 +29,33 @@ module.exports = function(Departamento) {
{or: [ {nome: _query},
{codigo: _query} ]},include:_include})
return dpts
var result = []
for( var i=0; i< dpts.length; i++) {
var dpt = dpts[i].toJSON()
var departamento = {
"codigo": dpt.codigo,
"nome": dpt.nome
}
var disciplinas = {}
for( var j=0; j< dpt.disciplinas.length; j++) {
var disciplina = await app.models.Disciplina.findById(dpt.disciplinas[j].codigo)
var disciplina_equiv = await disciplina.getEquivalencias()
disciplina_equiv.push(disciplina.codigo)
var disciplina_codigo = disciplina_equiv.sort().join(" - ")
if(disciplinas[disciplina_codigo])
disciplinas[disciplina_codigo].turmas.push(dpt.disciplinas[j].turmas)
else {
disciplinas[disciplina_codigo] = {}
disciplinas[disciplina_codigo].nome = dpt.disciplinas[j].nome
disciplinas[disciplina_codigo].codigo = disciplina_codigo
disciplinas[disciplina_codigo].disciplinaCod = disciplina.codigo
disciplinas[disciplina_codigo].turmas = dpt.disciplinas[j].turmas
}
}
departamento.disciplinas = Object.values(disciplinas)
result.push(departamento)
}
return result
};
};
......@@ -33,6 +33,11 @@
"model": "Turma",
"foreignKey": "departamentoCod"
},
"disciplinas": {
"type": "hasMany",
"model": "Disciplina",
"foreignKey": "departamentoCod"
},
"professores": {
"type": "hasMany",
"model": "Professor",
......
This diff is collapsed.
......@@ -18,6 +18,10 @@
"precision": null,
"scale": null
},
"equivalenced": {
"type": "boolean",
"default": false
},
"carga_horaria": {
"type": "Number",
"required": true,
......@@ -138,6 +142,37 @@
"path": "/equivalencias"
}
},
"prototype.getAllEquivalencias": {
"accepts": [],
"returns": {
"type": "object",
"root": true
},
"description": "Find all equivalences of tree model matched.",
"http": {
"verb": "get",
"path": "/allequivalencias"
}
},
"prototype.get_equivalence_root": {
"accepts": [
{
"arg": "disciplina",
"type": "string"
}
],
"returns": {
"type": "object",
"root": true
},
"description": "Find equivalence root.",
"http": {
"verb": "get",
"path": "/equivalence_root"
}
},
"prototype.deleteEquivalencia": {
"accepts": [
{
......@@ -182,6 +217,34 @@
"verb": "get"
}
]
},
"equivalencedpt": {
"accepts": [
{
"arg": "departamento",
"type": "string",
"required": true,
"description": "codigo do departamento",
"http": {
"source": "query"
}
}
],
"returns": [
{
"arg": "equivalencias",
"type": "array",
"root": false,
"description": "lista de todas as equivalencias de todas as disciplinas "
}
],
"description": "pesquisa por turma ",
"http": [
{
"path": "/equivalenciasdpt",
"verb": "get"
}
]
}
}
}
......@@ -6,20 +6,24 @@
"validateUpsert": true
},
"properties": {
"line": {
"linha_numero": {
"type": "number"
},
"message": {
"type": "string",
"required": true
},
"linha": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"fileUpload": {
"type": "belongsTo",
"type": "hasAndBelongsToMany",
"model": "FileUpload",
"foreignKey": "fileUploadId"
"throughTable": "FileUploadFileUploadError"
}
},
"acls": [],
......
......@@ -26,18 +26,11 @@
},
"status": {
"type": "string"
},
"completed": {
"type": "number",
"default": 0,
"postgresql": {
"dataType": "real"
}
}
},
"validations": [],
"relations": {
"errors": {
"erros": {
"type": "hasAndBelongsToMany",
"model": "FileUploadError"
},
......
......@@ -56,7 +56,7 @@ module.exports = function(Horario) {
var horarios_turma = t.horarios;
for(var h in horarios_turma){
var horario = horarios_turma[h];
if(horario.id == horario_id) return t.vagas;
if(horario.id == horario_id) return (horario.vagas)? horario.vagas : t.vagas;
}
return 0;
});
......@@ -130,7 +130,7 @@ module.exports = function(Horario) {
{
relation: "horarios",
scope: {
where: { salaCode: _query }
where: {and: [{ salaCode: _query },{"visible":true}]}
}
}
]
......
......@@ -33,6 +33,10 @@
"visible": {
"type": "boolean",
"default": true
},
"vagas": {
"type": "number",
"default": 0
}
},
"validations": [],
......@@ -42,15 +46,20 @@
"model": "Sala",
"foreignKey": "salaCode"
},
"horario": {
"type": "belongsTo",
"model": "Horario",
"foreignKey": "mergedCod",
"invert": true
},
"ensalamento": {
"type": "belongsTo",
"model": "Ensalamento",
"foreignKey": "ensalamentoId"
},
"turmas": {
"type": "hasMany",
"model": "Turma",
"foreignKey": "turmaCod"
"type": "hasAndBelongsToMany",
"model": "Turma"
},
"bloco": {
"type": "belongsTo",
......@@ -82,6 +91,20 @@
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "searchBySala"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "searchByBloco"
}
],
"methods": {
......
......@@ -33,9 +33,9 @@ var models = [
"FileUpload",
"FileUploadError",
"FileUploadFileUploadError",
"TurmaHorario",
"TurmaProfessor",
"TurmaCurso"
"CursoTurma",
"HorarioTurma",
"ProfessorTurma"
];
/**
......
......@@ -33,6 +33,10 @@
"type": "belongsTo",
"model": "Departamento",
"foreignKey": "departamentoCod"
},
"turmas": {
"type": "hasAndBelongsToMany",
"model": "Turma"
}
},
"acls": [
......
......@@ -124,7 +124,6 @@ module.exports = function(Reserva) {
/**
* faz a reserva de uma sala
* @param {object} reserva objeto com informaçoes da reserva
* @param {Function(Error, object)} callback
*/
Reserva.reservar = async function(reserva) {
......
......@@ -82,6 +82,20 @@
"principalType": "ROLE",
"principalId": "comissao",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "reservar"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "search"
}
],
"methods": {
......
......@@ -19,8 +19,11 @@ module.exports = function(Sala) {
},
function(user,instance,role,callback) { // verifica a role, se for secretario então pega o secretario
if(role == "secretario_setor")
return callback(null,user,instance,user._secretario)
if(role == "secretario_dpto")
user.secretario.get( ( err,obj)=>{
if(obj) return callback(null,user,instance,secretario)
return callback( true, {"code":15, "msg":"Secretario não encontrado"})
})
else
return callback(true,{"code":1}) // quer dizer que a role não é de secretario
},
......
......@@ -18,6 +18,16 @@
"public": {
"type": "boolean",
"default": false
},
"status_number": {
"type": "number",
"default": 0,
"postgresql": {
"dataType": "real"
}
},
"status_msg": {
"type": "string"
}
},
"validations": [],
......
......@@ -64,6 +64,12 @@
"permission": "ALLOW",
"property": "*"
},
{
"principalType": "READ",
"principalId": "secretario_setor",
"permission": "ALLOW",
"property": "*"
},
{
"principalType": "ROLE",
"principalId": "comissao",
......
'use strict';
module.exports = function(Turmaprofessor) {
};
{
"name": "TurmaProfessor",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
This diff is collapsed.
......@@ -49,9 +49,8 @@
"turmasMergeds": {
"type": "belongsTo",
"model": "Turma",
"invert": true,
"foreignKey": "mergedCod"
"foreignKey": "mergedCod",
"invert": true
},
"professores": {
"type": "hasAndBelongsToMany",
......@@ -60,8 +59,7 @@
},
"horarios": {
"type": "hasAndBelongsToMany",
"model": "Horario",
"foreignKey": ""
"model": "Horario"
}
},
"acls": [
......@@ -100,10 +98,16 @@
"juntar": {
"accepts": [
{
"arg": "turmas",
"type": "array",
"arg": "_turma_x",
"type": "string",
"required": true,
"description": "Id da primeira turma"
},
{
"arg": "_turma_y",
"type": "string",
"required": true,
"description": "lista de turmas a serem unidas"
"description": "Id da segunda turma"
}
],
"returns": [
......@@ -122,13 +126,44 @@
}
]
},
"dividir": {
"accepts": [
{
"arg": "_turma_x",
"type": "string",
"required": true,
"description": "Id da turma a ser dividida"
}
],
"returns": [
{
"arg": "status",
"type": "object",
"root": false,
"description": "status da divisao"
}
],
"description": "divide uma turma que foi unida em duas",
"http": [
{
"path": "/split",
"verb": "post"
}
]
},
"mergehorario": {
"accepts": [
{
"arg": "horarios",
"type": "array",
"arg": "_turma_x",
"type": "object",
"required": true,
"description": "Objeto contendo id da turma e horario id"
},
{
"arg": "_turma_y",
"type": "object",
"required": true,
"description": "array de objetos horarios, incluindo turma"
"description": "Objeto contendo id da turma e horario id"
}
],
"returns": [
......@@ -147,6 +182,37 @@
}
]
},
"splithorario": {
"accepts": [
{
"arg": "_turma_x",
"type": "object",
"required": true,
"description": "Objeto contendo id da turma e horario id"
},
{
"arg": "_turma_y",
"type": "object",
"required": true,
"description": "Objeto contendo id da turma e horario id"
}
],
"returns": [
{
"arg": "status",
"type": "object",
"root": false,
"description": "status de retorno"
}
],
"description": "divide dois horarios de turmas diferentes",
"http": [
{
"path": "/splithorario",
"verb": "post"
}
]
},
"create_turma": {
"accepts": [
{
......
......@@ -2,14 +2,13 @@
set -e
#if [ "$1" = 'DEVELOPMENT' ]; then
# /usr/local/bin/node /app/bin/automigrate.js
# # echo "oi"
#fi
#
#if [ "$1" = 'PRODUCTION' ]; then
# /usr/local/bin/node /app/bin/automigrate.js
#fi
if [ "$1" = 'DEVELOPMENT' ]; then
/usr/local/bin/node /app/bin/automigrate.js
fi
if [ "$1" = 'PRODUCTION' ]; then
/usr/local/bin/node /app/bin/automigrate.js
fi
# echo "while true; do sleep 2; done" >> /app/test.sh && chmod +x /app/test.sh
# /bin/bash /app/test.sh
......
......@@ -19,7 +19,10 @@ async function aclSecretarioDpto(_model,ctx,next) {
},
function(user,instance,role,callback) { // verifica a role, se for secretario então pega o secretario
if(role == "secretario_dpto")
return callback(null,user,instance,user._secretario)
user.secretario.get( ( err,obj)=>{
if(obj) return callback(null,user,instance,obj)
return callback( true, {"code":15, "msg":"Secretario não encontrado"})
})
else
return callback(true,{"code":1}) // quer dizer que a role não é de secretario
},
......@@ -83,8 +86,11 @@ function aclSecretarioSetor(_model,ctx,next) {
},
function(user,instance,role,callback) { // verifica a role, se for secretario então pega o secretario
if(role == "secretario_setor")
return callback(null,user,instance,user._secretario)
if(role == "secretario_dpto")
user.secretario.get( ( err,obj)=>{
if(obj) return callback(null,user,instance,obj)
return callback( true, {"code":15, "msg":"Secretario não encontrado"})
})
else
return callback(true,{"code":1}) // quer dizer que a role não é de secretario
},
......
......@@ -33,6 +33,7 @@ function getScheduleInstance(h, cb){
course: horarioCurso,
department: "dinf",
klass_id: 1
assigned: horario.salaCode
});
cb(null,schedule);
});
......@@ -43,7 +44,7 @@ async function getAllSchedulesInstances(newEnsalamento,cb){
var Horario = app.models.Horario;
// TODO: Filter by parameters specified by user
var queryHorario = {where:{"visible":true}};
var queryHorario = {where:{and:[{"visible":true},"livre":true]}};
var queryTurma = {
include: ["horarios","cursos"]
......
......@@ -6,6 +6,7 @@ const fs = require('fs');
const path = require('path');
const app = require(path.resolve(__dirname, '../server/server'));
const Disciplina = app.models.Disciplina;
const Semestre = app.models.Semestre
const Departamento = app.models.Departamento;
const FileUpload = app.models.FileUpload;
const Curso = app.models.Curso;
......@@ -27,17 +28,13 @@ function check_fields(obj) {
}
async function handle_line(line) {
if (line.COD_DISCIPLINA === "" || line.NOME_DISCIPLINA === "")
return {"status":true,"msg":"nome ou código de disciplina vazia"};
var course = line.NOME_DISCIPLINA.replace('\n','');