const getAnswer = (errors, data, success = true) => { if (errors) { return { success: false, errors } } else { return { success, body: data } } } function generateCode(length) { return Array.from(Array(length)).map(_un => Math.floor(Math.random() * 9)).join('') } function cleanId(entity) { if (Array.isArray(entity)) { return entity.map(cleanId) } const { _id, ...other } = entity return { ...other, id: _id } } function withoutPassword(user) { const { password, ...cleanUser } = user return cleanUser } export { generateCode, getAnswer, cleanId, withoutPassword, }