Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Juan Ferrer Toribio 2017-06-07 08:39:43 +02:00
commit 0fd9db06f6
12 changed files with 407 additions and 7 deletions

4
Jenkinsfile vendored
View File

@ -25,10 +25,6 @@ node {
checkout scm
}
stage ('webpack'){
sh "webpack"
}
stage ('install modules'){
sh "npm install"
}

View File

@ -9,6 +9,8 @@ var fs = require('fs');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var services = require("./gulpfiles/services.json");
// Configuration
var srcDir = './client';
@ -32,11 +34,27 @@ gulp.task('client', ['clean'], function() {
return gulp.start('watch', 'routes', 'locales', 'webpack-dev-server');
});
gulp.task('services', function() {
gulp.task('copy', function() {
var streams = [];
for (i=0; i < services.services.length; i++) {
var service = services.services[i];
for (j=0; j < services.files.length; j++) {
var file = services.files[j];
streams.push(gulp.src("./services/service/models/" + file)
.pipe(gulp.dest(service + "/common/models/")));
}
}
return merge(streams);
});
gulp.task('services', ['copy'], function() {
require('./services/auth/server/server.js').start();
require('./services/client/server/server.js').start();
require('./services/salix/server/server.js').start();
require('./services/mailer/server.js').start();
for (i=0; i < services.services.length; i++) {
require(services.services[i] + "/server/server.js").start();
}
});
gulp.task('clean', function() {

14
gulpfiles/services.json Normal file
View File

@ -0,0 +1,14 @@
{
"services": [
"./services/client",
"./services/production"
],
"files":[
"account.json",
"my-model.js",
"my-model.json",
"user.json"
]
}

View File

@ -0,0 +1,46 @@
{
"name": "Account",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"active": {
"type": "boolean"
},
"email": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "root",
"permission": "ALLOW"
}
]
}

View File

@ -0,0 +1,125 @@
module.exports = function(self) {
self.setup = function() {
self.super_.setup.call(this);
let disableMethods = {
'create': true,
'replaceOrCreate': true,
'patchOrCreate': true,
'upsert': true,
'updateOrCreate': true,
'exists': true,
'find': true,
'findOne': true,
'findById': true,
'deleteById': true,
'replaceById': true,
'updateAttributes': false,
'createChangeStream': true,
'updateAll': true,
'upsertWithWhere': true,
'count': true
};
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
}
self.installMethod = function(methodName, filterCb) {
this.remoteMethod(methodName, {
description: 'List items using a filter',
accessType: 'READ',
accepts: [
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: `/${methodName}`
}
});
this[methodName] = (params, cb) => {
let filter = removeEmpty(filterCb(params));
var response = {}
function returnValues(){
if(response.instances !== undefined && response.count !== undefined)
cb(null, response);
}
function error(){
cb(null, response);
}
this.find(filter, function(err, instances) {
if(!err){
response.instances = instances;
returnValues();
}
else{
error();
}
})
this.count(filter.where, function(err, totalCount){
if(!err){
response.count = totalCount;
returnValues();
}
else{
error();
}
})
};
};
}
function removeEmpty(o) {
if(Array.isArray(o)) {
let array = [];
for(let item of o) {
let i = removeEmpty(item);
if(!isEmpty(item))
array.push(item);
};
if(array.length > 0)
return array;
}
else if (typeof o === 'object') {
let object = {};
for(let key in o) {
let i = removeEmpty(o[key]);
if(!isEmpty(i))
object[key] = i;
}
if(Object.keys(object).length > 0)
return object;
}
else if (!isEmpty(o))
return o;
return undefined;
}
function isEmpty(value) {
return value === undefined || value === "";
}

View File

@ -0,0 +1,4 @@
{
"name": "MyModel",
"base": "PersistedModel"
}

View File

@ -0,0 +1,11 @@
{
"name": "user",
"base": "User",
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
}
}
}

View File

@ -1,7 +1,7 @@
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"port": 3004,
"remoting": {
"context": false,
"rest": {

View File

@ -0,0 +1,46 @@
{
"name": "Account",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"active": {
"type": "boolean"
},
"email": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "root",
"permission": "ALLOW"
}
]
}

View File

@ -0,0 +1,125 @@
module.exports = function(self) {
self.setup = function() {
self.super_.setup.call(this);
let disableMethods = {
'create': true,
'replaceOrCreate': true,
'patchOrCreate': true,
'upsert': true,
'updateOrCreate': true,
'exists': true,
'find': true,
'findOne': true,
'findById': true,
'deleteById': true,
'replaceById': true,
'updateAttributes': false,
'createChangeStream': true,
'updateAll': true,
'upsertWithWhere': true,
'count': true
};
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
}
self.installMethod = function(methodName, filterCb) {
this.remoteMethod(methodName, {
description: 'List items using a filter',
accessType: 'READ',
accepts: [
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: `/${methodName}`
}
});
this[methodName] = (params, cb) => {
let filter = removeEmpty(filterCb(params));
var response = {}
function returnValues(){
if(response.instances !== undefined && response.count !== undefined)
cb(null, response);
}
function error(){
cb(null, response);
}
this.find(filter, function(err, instances) {
if(!err){
response.instances = instances;
returnValues();
}
else{
error();
}
})
this.count(filter.where, function(err, totalCount){
if(!err){
response.count = totalCount;
returnValues();
}
else{
error();
}
})
};
};
}
function removeEmpty(o) {
if(Array.isArray(o)) {
let array = [];
for(let item of o) {
let i = removeEmpty(item);
if(!isEmpty(item))
array.push(item);
};
if(array.length > 0)
return array;
}
else if (typeof o === 'object') {
let object = {};
for(let key in o) {
let i = removeEmpty(o[key]);
if(!isEmpty(i))
object[key] = i;
}
if(Object.keys(object).length > 0)
return object;
}
else if (!isEmpty(o))
return o;
return undefined;
}
function isEmpty(value) {
return value === undefined || value === "";
}

View File

@ -0,0 +1,4 @@
{
"name": "MyModel",
"base": "PersistedModel"
}

View File

@ -0,0 +1,11 @@
{
"name": "user",
"base": "User",
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
}
}
}