2020-10-27 06:44:11 -04:00
|
|
|
const { waitForDb } = require('../app/src/infrastructure/mongodb')
|
2021-10-25 09:57:16 -04:00
|
|
|
const ProjectEntityRestoreHandler = require('../app/src/Features/Project/ProjectEntityRestoreHandler')
|
2021-05-21 07:32:30 -04:00
|
|
|
const DocstoreManager = require('../app/src/Features/Docstore/DocstoreManager')
|
2020-10-27 06:44:11 -04:00
|
|
|
|
|
|
|
const ARGV = process.argv.slice(2)
|
|
|
|
const DEVELOPER_USER_ID = ARGV.shift()
|
|
|
|
const PROJECT_ID = ARGV.shift()
|
|
|
|
const FILE_NAMES_TO_RESTORE = ARGV
|
|
|
|
|
|
|
|
async function main() {
|
2021-05-21 07:32:30 -04:00
|
|
|
const deletedDocs = await DocstoreManager.promises.getAllDeletedDocs(
|
|
|
|
PROJECT_ID
|
|
|
|
)
|
|
|
|
const docsToRestore = deletedDocs.filter(doc =>
|
2020-10-27 06:44:11 -04:00
|
|
|
FILE_NAMES_TO_RESTORE.includes(doc.name)
|
|
|
|
)
|
|
|
|
for (const deletedDoc of docsToRestore) {
|
2023-04-13 06:08:27 -04:00
|
|
|
const newDoc = await ProjectEntityRestoreHandler.promises.restoreDeletedDoc(
|
2021-10-25 09:57:16 -04:00
|
|
|
PROJECT_ID,
|
|
|
|
deletedDoc._id,
|
2023-04-13 06:08:27 -04:00
|
|
|
deletedDoc.name,
|
2021-10-25 09:57:16 -04:00
|
|
|
DEVELOPER_USER_ID
|
|
|
|
)
|
2020-10-27 06:44:11 -04:00
|
|
|
console.log(newDoc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
waitForDb()
|
|
|
|
.then(main)
|
|
|
|
.then(() => {
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
})
|