Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Kotahi
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Omo Oaiya
Kotahi
Commits
6d5136cb
Commit
6d5136cb
authored
3 years ago
by
Mihail Gorceag
Browse files
Options
Downloads
Patches
Plain Diff
fix: add logging and comments for debugging purposes
parent
1db3fd48
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/app.js
+6
-0
6 additions, 0 deletions
server/app.js
server/model-manuscript/src/graphql.js
+65
-65
65 additions, 65 deletions
server/model-manuscript/src/graphql.js
with
71 additions
and
65 deletions
server/app.js
+
6
−
0
View file @
6d5136cb
...
@@ -20,11 +20,17 @@ const compression = require('compression')
...
@@ -20,11 +20,17 @@ const compression = require('compression')
const
EventEmitter
=
require
(
'
events
'
)
const
EventEmitter
=
require
(
'
events
'
)
const
gqlApi
=
require
(
'
./graphql
'
)
const
gqlApi
=
require
(
'
./graphql
'
)
console
.
log
(
'
process.version
'
)
console
.
log
(
process
.
version
)
const
configureApp
=
app
=>
{
const
configureApp
=
app
=>
{
const
models
=
require
(
'
@pubsweet/models
'
)
const
models
=
require
(
'
@pubsweet/models
'
)
const
authsome
=
require
(
'
pubsweet-server/src/helpers/authsome
'
)
// TODO: Fix import
const
authsome
=
require
(
'
pubsweet-server/src/helpers/authsome
'
)
// TODO: Fix import
app
.
use
(
compression
())
app
.
use
(
compression
())
console
.
log
(
'
process.version
'
)
console
.
log
(
process
.
version
)
app
.
locals
.
models
=
models
app
.
locals
.
models
=
models
app
.
use
(
bodyParser
.
json
({
limit
:
'
50mb
'
}))
app
.
use
(
bodyParser
.
json
({
limit
:
'
50mb
'
}))
...
...
This diff is collapsed.
Click to expand it.
server/model-manuscript/src/graphql.js
+
65
−
65
View file @
6d5136cb
...
@@ -299,71 +299,71 @@ const resolvers = {
...
@@ -299,71 +299,71 @@ const resolvers = {
}
}
}
}
if
(
process
.
env
.
INSTANCE_NAME
===
'
ncrc
'
)
{
//
if (process.env.INSTANCE_NAME === 'ncrc') {
// eslint-disable-next-line
//
// eslint-disable-next-line
const
submissionForm
=
require
(
'
../../../app/storage/forms-ncrc/submit.json
'
)
//
const submissionForm = require('../../../app/storage/forms-ncrc/submit.json')
const
spreadsheetId
=
'
1OvWJj7ZTFhniC4KbFNbskuYSNMftsG2ocKuY-i9ezVA
'
//
const spreadsheetId = '1OvWJj7ZTFhniC4KbFNbskuYSNMftsG2ocKuY-i9ezVA'
const
fieldsOrder
=
submissionForm
.
children
//
const fieldsOrder = submissionForm.children
.
filter
(
el
=>
el
.
name
)
//
.filter(el => el.name)
.
map
(
formElement
=>
formElement
.
name
.
split
(
'
.
'
)[
1
])
//
.map(formElement => formElement.name.split('.')[1])
const
formatSubmissionData
=
rawSubmissionData
=>
{
//
const formatSubmissionData = rawSubmissionData => {
return
Object
.
keys
(
rawSubmissionData
).
reduce
((
acc
,
key
)
=>
{
//
return Object.keys(rawSubmissionData).reduce((acc, key) => {
return
{
...
acc
,
[
key
]:
rawSubmissionData
[
key
].
toString
()
}
//
return { ...acc, [key]: rawSubmissionData[key].toString() }
},
{})
//
}, {})
}
//
}
const
publishArticleInGoogleSheets
=
async
submissionData
=>
{
//
const publishArticleInGoogleSheets = async submissionData => {
const
formattedSubmissionData
=
formatSubmissionData
(
submissionData
)
//
const formattedSubmissionData = formatSubmissionData(submissionData)
const
{
articleURL
}
=
formattedSubmissionData
//
const { articleURL } = formattedSubmissionData
const
doc
=
new
GoogleSpreadsheet
(
spreadsheetId
)
//
const doc = new GoogleSpreadsheet(spreadsheetId)
await
doc
.
useServiceAccountAuth
({
//
await doc.useServiceAccountAuth({
client_email
:
credentials
.
client_email
,
//
client_email: credentials.client_email,
private_key
:
credentials
.
private_key
,
//
private_key: credentials.private_key,
})
//
})
await
doc
.
loadInfo
()
//
await doc.loadInfo()
const
sheet
=
doc
.
sheetsByIndex
[
0
]
//
const sheet = doc.sheetsByIndex[0]
const
rows
=
await
sheet
.
getRows
()
//
const rows = await sheet.getRows()
const
indexOfExistingArticle
=
rows
.
findIndex
(
//
const indexOfExistingArticle = rows.findIndex(
row
=>
row
.
articleURL
===
articleURL
,
//
row => row.articleURL === articleURL,
)
//
)
if
(
indexOfExistingArticle
!==
-
1
)
{
//
if (indexOfExistingArticle !== -1) {
fieldsOrder
.
forEach
(
fieldName
=>
{
//
fieldsOrder.forEach(fieldName => {
rows
[
indexOfExistingArticle
][
fieldName
]
=
//
rows[indexOfExistingArticle][fieldName] =
formattedSubmissionData
[
fieldName
]
||
''
//
formattedSubmissionData[fieldName] || ''
})
//
})
await
rows
[
indexOfExistingArticle
].
save
()
//
await rows[indexOfExistingArticle].save()
}
else
{
//
} else {
await
sheet
.
addRow
({
...
formattedSubmissionData
})
//
await sheet.addRow({ ...formattedSubmissionData })
}
//
}
}
//
}
try
{
//
try {
await
publishArticleInGoogleSheets
(
manuscript
.
submission
)
//
await publishArticleInGoogleSheets(manuscript.submission)
const
updatedManuscript
=
await
ctx
.
models
.
Manuscript
.
query
().
updateAndFetchById
(
//
const updatedManuscript = await ctx.models.Manuscript.query().updateAndFetchById(
id
,
//
id,
{
//
{
published
:
new
Date
(),
//
published: new Date(),
status
:
'
published
'
,
//
status: 'published',
},
//
},
)
//
)
return
updatedManuscript
//
return updatedManuscript
}
catch
(
e
)
{
//
} catch (e) {
// eslint-disable-next-line
//
// eslint-disable-next-line
console
.
log
(
'
error while publishing in google spreadsheet
'
)
//
console.log('error while publishing in google spreadsheet')
// eslint-disable-next-line
//
// eslint-disable-next-line
console
.
log
(
e
)
//
console.log(e)
return
null
//
return null
}
//
}
}
//
}
if
(
!
manuscript
.
published
&&
process
.
env
.
INSTANCE_NAME
===
'
aperture
'
)
{
if
(
!
manuscript
.
published
&&
process
.
env
.
INSTANCE_NAME
===
'
aperture
'
)
{
manuscript
=
ctx
.
models
.
Manuscript
.
query
().
updateAndFetchById
(
id
,
{
manuscript
=
ctx
.
models
.
Manuscript
.
query
().
updateAndFetchById
(
id
,
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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