dss-server / src /utils /objectId.js
yeshwanth-kr's picture
Upload 43 files
8c7b7ca verified
raw
history blame contribute delete
431 Bytes
const { Types } = require('mongoose');
function toValidObjectIdStrings(values = []) {
const ids = new Set();
for (const value of values) {
if (value === null || value === undefined) continue;
const normalized = String(value).trim();
if (!normalized) continue;
if (Types.ObjectId.isValid(normalized)) {
ids.add(normalized);
}
}
return [...ids];
}
module.exports = {
toValidObjectIdStrings
};