multy-stub/server/routers/old/stc-22-24/utils/common.js
Primakov Alexandr Alexandrovich 4b0d9b4dbc mongoose + tests
2024-10-16 11:06:23 +03:00

35 lines
510 B
JavaScript

const _idToId = (data) => {
const { _id, ...rest } = data
return {
id: _id,
...rest,
}
}
const _idToIdArray = (data) => {
const _idToIdMap = data.map((item) => _idToId(item))
return _idToIdMap
}
const getResponse = (error, data, success = true) => {
if (error) {
return {
success: false,
error,
}
}
return {
success,
data,
}
}
module.exports = {
getResponse,
_idToIdArray,
_idToId,
}