Commit 9e107964 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴 Committed by Bruno Meyer
Browse files

Resolve "Preparar para conexão com Postgres"

parent 87b9bd51
ENSALAMENTO_DB_USER=ensalamento
ENSALAMENTO_DB_PASSWORD=123mudar
ENSALAMENTO_NODE_ENV=development
...@@ -6,7 +6,7 @@ var app = require(path.resolve(__dirname, '../server/server')); ...@@ -6,7 +6,7 @@ var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.ensalamento; var ds = app.datasources.ensalamento;
var lbTables = ['User','AccessToken','ACL','RoleMapping','Role','Sala','Bloco','Disciplina', 'EquivalenciaDisciplina']; var lbTables = ['User','AccessToken','ACL','RoleMapping','Role','Sala','Bloco','Disciplina', 'Equivalenciadisciplina'];
ds.automigrate(lbTables, function(err) { ds.automigrate(lbTables, function(err) {
if (err) throw err; if (err) throw err;
...@@ -83,9 +83,9 @@ function criaEquivalencia(cb){ ...@@ -83,9 +83,9 @@ function criaEquivalencia(cb){
app.models.Disciplina.find({id:1}, function(err, disc){ app.models.Disciplina.find({id:1}, function(err, disc){
disc[0].addEquivalencia(2,function(err,data){ disc[0].addEquivalencia(2,function(err,data){
if (err) throw err; if (err) throw err;
console.log('Created EquivalenciaDisciplina:', disc); console.log('Created Equivalenciadisciplina:', disc);
}); });
}); });
} }
......
var path = require('path'); var path = require('path');
var async = require('async'); var async = require('async');
var app = require(path.resolve(__dirname, '../server/server')); var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.ensalamento; var ds = app.datasources.ensalamento;
var functions = [discoverAndBuildUser, discoverAndBuildRole, discoverAndBuildSala,
discoverAndBuildSala, discoverAndBuildBloco, discoverAndBuildDisciplina,
discoverAndBuildEquivalenciadisciplina, discoverAndBuildAccessToken,
discoverAndBuildACL,discoverAndBuildRoleMapping
]
async.parallel(functions,function(error){
if (err) throw err;
ds.disconnect();
});
function discoverAndBuildUser(){ function discoverAndBuildUser(){
...@@ -27,11 +34,9 @@ function discoverAndBuildAccessToken(){ ...@@ -27,11 +34,9 @@ function discoverAndBuildAccessToken(){
ds.discoverAndBuildModels('accesstoken', {schema: 'public'}, function(err, models) { ds.discoverAndBuildModels('accesstoken', {schema: 'public'}, function(err, models) {
if (err) throw err; if (err) throw err;
models.Accesstoken.find(function(err, accesstokens) {
models.AccessToken.find(function(err, accesstokens) {
if (err) return console.log(err); if (err) return console.log(err);
console.log(accesstokens);
console.log(accesstoken);
}); });
...@@ -44,8 +49,7 @@ function discoverAndBuildACL(){ ...@@ -44,8 +49,7 @@ function discoverAndBuildACL(){
ds.discoverAndBuildModels('acl', {schema: 'public'}, function(err, models) { ds.discoverAndBuildModels('acl', {schema: 'public'}, function(err, models) {
if (err) throw err; if (err) throw err;
models.Acl.find(function(err, acls) {
models.ACL.find(function(err, acls) {
if (err) return console.log(err); if (err) return console.log(err);
console.log(acls); console.log(acls);
...@@ -63,10 +67,10 @@ function discoverAndBuildRoleMapping(){ ...@@ -63,10 +67,10 @@ function discoverAndBuildRoleMapping(){
ds.discoverAndBuildModels('rolemapping', {schema: 'public'}, function(err, models) { ds.discoverAndBuildModels('rolemapping', {schema: 'public'}, function(err, models) {
if (err) throw err; if (err) throw err;
models.RoleMapping.find(function(err, rolesmapping) { models.Rolemapping.find(function(err, rolesmappings) {
if (err) return console.log(err); if (err) return console.log(err);
console.log(rolesmapping); console.log(rolesmappings);
}); });
...@@ -135,7 +139,7 @@ function discoverAndBuildDisciplina(){ ...@@ -135,7 +139,7 @@ function discoverAndBuildDisciplina(){
models.Disciplina.find(function(err, disciplinas) { models.Disciplina.find(function(err, disciplinas) {
if (err) return console.log(err); if (err) return console.log(err);
console.log(disciplina); console.log(disciplinas);
}); });
...@@ -145,12 +149,11 @@ function discoverAndBuildDisciplina(){ ...@@ -145,12 +149,11 @@ function discoverAndBuildDisciplina(){
function discoverAndBuildEquivalenciaDisciplina(){ function discoverAndBuildEquivalenciadisciplina(){
ds.discoverAndBuildModels('equivalenciadisciplina', {schema: 'public'}, function(err, models) { ds.discoverAndBuildModels('equivalenciadisciplina', {schema: 'public'}, function(err, models) {
if (err) throw err; if (err) throw err;
models.Equivalenciadisciplina.find(function(err, equivalenciadisciplinas) {
models.EquivalenciaDisciplina.find(function(err, equivalenciadisciplinas) {
if (err) return console.log(err); if (err) return console.log(err);
console.log(equivalenciadisciplinas); console.log(equivalenciadisciplinas);
......
...@@ -3,29 +3,28 @@ ...@@ -3,29 +3,28 @@
var app = require('../../server/server'); var app = require('../../server/server');
module.exports = function(Disciplina) { module.exports = function(Disciplina) {
// The follow remote methods was constructed because there is many problems // The follow remote methods was constructed because there is many problems
// in the Model Self Relation in LoopBack API 3 // in the Model Self Relation in LoopBack API 3
// The model EquivalenciaDisciplina was created to implement this relation // The model EquivalenciaDisciplina was created to implement this relation
Disciplina.prototype.addEquivalencia = function(disciplina_eq_id, cb) { Disciplina.prototype.addEquivalencia = function(disciplina_eq_id, cb) {
var Eq = app.models.EquivalenciaDisciplina; var Eq = app.models.Equivalenciadisciplina;
Eq.create({"disciplina1": this.id, "disciplina2":disciplina_eq_id}, function(err, eq){ Eq.create({"disciplina1": this.id, "disciplina2":disciplina_eq_id}, function(err, eq){
cb(err,eq); cb(err,eq);
}); });
}; };
Disciplina.prototype.getEquivalencias = function(cb) { Disciplina.prototype.getEquivalencias = function(cb) {
var Eq = app.models.EquivalenciaDisciplina; var Eq = app.models.Equivalenciadisciplina;
let myId = this.id; let myId = this.id;
Eq.find({where:{or:[ {disciplina1:myId}, {disciplina2:myId} ]}}, function(err, eq){ Eq.find({where:{or:[ {disciplina1:myId}, {disciplina2:myId} ]}}, function(err, eq){
// Filter only the ids of equivalents courses // Filter only the ids of equivalents courses
// The id can be on disciplina1 or disciplina2 columns // The id can be on disciplina1 or disciplina2 columns
// console.log(eq[0].disciplina1.toString(), eq[0].disciplina2.toString()); // console.log(eq[0].disciplina1.toString(), eq[0].disciplina2.toString());
var ret = eq.map(function(x){ var ret = eq.map(function(x){
x = x.toJSON(); x = x.toJSON();
if(myId == x.disciplina1) return x.disciplina2; if(myId == x.disciplina1) return x.disciplina2;
...@@ -39,13 +38,13 @@ module.exports = function(Disciplina) { ...@@ -39,13 +38,13 @@ module.exports = function(Disciplina) {
cb(err,uniqueArray); cb(err,uniqueArray);
}); });
}; };
Disciplina.prototype.deleteEquivalencia = function(disciplina_eq_id, cb) { Disciplina.prototype.deleteEquivalencia = function(disciplina_eq_id, cb) {
var Eq = app.models.EquivalenciaDisciplina; var Eq = app.models.Equivalenciadisciplina;
let myId = this.id; let myId = this.id;
// Find and destroy all relations between the two specified instances // Find and destroy all relations between the two specified instances
// The relation can be in form of (id1,id2) or (id2,id1) // The relation can be in form of (id1,id2) or (id2,id1)
Eq.destroyAll({ Eq.destroyAll({
...@@ -66,7 +65,7 @@ module.exports = function(Disciplina) { ...@@ -66,7 +65,7 @@ module.exports = function(Disciplina) {
}, function(err, info){ }, function(err, info){
cb(err,info); cb(err,info);
}); });
}; };
}; };
{ {
"name": "EquivalenciaDisciplina", "name": "Equivalenciadisciplina",
"plural": "equivalenciasDisciplinas", "plural": "equivalenciasdisciplinas",
"base": "PersistedModel", "base": "PersistedModel",
"idInjection": true, "idInjection": true,
"options": { "options": {
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
"dataSource": "ensalamento", "dataSource": "ensalamento",
"public": true "public": true
}, },
"EquivalenciaDisciplina": { "Equivalenciadisciplina": {
"dataSource": "ensalamento", "dataSource": "ensalamento",
"public": false "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