implementation from the prompt

This commit is contained in:
2026-10-09 13:21:38 -04:00
parent f29b77bcab
commit 40dfd6252d
9 changed files with 192 additions and 47 deletions

View File

@@ -0,0 +1,18 @@
const mongoose = require('mongoose')
const requireUserId = (userId) => {
if (typeof userId !== 'string' || !/^[a-f\d]{24}$/i.test(userId)) {
throw new Error('A valid job userId is required')
}
return userId
}
const tenantFilter = (filter) => {
if (!filter || typeof filter !== 'object') {
throw new Error('A tenant-scoped filter is required')
}
const userId = requireUserId(filter.userId)
return { ...filter, userId: new mongoose.Types.ObjectId(userId) }
}
module.exports = { requireUserId, tenantFilter }