Commit 06091cbe authored by Bruno Meyer's avatar Bruno Meyer 😢 Committed by Matheus Horstmann

Resolve "Criar model RecursoDeSala"

parent 03839f7d
......@@ -6,12 +6,25 @@ var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.ensalamento;
var lbTables = ['User','AccessToken','ACL','RoleMapping','Role','Sala','Bloco','Disciplina', 'Equivalenciadisciplina', 'Evento', 'Turma'];
var lbTables = [
'User',
'AccessToken',
'ACL','RoleMapping',
'Role',
'Sala',
'Bloco',
'Disciplina',
'Equivalenciadisciplina',
'Evento',
'Turma',
'Recursodesala',
'DisciplinaRecursodesala'
];
ds.automigrate(lbTables, function(err) {
if (err) throw err;
async.waterfall([criaBloco,criaSala,criaUser,criaDisciplina, criaEquivalencia], function(err) {
async.waterfall([criaBloco,criaSala,criaUser,criaDisciplina, criaEquivalencia, criaRecursodesala], function(err) {
if (err) throw err;
ds.disconnect();
})
......@@ -56,6 +69,23 @@ function criaSala(cb){
}
function criaRecursodesala(cb){
var recursos = [
{descricao: 'recurso1'},
{descricao: 'recurso2'}
];
async.each(recursos, function(recurso, callback) {
app.models.Recursodesala.create(recurso, function(err, model) {
callback(err);
console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaUser(cb){
app.models.User.create([
{username: 'admin', email: 'admin@admin.com', password: '123mudar'},
......@@ -85,6 +115,7 @@ function criaEquivalencia(cb){
disc[0].addEquivalencia(2,function(err,data){
if (err) throw err;
console.log('Created Equivalenciadisciplina:', disc);
cb(err);
});
});
......@@ -99,10 +130,12 @@ function criaDisciplina(cb){
async.each(disciplinas, function(disciplina, callback) {
app.models.Disciplina.create(disciplina, function(err, model) {
if (err) throw err;
callback(err);
console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
......
......@@ -40,6 +40,7 @@
- Relations
* This model have a self-realtion. To implement this, we use the EquivalenciaDisciplina model
* Has Many : **Turma** `Required (in Turma)` as `disciplinaId (in Turma)`
* Has and Belongs To Many : **Recursodesala**
## EquivalenciaDisciplina
......@@ -80,3 +81,13 @@
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
## Recursodesala
- Public: `False`
- Attributes
* descricao : **string** `Required`
- ACLs
* All permissions not specified is `DENY`
* **$everyone** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
......@@ -2,42 +2,20 @@
"name": "Disciplina",
"plural": "disciplinas",
"base": "PersistedModel",
"options": {
"ensalemento": {
"schema": "strongloop",
"table": "disciplina"
}
},
"properties": {
"codigo": {
"type": "String",
"required": true,
"length": 64,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "codigo",
"dataType": "character varying",
"dataLength": 64,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO"
}
"scale": null
},
"carga_horaria": {
"type": "Number",
"required": true,
"precision": null,
"scale": null,
"default": 0,
"postgresql": {
"columnName": "carga_horaria",
"dataType": "Integer",
"dataPrecision": null,
"dataScale": null,
"nullable": "NO",
"default": 0
}
"default": 0
},
"duracao": {
"type": "String",
......@@ -45,16 +23,7 @@
"length": 64,
"precision": null,
"scale": null,
"default": "semestral",
"postgresql": {
"columnName": "duracao",
"dataType": "character varying",
"dataLength": 64,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO",
"default": "semestral"
}
"default": "semestral"
},
"modalidade": {
"type": "String",
......@@ -62,16 +31,7 @@
"length": 64,
"precision": null,
"scale": null,
"default": "presencial",
"postgresql": {
"columnName": "modalidade",
"dataType": "character varying",
"dataLength": 64,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO",
"default": "presencial"
}
"default": "presencial"
}
},
"validations": [],
......@@ -81,6 +41,11 @@
"model": "Turma",
"foreignKey": "disciplinaId",
"required": true
},
"recursosnecessarios": {
"type": "hasAndBelongsToMany",
"model": "Recursodesala",
"foreignKey": ""
}
},
"acls": [
......
'use strict';
module.exports = function(Recursodesala) {
};
{
"name": "Recursodesala",
"plural": "recursosdesalas",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"descricao": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "*"
}
],
"methods": {}
}
......@@ -58,5 +58,9 @@
"Turma": {
"dataSource": "ensalamento",
"public": true
},
"Recursodesala": {
"dataSource": "ensalamento",
"public": false
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment