2024-10-18 07:04:57 -04:00
|
|
|
import minimist from 'minimist'
|
|
|
|
import { waitForDb, ObjectId } from '../app/src/infrastructure/mongodb.js'
|
|
|
|
import ProjectEntityUpdateHandler from '../app/src/Features/Project/ProjectEntityUpdateHandler.js'
|
|
|
|
import Errors from '../app/src/Features/Errors/Errors.js'
|
2022-03-28 06:24:04 -04:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
|
|
|
const projectId = argv['project-id']
|
|
|
|
const docId = argv['doc-id']
|
|
|
|
const userId = argv['user-id']
|
|
|
|
|
|
|
|
if ([projectId, docId, userId].some(it => !it || !ObjectId.isValid(it))) {
|
|
|
|
throw new Error(
|
|
|
|
'provide a valid object id as --project-id, --doc-id and --user-id'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Converting doc ${projectId}/${docId} as user ${userId}`)
|
|
|
|
await waitForDb()
|
|
|
|
try {
|
|
|
|
await ProjectEntityUpdateHandler.promises.convertDocToFile(
|
|
|
|
projectId,
|
|
|
|
docId,
|
2022-08-25 08:01:39 -04:00
|
|
|
userId,
|
|
|
|
null
|
2022-03-28 06:24:04 -04:00
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
if (err instanceof Errors.NotFoundError) {
|
|
|
|
throw new Error('Document not found')
|
|
|
|
} else if (err instanceof Errors.DocHasRangesError) {
|
|
|
|
throw new Error('Document has comments or tracked changes')
|
|
|
|
} else {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
try {
|
|
|
|
await main()
|
|
|
|
console.log('Done.')
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|