Files
overleaf-cep/services/web/scripts/validate-data-of-model.mjs
Andrew Rumble 394c60f2cf Merge pull request #29659 from overleaf/revert-29656-revert-29521-ar-models-es-conversion
Revert "Revert "[web] Convert models and self-referential test files to ESM ""

GitOrigin-RevId: f64000ae31d298b075a8722dfc51f294c71bc021
2025-11-18 09:04:56 +00:00

28 lines
663 B
JavaScript

import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
import { db } from '../app/src/infrastructure/mongodb.js'
const MODEL_NAME = process.argv.pop()
const { [MODEL_NAME]: Model } = await import(
`../app/src/models/${MODEL_NAME}.mjs`
)
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(
db[Model.collection.name],
{},
async nextBatch => {
processBatch(nextBatch)
},
{} // fetch the entire record
)