Commit 389bfd4f11e3c2793933c892e688323eff9efcf4
1 parent
dde00da1
Exists in
master
and in
1 other branch
refatora as validacoes e chama o core para legendas ou videos de acordo com os parametros passados
Showing
2 changed files
with
18 additions
and
14 deletions
Show diff stats
endpoints/videornp.js
@@ -7,34 +7,33 @@ var db = require('../db/api'); | @@ -7,34 +7,33 @@ var db = require('../db/api'); | ||
7 | var uuid = require('node-uuid'); | 7 | var uuid = require('node-uuid'); |
8 | var mkdirp = require('mkdirp'); | 8 | var mkdirp = require('mkdirp'); |
9 | var async = require('async'); | 9 | var async = require('async'); |
10 | +var _ = require('lodash'); | ||
10 | 11 | ||
11 | function init(req, res, Request) { | 12 | function init(req, res, Request) { |
12 | res.set("Content-Type", "application/json"); | 13 | res.set("Content-Type", "application/json"); |
13 | 14 | ||
14 | - /* Verifica se os paramêtros [transparencia, texto] possuem algum valor */ | ||
15 | - if (((req.body.legenda_url === '') && (req.body.video_url === '')) || ((typeof req.body.legenda_url === 'undefined') && (typeof req.body.video_url === 'undefined'))) { | ||
16 | - res.send(500, parameters.errorMessage('O valor de algum parâmetro está vazio')); | 15 | + if (_.isEmpty(req.body.legenda_url) && _.isEmpty(req.body.video_url)) { |
16 | + res.send(500, parameters.errorMessage('O valor do parâmetro legenda_url e video_url está vazio')); | ||
17 | return; | 17 | return; |
18 | - } | 18 | + } |
19 | 19 | ||
20 | - /* Verifica se os paramêtros [transparencia, texto] possuem algum valor */ | ||
21 | - if ((typeof req.body.revisaomanual === 'undefined') || ((req.body.revisaomanual.toUpperCase() !== "SIM") && (req.body.revisaomanual.toUpperCase() !== "NAO"))) { | 20 | + if (_.includes(req.body.revisaomanual, "SIM", "NAO")) { |
22 | res.send(500, parameters.errorMessage('O valor do parâmetro revisaomanual é inválido.')); | 21 | res.send(500, parameters.errorMessage('O valor do parâmetro revisaomanual é inválido.')); |
23 | return; | 22 | return; |
24 | } | 23 | } |
25 | 24 | ||
26 | - if ((typeof req.body.conteudista === 'undefined') || (req.body.conteudista === '')) { | ||
27 | - res.send(500, parameters.errorMessage('O valor de algum parâmetro está vazio')); | 25 | + if (_.isEmpty(req.body.conteudista)) { |
26 | + res.send(500, parameters.errorMessage('O valor do parâmetro conteudista está vazio')); | ||
28 | return; | 27 | return; |
29 | } | 28 | } |
30 | 29 | ||
31 | - if ((typeof req.body.instituicao === 'undefined') || (req.body.instituicao === '')) { | ||
32 | - res.send(500, parameters.errorMessage('O valor de algum parâmetro está vazio')); | 30 | + if (_.isEmpty(req.body.instituicao)) { |
31 | + res.send(500, parameters.errorMessage('O valor do parâmetro instituicao está vazio')); | ||
33 | return; | 32 | return; |
34 | } | 33 | } |
35 | 34 | ||
36 | - if ((typeof req.body.usuario === 'undefined') || (req.body.usuario === '')) { | ||
37 | - res.send(500, parameters.errorMessage('O valor de algum parâmetro está vazio')); | 35 | + if (_.isEmpty(req.body.usuario)) { |
36 | + res.send(500, parameters.errorMessage('O valor do parâmetro usuario está vazio')); | ||
38 | return; | 37 | return; |
39 | } | 38 | } |
40 | 39 | ||
@@ -97,7 +96,12 @@ function process(req, res, Request) { | @@ -97,7 +96,12 @@ function process(req, res, Request) { | ||
97 | 96 | ||
98 | // Faz a chamada ao core | 97 | // Faz a chamada ao core |
99 | try { | 98 | try { |
100 | - callCore(id, locals.video, locals.subtitle, req, res, Request, request_object); | 99 | + |
100 | + if (_.isEmpty(req.body.legenda_url)) { // video_url present | ||
101 | + callCore(id, locals.video, locals.subtitle, req, res, Request, request_object); | ||
102 | + } else { | ||
103 | + callCoreSubtitle(id, locals.subtitle, req, res, Request, request_object); | ||
104 | + } | ||
101 | callback(); | 105 | callback(); |
102 | } catch (err) { | 106 | } catch (err) { |
103 | callback(err); | 107 | callback(err); |