Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
850159d2
Commit
850159d2
authored
1 year ago
by
ems19
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] New routes
parent
a56bc9e0
No related branches found
No related tags found
4 merge requests
!379
homologa -> master
,
!378
dev -> homologa
,
!375
Prd migration
,
!374
Prd migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/routes_v1/publication.js
+127
-59
127 additions, 59 deletions
src/libs/routes_v1/publication.js
with
127 additions
and
59 deletions
src/libs/routes_v1/publication.js
+
127
−
59
View file @
850159d2
...
...
@@ -31,61 +31,127 @@ function emailSyntax(email) {
pubApp
.
get
(
'
/
'
,
async
(
req
,
res
,
next
)
=>
{
const
ordenar
=
req
.
query
.
order
||
'
DESC
'
;
const
filter
=
req
.
query
.
filter
||
'
all
'
;
const
filter
=
req
.
query
.
filter
||
'
all
'
;
const
page
=
parseInt
(
req
.
query
.
page
)
||
1
;
// Current page number
const
pageSize
=
parseInt
(
req
.
query
.
pageSize
)
||
5
;
// Number of items per page
if
(
filter
===
'
all
'
){
const
totalCount
=
await
Publication
.
count
();
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});}
else
{
const
totalCount
=
await
Publication
.
count
({
where
:{
is_draft
:
filter
}});
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
where
:{
is_draft
:
filter
}
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
if
(
filter
===
'
all
'
)
{
const
totalCount
=
await
Publication
.
count
();
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
}
else
{
const
totalCount
=
await
Publication
.
count
({
where
:
{
is_draft
:
filter
}
});
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
where
:
{
is_draft
:
filter
}
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
}
});
pubApp
.
get
(
'
/homepage
'
,
async
(
req
,
res
,
next
)
=>
{
const
totalCount
=
await
Publication
.
count
({
where
:
{
is_headline
:
true
}
});
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
where
:{
is_headline
:
true
}
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
});
pubApp
.
get
(
'
/type/:tp
'
,
async
(
req
,
res
,
next
)
=>
{
const
tp
=
req
.
params
.
tp
||
'
all
'
;
if
(
tp
===
'
all
'
){
const
totalCount
=
await
Publication
.
count
();
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
}
else
{
const
totalCount
=
await
Publication
.
count
({
where
:
{
filter
:
req
.
params
.
tp
}
});
const
offset
=
(
page
-
1
)
*
pageSize
;
const
publis
=
await
Publication
.
findAll
({
offset
,
limit
:
pageSize
,
order
:
[
[
'
created_at
'
,
ordenar
],
],
where
:
{
filter
:
req
.
params
.
tp
}
});
res
.
json
({
page
,
pageSize
,
totalCount
,
data
:
publis
,
});
}
});
pubApp
.
get
(
'
/:id
'
,
async
(
req
,
res
,
next
)
=>
{
let
pb
=
await
Publication
.
findByPk
(
req
.
params
.
id
).
catch
(
function
(
err
)
{
log
.
error
(
err
);
return
next
(
err
);}
return
next
(
err
);
}
);
if
(
!
pb
)
{
res
.
statusCode
=
404
;
res
.
json
({
msg
:
"
A publicação não está cadastrada
"
});
}
res
.
statusCode
=
404
;
res
.
json
({
msg
:
"
A publicação não está cadastrada
"
});
}
else
{
let
publ
=
pb
.
toJSON
();
publ
.
Filename
=
null
;
...
...
@@ -93,20 +159,21 @@ pubApp.get('/:id', async (req, res, next) => {
log
.
error
(
err
);
return
next
(
err
);
});
if
(
file_
){
if
(
file_
)
{
publ
.
Filename
=
file_
.
name
;
}
}
req
.
result
=
publ
;
next
();
}
},
response
(
'
publication
'
));
}
},
response
(
'
publication
'
));
pubApp
.
post
(
'
/
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
authorized
(
'
criar publicacao
'
),
upload
.
single
(
'
file
'
),
async
(
req
,
res
,
next
)
=>
{
let
_file_id
=
null
if
(
req
.
file
){
if
(
req
.
file
)
{
_file_id
=
await
fileWorker
.
uploadFile
(
req
.
file
);
if
(
!
_file_id
)
console
.
log
(
"
NAO ARQUIVO
"
);}
if
(
!
_file_id
)
console
.
log
(
"
NAO ARQUIVO
"
);
}
let
data
=
JSON
.
parse
(
req
.
body
.
data
);
let
pb
=
await
Publication
.
create
({
id
:
0
,
...
...
@@ -139,10 +206,11 @@ pubApp.post('/', passport.authenticate('bearer', { session: false }), authorized
pubApp
.
post
(
'
/edit
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
authorized
(
'
editar publicacao
'
),
upload
.
single
(
'
file
'
),
async
(
req
,
res
,
next
)
=>
{
let
_file_id
=
null
if
(
req
.
file
){
if
(
req
.
file
)
{
_file_id
=
await
fileWorker
.
uploadFile
(
req
.
file
);
if
(
!
_file_id
)
console
.
log
(
"
NAO ARQUIVO
"
);}
if
(
!
_file_id
)
console
.
log
(
"
NAO ARQUIVO
"
);
}
let
data
=
JSON
.
parse
(
req
.
body
.
data
);
console
.
log
(
data
);
let
pb
=
await
Publication
.
findByPk
(
data
.
id
).
catch
(
function
(
err
)
{
...
...
@@ -161,7 +229,7 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author
pb
.
upload
=
_file_id
||
pb
.
upload
;
pb
.
volume
=
data
.
volume
||
pb
.
volume
;
pb
.
pages
=
data
.
pagina
||
pb
.
pages
;
pb
.
save
().
catch
(
function
(
err
)
{
log
.
error
(
err
);
let
errors
=
[];
...
...
@@ -179,12 +247,12 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author
},
response
(
'
publication
'
));
pubApp
.
delete
(
'
/:id
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
authorized
(
'
apagar publicacao
'
),
async
(
req
,
res
,
next
)
=>
{
await
Publication
.
destroy
({
where
:
{
id
:
req
.
params
.
id
}
}).
catch
(
function
(
err
)
{
await
Publication
.
destroy
({
where
:
{
id
:
req
.
params
.
id
}
}).
catch
(
function
(
err
)
{
if
(
err
)
{
log
.
error
(
err
);
return
next
({
err
});
log
.
error
(
err
);
return
next
({
err
});
}
});
});
return
next
({
msg
:
'
Publication Deleted
'
,
status
:
200
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment