Commit 39b39bda authored by Matheus Horstmann's avatar Matheus Horstmann 🐴

Merge branch '28-preparar-sistema-de-upload-de-relatorios' into 'development'

Resolve "Preparar sistema de upload de relatórios"

Closes #28

See merge request !27
parents b6665575 28bc5a04
'use strict';
module.exports = function(Container) {
};
{
"name": "container",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
......@@ -109,10 +109,6 @@
},
"prototype.getEquivalencias": {
"accepts": [],
"returns": {
"arg": "data",
"type": "string"
},
"returns": {
"type": "object",
"root": true
......
'use strict';
module.exports = function(Fileuploaderror) {
};
{
"name": "FileUploadError",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"line": {
"type": "number"
},
"message": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"fileUpload": {
"type": "belongsTo",
"model": "FileUpload",
"foreignKey": "fileUploadId"
}
},
"acls": [],
"methods": {}
}
'use strict';
module.exports = function(Fileupload) {
};
{
"name": "FileUpload",
"plural": "file-uploads",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number"
},
"date": {
"type": "date",
"required": true,
"defaultFn": "now"
},
"fileType": {
"type": "string",
"required": true
},
"status": {
"type": "string"
}
},
"validations": [],
"relations": {
"errors": {
"type": "hasMany",
"model": "FileUploadError",
"foreignKey": "fileUploadId"
}
},
"acls": [],
"methods": {}
}
'use strict';
const _ = require('lodash');
const async = require('async');
const csv = require('fast-csv');
const { fork } = require('child_process');
const fs = require('fs');
const path = require('path');
const loopback = require('loopback');
module.exports = function(Turma) {
Turma.validatesPresenceOf('disciplinaCod');
Turma.validatesPresenceOf('disciplinaCod');
Turma.remoteMethod('upload', {
accepts: [
{ arg: 'req', type: 'object', http: { source: 'req' }},
{ arg: 'res', type: 'object', 'http': {source: 'res'}},
{ arg: 'letiveInit', type: 'date'},
{ arg: 'letiveEnd', type: 'date'}
],
http: {
verb: 'post',
path: '/upload'
},
returns: { arg: 'status', type: 'string' }
});
Turma.upload = function(req,res, letiveInit, letiveEnd, callback) {
var container_name = `turma-${Math.round(Date.now())}-${Math.round(Math.random() * 1000)}`;
var Container = Turma.app.models.container;
Container.createContainer({name:container_name},function(err,c) {
Container.upload(req,res,{container: c.name},callback);
});
};
};
......@@ -11,13 +11,16 @@
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"async": "^1.0.0",
"async": "^2.6.2",
"compression": "^1.7.3",
"cors": "^2.8.5",
"fast-csv": "^2.4.1",
"helmet": "^3.15.0",
"lodash": "^4.17.11",
"loopback": "^3.24.2",
"loopback-boot": "^2.27.1",
"loopback-component-explorer": "^6.3.1",
"loopback-component-storage": "^3.6.0",
"loopback-connector-postgresql": "^3.5.0",
"serve-favicon": "^2.5.0",
"strong-error-handler": "^3.2.0"
......
......@@ -12,5 +12,11 @@
"password": "${POSTGRES_PASSWORD}",
"user": "${POSTGRES_USER}",
"ssl": false
}
},
"container": {
"name": "container",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "tmp"
}
}
......@@ -2,5 +2,11 @@
"db": {
"name": "db",
"connector": "memory"
},
"container": {
"name": "container",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "tmp"
}
}
......@@ -99,5 +99,17 @@
"Ensalamento": {
"dataSource": "ensalamento",
"public": true
},
"FileUpload": {
"dataSource": "db",
"public": true
},
"FileUploadError": {
"dataSource": "db",
"public": true
},
"container": {
"dataSource": "container",
"public": true
}
}
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const server = require('./server.js');
const options = JSON.parse(process.argv[2]);
// Make sure that the node process is killed when the import process is over.
try {
server.models.Invoice.import(options.container, options.file, options, err => process.exit(err ? 1 : 0));
} catch (error) {
const err = error;
process.exit(err ? 1 : 0);
}
This diff is collapsed.
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