overleaf/services/web/scripts/validate-data-of-model.mjs
Liangjun Song 26f3f3e2e2 Merge pull request #21097 from overleaf/ls-scripts-to-esm-1
Migrate scripts folder to esm 1/x

GitOrigin-RevId: 4a4bc9a161f144fdb40ce3f2a0a9313b36c6df81
2024-10-21 08:04:42 +00:00

29 lines
687 B
JavaScript

import BatchedUpdateModule from './helpers/batchedUpdate.mjs'
const { batchedUpdateWithResultHandling } = BatchedUpdateModule
const MODEL_NAME = process.argv.pop()
// Todo: handle mjs file once models have been converted to ES module
const { [MODEL_NAME]: Model } = await import(
`../app/src/models/${MODEL_NAME}.js`
)
function processBatch(batch) {
for (const doc of batch) {
const error = new Model(doc).validateSync()
if (error) {
const { errors } = error
console.log(JSON.stringify({ _id: doc._id, errors }))
}
}
}
batchedUpdateWithResultHandling(
Model.collection.name,
{},
async nextBatch => {
await processBatch(nextBatch)
},
{}
)