mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
22 lines
614 B
JavaScript
22 lines
614 B
JavaScript
// check if exists all required fields inside the obj (can be a object or an array)
|
|
// if is something is missing, throw an error
|
|
export default (fields, obj) => {
|
|
const missing = []
|
|
const isArray = Array.isArray(obj)
|
|
|
|
for (const field of fields) {
|
|
if (isArray) {
|
|
if (!obj.includes(field)) {
|
|
missing.push(field)
|
|
}
|
|
} else {
|
|
if (!obj[field]) {
|
|
missing.push(field)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (missing.length > 0) {
|
|
throw new OperationError(400, `Missing required fields: ${missing.join(", ")}`)
|
|
}
|
|
} |