Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-rest-api-mcafee
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cristian Mauricio Diaz Canales
node-rest-api-mcafee
Commits
0ff928fa
Commit
0ff928fa
authored
Oct 22, 2020
by
Cristian Mauricio Diaz Canales
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mejoras sistema
parent
aa150142
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
217 additions
and
190 deletions
+217
-190
index.js
index.js
+0
-1
routes/campanias.js
routes/campanias.js
+217
-189
No files found.
index.js
View file @
0ff928fa
...
@@ -9,7 +9,6 @@ require('events').EventEmitter.prototype._maxListeners = 100;
...
@@ -9,7 +9,6 @@ require('events').EventEmitter.prototype._maxListeners = 100;
**/
**/
console
.
log
(
`Aplicacion :
${
config
.
get
(
"
name
"
)}
`
);
console
.
log
(
`Aplicacion :
${
config
.
get
(
"
name
"
)}
`
);
/*
/*
* Solo en ambientes de desarrollo locales se coloca el puerto directamente al iniciar la aplicacion
* Solo en ambientes de desarrollo locales se coloca el puerto directamente al iniciar la aplicacion
* en servidores, se debe obtener del objeto global "process"
* en servidores, se debe obtener del objeto global "process"
...
...
routes/campanias.js
View file @
0ff928fa
const
express
=
require
(
'
express
'
);
const
express
=
require
(
"
express
"
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
const
config
=
require
(
'
config
'
);
const
config
=
require
(
"
config
"
);
const
dbConn
=
require
(
'
../middleware/database
'
);
const
dbConn
=
require
(
"
../middleware/database
"
);
const
szerCampaniaValidator
=
require
(
"
../middleware/validation
"
);
const
szerCampaniaValidator
=
require
(
"
../middleware/validation
"
);
const
log
=
require
(
'
../middleware/logger
'
);
const
jsonResponse
=
{};
const
jsonResponse
=
{};
dbConn
.
getConnection
((
err
,
connection
)
=>
{
dbConn
.
getConnection
((
err
,
connection
)
=>
{
if
(
err
)
{
if
(
err
)
{
log
.
logger
.
error
(
`Error con la conexion a la base de datos :
${
err
}
`
);
log
.
logger
.
error
(
`Error con la conexion a la base de datos :
${
err
}
`
);
throw
err
;
throw
err
;
}
else
console
.
log
(
"
Conectado!...
"
)
;
}
else
console
.
log
(
"
Conectado!...
"
);
});
});
router
.
post
(
"
/obtener/contenido
"
,
(
req
,
res
)
=>
{
router
.
post
(
'
/obtener/contenido
'
,
(
req
,
res
)
=>
{
const
validateCampania
=
new
szerCampaniaValidator
();
const
validateCampania
=
new
szerCampaniaValidator
();
//Si falta el parametro uid, error 400
//Si falta el parametro uid, error 400
var
{
error
}
=
validateCampania
.
validate
(
req
.
body
);
var
{
error
}
=
validateCampania
.
validate
(
req
.
body
);
if
(
error
)
{
if
(
error
)
{
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.BAD_REQUEST
"
)).
json
({
"
error
"
:
error
.
details
[
0
].
message
});
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.BAD_REQUEST
"
))
.
json
({
error
:
error
.
details
[
0
].
message
});
return
;
return
;
}
}
...
@@ -28,21 +29,25 @@ router.post('/obtener/contenido', (req, res) => {
...
@@ -28,21 +29,25 @@ router.post('/obtener/contenido', (req, res) => {
//Seteo de entorno mediante userAgent
//Seteo de entorno mediante userAgent
let
isMobile
=
req
.
useragent
.
isMobile
;
let
isMobile
=
req
.
useragent
.
isMobile
;
processHtml
(
res
,
uid
,
isMobile
);
processHtml
(
res
,
uid
,
isMobile
);
});
});
async
function
processHtml
(
res
,
uid
,
isMobile
)
{
async
function
processHtml
(
res
,
uid
,
isMobile
)
{
//Buscar UID , si no esta es error 404
//Buscar UID , si no esta es error 404
//console.log("obteniendo campaña asociada...");
//console.log("obteniendo campaña asociada...");
try
{
const
campania
=
await
getCampaniaById
([
uid
]);
const
campania
=
await
getCampaniaById
([
uid
]);
if
(
!
campania
||
campania
.
length
==
0
)
{
if
(
!
campania
||
campania
.
length
==
0
)
{
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.NOT_FOUND
"
)).
json
({
"
error
"
:
`El uid
${
uid
}
no esta asociado a ninguna campaña.`
});
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.NOT_FOUND
"
))
.
json
({
error
:
`El uid
${
uid
}
no esta asociado a ninguna campaña.`
});
return
;
return
;
}
}
//console.log(campania[0].cam_id);
//console.log(campania[0].cam_id);
const
template
=
await
getTemplateById
([
campania
[
0
].
tem_id
]);
const
template
=
await
getTemplateById
([
campania
[
0
].
tem_id
]);
if
(
!
template
||
template
.
length
==
0
)
{
if
(
!
template
||
template
.
length
==
0
)
{
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.NOT_FOUND
"
)).
json
({
"
error
"
:
`La campaña uid
${
uid
}
no tiene asociado ninguna plantilla de diseño.`
});
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.NOT_FOUND
"
)).
json
({
error
:
`La campaña uid
${
uid
}
no tiene asociado ninguna plantilla de diseño.`
,
});
return
;
return
;
}
}
//console.log(template[0].tem_id);
//console.log(template[0].tem_id);
...
@@ -72,16 +77,18 @@ async function processHtml(res, uid, isMobile) {
...
@@ -72,16 +77,18 @@ async function processHtml(res, uid, isMobile) {
jsonResponse
.
terminosCondiciones
=
generateHtmlCondiciones
(
campania
);
jsonResponse
.
terminosCondiciones
=
generateHtmlCondiciones
(
campania
);
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.OK
"
)).
send
(
jsonResponse
);
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.OK
"
)).
send
(
jsonResponse
);
}
catch
(
err
)
{
log
.
logger
.
error
(
`Error :
${
err
.
message
}
`
);
res
.
status
(
config
.
get
(
"
constants.HTTP_STATUS_CODE.ERROR
"
))
.
json
({
error
:
`Ha ocurrido un error :
${
err
.
message
}
`
});
}
}
}
async
function
generateHtmlSection
(
campania
,
type
,
isMobile
)
{
async
function
generateHtmlSection
(
campania
,
type
,
isMobile
)
{
try
{
let
contenidos
=
await
getContenido
(
campania
,
type
,
isMobile
,
false
);
let
contenidos
=
await
getContenido
(
campania
,
type
,
isMobile
,
false
);
let
countContenido
=
await
getContenido
(
let
countContenido
=
await
getContenido
(
campania
,
type
,
isMobile
,
true
);
campania
,
type
,
isMobile
,
true
);
var
posContenido
=
0
;
var
posContenido
=
0
;
var
fila
=
0
;
var
fila
=
0
;
var
html
=
""
;
var
html
=
""
;
...
@@ -90,10 +97,12 @@ async function generateHtmlSection(campania, type, isMobile) {
...
@@ -90,10 +97,12 @@ async function generateHtmlSection(campania, type, isMobile) {
contenidos
.
forEach
((
contenido
)
=>
{
contenidos
.
forEach
((
contenido
)
=>
{
let
json
=
{};
let
json
=
{};
var
cantidadContenido
=
countContenido
[
0
][
"
cantidad
"
];
var
cantidadContenido
=
countContenido
[
0
][
"
cantidad
"
];
if
(
fila
!==
contenido
.
cco_fila
)
{
if
(
fila
!==
contenido
.
cco_fila
)
{
if
(
fila
!=
0
)
html
=
html
+
"
</div>
"
;
if
(
fila
!=
0
)
html
=
html
+
"
</div>
"
;
fila
=
contenido
.
cco_fila
;
fila
=
contenido
.
cco_fila
;
html
=
html
+
`<div id='fila_id_
${
contenido
.
cco_fila
}
_
${
contenido
.
cco_id
}
' class='row'>`
;
html
=
html
+
`<div id='fila_id_
${
contenido
.
cco_fila
}
_
${
contenido
.
cco_id
}
' class='row'>`
;
}
}
json
.
id
=
contenido
.
cco_id
;
json
.
id
=
contenido
.
cco_id
;
...
@@ -107,22 +116,25 @@ async function generateHtmlSection(campania, type, isMobile) {
...
@@ -107,22 +116,25 @@ async function generateHtmlSection(campania, type, isMobile) {
posContenido
++
;
posContenido
++
;
fila
=
contenido
.
cco_fila
;
fila
=
contenido
.
cco_fila
;
if
(
posContenido
==
cantidadContenido
)
{
if
(
posContenido
==
cantidadContenido
){
json
.
contenido
=
json
.
contenido
+
"
</div>
"
;
json
.
contenido
=
json
.
contenido
+
'
</div>
'
;
arrayJson
[
posContenido
-
1
]
=
json
;
arrayJson
[
posContenido
-
1
]
=
json
;
}
}
html
=
""
;
html
=
""
;
});
});
return
arrayJson
;
return
arrayJson
;
}
catch
(
err
)
{
log
.
logger
.
error
(
`Error :
${
err
.
message
}
`
);
return
[];
}
}
}
async
function
getContenido
(
campania
,
type
,
isMobile
,
isCount
)
{
async
function
getContenido
(
campania
,
type
,
isMobile
,
isCount
)
{
var
query
=
``
;
var
query
=
``
;
if
(
isCount
)
query
=
query
+
`SELECT count(*) as cantidad FROM campania_contenido `
;
if
(
isCount
)
query
=
query
+
`SELECT count(*) as cantidad FROM campania_contenido `
;
else
query
=
query
+
`SELECT * FROM campania_contenido `
;
else
query
=
query
+
`SELECT * FROM campania_contenido `
;
query
=
query
=
...
@@ -136,11 +148,15 @@ async function getContenido(campania, type, isMobile, isCount) {
...
@@ -136,11 +148,15 @@ async function getContenido(campania, type, isMobile, isCount) {
if
(
isMobile
)
if
(
isMobile
)
query
=
query
=
query
+
query
+
` and dis_id in (
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.MOBILE
"
)}
,
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.BOTH
"
)}
) `
;
` and dis_id in (
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.MOBILE
"
)}
,
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.BOTH
"
)}
) `
;
else
else
query
=
query
=
query
+
query
+
` and dis_id in (
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.DESKTOP
"
)}
,
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.BOTH
"
)}
) `
;
` and dis_id in (
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.DESKTOP
"
)}
,
${
config
.
get
(
"
constants.CONTENT_DEVICE_DISPOSITION.BOTH
"
)}
) `
;
query
=
query
+
` ORDER BY cco_fila ASC, cco_columna ASC;`
;
query
=
query
+
` ORDER BY cco_fila ASC, cco_columna ASC;`
;
//console.log(query);
//console.log(query);
...
@@ -148,27 +164,42 @@ async function getContenido(campania, type, isMobile, isCount) {
...
@@ -148,27 +164,42 @@ async function getContenido(campania, type, isMobile, isCount) {
return
doQuery
(
query
);
return
doQuery
(
query
);
}
}
function
htmlAnalyzer
(
contenido
){
function
htmlAnalyzer
(
contenido
)
{
var
html
=
""
;
var
html
=
""
;
switch
(
contenido
.
cco_tipo
)
{
switch
(
contenido
.
cco_tipo
)
{
case
config
.
get
(
"
constants.CONTENT_TYPE.TEXT
"
):
case
config
.
get
(
"
constants.CONTENT_TYPE.TEXT
"
):
html
=
""
;
html
=
""
;
html
=
getColumnaByDisposicion
(
contenido
.
cco_disposicion_nombre
,
contenido
.
cco_columna
);
html
=
getColumnaByDisposicion
(
html
=
html
+
`<div id="texto_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
" >
${
contenido
.
cco_contenido
}
</div>`
;
contenido
.
cco_disposicion_nombre
,
html
=
html
+
'
</div>
'
;
contenido
.
cco_columna
);
html
=
html
+
`<div id="texto_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
" >
${
contenido
.
cco_contenido
}
</div>`
;
html
=
html
+
"
</div>
"
;
break
;
break
;
case
config
.
get
(
"
constants.CONTENT_TYPE.IMAGE
"
):
case
config
.
get
(
"
constants.CONTENT_TYPE.IMAGE
"
):
html
=
""
;
html
=
""
;
html
=
getColumnaByDisposicion
(
contenido
.
cco_disposicion_nombre
,
contenido
.
cco_columna
);
html
=
getColumnaByDisposicion
(
html
=
html
+
`<img id="imagen_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
" src="
${
contenido
.
cco_contenido
}
" />`
;
contenido
.
cco_disposicion_nombre
,
html
=
html
+
'
</div>
'
;
contenido
.
cco_columna
);
html
=
html
+
`<img id="imagen_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
" src="
${
contenido
.
cco_contenido
}
" />`
;
html
=
html
+
"
</div>
"
;
break
;
break
;
case
config
.
get
(
"
constants.CONTENT_TYPE.VIDEO
"
):
case
config
.
get
(
"
constants.CONTENT_TYPE.VIDEO
"
):
html
=
""
;
html
=
""
;
html
=
getColumnaByDisposicion
(
contenido
.
cco_disposicion_nombre
,
contenido
.
cco_columna
);
html
=
getColumnaByDisposicion
(
html
=
html
+
`<div id="video_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="
${
contenido
.
cco_contenido
}
"></iframe></div>`
;
contenido
.
cco_disposicion_nombre
,
html
=
html
+
'
</div>
'
;
contenido
.
cco_columna
);
html
=
html
+
`<div id="video_fil_
${
contenido
.
cco_fila
}
_con_
${
contenido
.
cco_id
}
" class="
${
contenido
.
cco_clase_css
}
embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" src="
${
contenido
.
cco_contenido
}
"></iframe></div>`
;
html
=
html
+
"
</div>
"
;
break
;
break
;
default
:
default
:
html
=
""
;
html
=
""
;
...
@@ -178,9 +209,9 @@ function htmlAnalyzer(contenido){
...
@@ -178,9 +209,9 @@ function htmlAnalyzer(contenido){
return
html
;
return
html
;
}
}
function
getColumnaByDisposicion
(
nombre
,
columna
){
function
getColumnaByDisposicion
(
nombre
,
columna
)
{
var
html
=
""
;
var
html
=
""
;
switch
(
nombre
)
{
switch
(
nombre
)
{
case
"
(1)
"
:
case
"
(1)
"
:
html
=
'
<div class = "col-lg-12 col-md-12 col-sm-12 col-xs-12">
'
;
html
=
'
<div class = "col-lg-12 col-md-12 col-sm-12 col-xs-12">
'
;
break
;
break
;
...
@@ -226,8 +257,7 @@ function getColumnaByDisposicion(nombre, columna){
...
@@ -226,8 +257,7 @@ function getColumnaByDisposicion(nombre, columna){
return
html
;
return
html
;
}
}
function
generateHtmlCondiciones
(
campania
){
function
generateHtmlCondiciones
(
campania
)
{
let
arrayJson
=
[];
let
arrayJson
=
[];
let
json
=
{};
let
json
=
{};
let
html
=
`<div id="terminos_
${
campania
[
0
].
cam_id
}
" class="gearlabs_terminos">Ver términos y condiciones <a href="
${
campania
[
0
].
cam_url_terminos_condiciones_campania
}
" target = "_blank">aquí</a></div>`
;
let
html
=
`<div id="terminos_
${
campania
[
0
].
cam_id
}
" class="gearlabs_terminos">Ver términos y condiciones <a href="
${
campania
[
0
].
cam_url_terminos_condiciones_campania
}
" target = "_blank">aquí</a></div>`
;
...
@@ -236,10 +266,8 @@ function generateHtmlCondiciones(campania){
...
@@ -236,10 +266,8 @@ function generateHtmlCondiciones(campania){
arrayJson
.
push
(
json
);
arrayJson
.
push
(
json
);
return
arrayJson
;
return
arrayJson
;
}
}
async
function
getCampanias
()
{
async
function
getCampanias
()
{
let
query
=
`SELECT * FROM campania;`
;
let
query
=
`SELECT * FROM campania;`
;
return
doQuery
(
query
);
return
doQuery
(
query
);
...
@@ -263,8 +291,8 @@ async function doQuery(queryToDo) {
...
@@ -263,8 +291,8 @@ async function doQuery(queryToDo) {
let
pro
=
new
Promise
((
resolve
,
reject
)
=>
{
let
pro
=
new
Promise
((
resolve
,
reject
)
=>
{
let
query
=
queryToDo
;
let
query
=
queryToDo
;
dbConn
.
query
(
query
,
function
(
err
,
result
)
{
dbConn
.
query
(
query
,
function
(
err
,
result
)
{
if
(
err
)
throw
err
;
if
(
err
)
//console.log(result
);
reject
(
new
Error
(
`Ocurrio el siguiente error en la BD :
${
err
}
`
)
);
resolve
(
result
);
resolve
(
result
);
});
});
});
});
...
@@ -277,7 +305,8 @@ async function doQueryParams(queryToDo, array) {
...
@@ -277,7 +305,8 @@ async function doQueryParams(queryToDo, array) {
let
pro
=
new
Promise
((
resolve
,
reject
)
=>
{
let
pro
=
new
Promise
((
resolve
,
reject
)
=>
{
let
query
=
queryToDo
;
let
query
=
queryToDo
;
dbConn
.
query
(
query
,
array
,
function
(
err
,
result
)
{
dbConn
.
query
(
query
,
array
,
function
(
err
,
result
)
{
if
(
err
)
throw
err
;
if
(
err
)
reject
(
new
Error
(
`Ocurrio el siguiente error en la BD :
${
err
}
`
));
resolve
(
result
);
resolve
(
result
);
});
});
});
});
...
@@ -287,4 +316,3 @@ async function doQueryParams(queryToDo, array) {
...
@@ -287,4 +316,3 @@ async function doQueryParams(queryToDo, array) {
}
}
module
.
exports
=
router
;
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment