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