2019-07-18 10:18:56 -04:00
|
|
|
const { DeletedProject } = require('../app/src/models/DeletedProject')
|
|
|
|
const Async = require('async')
|
|
|
|
|
2019-07-26 10:26:25 -04:00
|
|
|
DeletedProject.find({}, (error, deletedProjects) => {
|
|
|
|
if (error) {
|
|
|
|
throw error
|
|
|
|
}
|
2019-07-18 10:18:56 -04:00
|
|
|
|
2019-07-26 10:26:25 -04:00
|
|
|
Async.eachLimit(
|
|
|
|
deletedProjects,
|
|
|
|
10,
|
|
|
|
(deletedProject, cb) => {
|
|
|
|
if (deletedProject.project) {
|
|
|
|
const src = deletedProject.project
|
2019-07-26 11:27:28 -04:00
|
|
|
|
|
|
|
let values = {
|
|
|
|
'deleterData.deletedProjectId': src._id,
|
|
|
|
'deleterData.deletedProjectOwnerId': src.owner_ref,
|
|
|
|
'deleterData.deletedProjectCollaboratorIds': src.collaberator_refs,
|
|
|
|
'deleterData.deletedProjectReadOnlyIds': src.readOnly_refs,
|
|
|
|
'deleterData.deletedProjectReadWriteToken': src.tokens
|
|
|
|
? src.tokens.readAndWrite
|
|
|
|
: undefined,
|
|
|
|
'deleterData.deletedProjectOverleafId': src.overleaf
|
|
|
|
? src.overleaf.id
|
|
|
|
: undefined,
|
|
|
|
'deleterData.deletedProjectOverleafHistoryId':
|
|
|
|
src.overleaf && src.overleaf.history
|
|
|
|
? src.overleaf.history.id
|
|
|
|
: undefined,
|
|
|
|
'deleterData.deletedProjectReadOnlyToken': src.tokens
|
|
|
|
? src.tokens.readOnly
|
|
|
|
: undefined,
|
|
|
|
'deleterData.deletedProjectReadWriteTokenAccessIds':
|
|
|
|
src.tokenAccessReadOnly_refs,
|
|
|
|
'deleterData.deletedProjectReadOnlyTokenAccessIds':
|
|
|
|
src.tokenAccessReadAndWrite_refs,
|
|
|
|
'deleterData.deletedProjectLastUpdatedAt': src.lastUpdated
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(values).forEach(
|
|
|
|
key => (values[key] === undefined ? delete values[key] : '')
|
|
|
|
)
|
|
|
|
|
2019-07-26 10:26:25 -04:00
|
|
|
DeletedProject.findOneAndUpdate(
|
|
|
|
{ _id: deletedProject._id },
|
|
|
|
{
|
2019-07-26 11:27:28 -04:00
|
|
|
$set: values
|
2019-07-26 10:26:25 -04:00
|
|
|
},
|
|
|
|
cb
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
cb()
|
2019-07-18 10:18:56 -04:00
|
|
|
}
|
2019-07-26 10:26:25 -04:00
|
|
|
},
|
|
|
|
err => {
|
|
|
|
if (err) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|