Skip to content
Snippets Groups Projects
Commit d4c9edc7 authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

removed data-access methods to use index.js

parent 41fb619d
No related branches found
No related tags found
2 merge requests!116Shared data model,!117Dev
......@@ -7,7 +7,7 @@ const db = require('../utils/db.js')
const { execSync } = require('child_process')
const uuidv4 = require('uuid/v4')
const config = require('config')
const manuscriptModel = require('../xpub-model/entities/manuscript/data-access')
const manuscriptModel = require('../xpub-model/entities/manuscript')
const ftpTagger = config.get('ftp_tagger')
const {
......@@ -74,7 +74,8 @@ async function processFile(path) {
try {
logger.info(`Processing tagged XML packages: ${path}`)
const user = await getUser.getFTPUser(rootPath, path)
const user = await getUser.getFTPUser()
const userId = user.userId
const tmpPath = await tar.createTempDir()
const extractedFilePath = await tar.untar(path, tmpPath)
const manifestFilename = await files.getManifestFilename(extractedFilePath)
......@@ -82,10 +83,10 @@ async function processFile(path) {
extractedFilePath,
manifestFilename,
)
const filesArr = await files.checkFiles(filesData, tmpPath, user)
const filesArr = await files.checkFiles(filesData, tmpPath, userId)
// delete current existing 'tagging' files
await db.deleteTaggingFiles(manuscriptId, user)
await db.deleteTaggingFiles(manuscriptId, userId)
// upload to minio
for (let i = 0; i < filesArr.length; i += 1) {
......@@ -108,17 +109,22 @@ async function processFile(path) {
// create rows in 'file' table
await db.createTaggersFiles(dbFilesArr)
manuscriptModel.update(
{ id: manuscriptId, pdfDepositState: 'WAITING_FOR_PDF_CONVERSION' },
user.id,
)
await files.renameFile(path)
logger.info('Uploading to Minio and the database has been completed.')
const manuscriptObj = await manuscriptModel.getManuscriptById(manuscriptId)
const manuscriptObj = await manuscriptModel.findById(manuscriptId, userId)
// send email to taggers
processedTaggerEmail(
ftpTagger.email,
manuscriptId,
manuscriptObj[0]['meta,title'],
manuscriptObj['meta,title'],
`${path}`,
)
// clean up tmp folder
......
......@@ -60,7 +60,7 @@ module.exports.upsertHtmlPrevFile = async function upsertHtmlPrevFile(
module.exports.deleteTaggingFiles = async function deleteTaggingFiles(
manuscriptId,
user,
userId,
) {
const manFiles = await FileModel.selectByManuscriptId(manuscriptId)
const submissionFilesTypes = ['manuscript', 'figure', 'table', 'supplement']
......@@ -69,7 +69,7 @@ module.exports.deleteTaggingFiles = async function deleteTaggingFiles(
)
// delete tagging files
for (let i = 0; i < taggingFiles.length; i += 1) {
await FileModel.deleteById(taggingFiles[i].id, user.userId)
await FileModel.deleteById(taggingFiles[i].id, userId)
}
logger.info(`${taggingFiles.length} files deleted.`)
}
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