2020-04-28 13:11:39 +00:00
|
|
|
const readline = require('readline')
|
2020-10-05 08:29:37 +00:00
|
|
|
const { waitForDb } = require('../app/src/infrastructure/mongodb')
|
2020-04-28 13:11:39 +00:00
|
|
|
const ProjectEntityHandler = require('../app/src/Features/Project/ProjectEntityHandler')
|
|
|
|
const ProjectGetter = require('../app/src/Features/Project/ProjectGetter')
|
|
|
|
const Errors = require('../app/src/Features/Errors/Errors')
|
|
|
|
|
2020-05-01 11:42:17 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2020-04-28 13:11:39 +00:00
|
|
|
async function countFiles() {
|
|
|
|
const rl = readline.createInterface({
|
2021-04-27 07:52:58 +00:00
|
|
|
input: process.stdin,
|
2020-04-28 13:11:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for await (const projectId of rl) {
|
|
|
|
try {
|
|
|
|
const project = await ProjectGetter.promises.getProject(projectId)
|
2020-04-29 10:50:34 +00:00
|
|
|
if (!project) {
|
|
|
|
throw new Errors.NotFoundError('project not found')
|
|
|
|
}
|
2021-12-06 15:27:12 +00:00
|
|
|
const { files, docs } = ProjectEntityHandler.getAllEntitiesFromProject(
|
|
|
|
project
|
|
|
|
)
|
2020-04-28 13:11:39 +00:00
|
|
|
console.error(
|
|
|
|
projectId,
|
|
|
|
files.length,
|
2020-04-29 09:48:17 +00:00
|
|
|
(project.deletedFiles && project.deletedFiles.length) || 0,
|
2020-04-28 13:11:39 +00:00
|
|
|
docs.length,
|
2020-04-29 09:48:17 +00:00
|
|
|
(project.deletedDocs && project.deletedDocs.length) || 0
|
2020-04-28 13:11:39 +00:00
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Errors.NotFoundError) {
|
|
|
|
console.error(projectId, 'NOTFOUND')
|
|
|
|
} else {
|
2020-05-01 11:42:17 +00:00
|
|
|
console.log(projectId, 'ERROR', err.name, err.message)
|
2020-04-28 13:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 08:29:37 +00:00
|
|
|
waitForDb()
|
|
|
|
.then(countFiles)
|
2020-05-01 11:42:17 +00:00
|
|
|
.then(() => {
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log('Aiee, something went wrong!', err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|