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

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