19 lines
531 B
JavaScript
19 lines
531 B
JavaScript
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 }
|