jirevwe
10/19/2018 - 4:44 PM

Params not valid

Params not valid

exports.paramsNotValid = (...args) => args
  .map(param => param !== undefined && param != null && param !== '')
  .includes(false)
/**
 * @method POST /api/projects
 * @description creates a project
 * @param name project name
 * @param description project description
 * @param beneficiary the charity that benefits from the project
 * @param image the project's cover image
 * @param goal the target amount to be raised by the project
 * @param category the project category
 */
router.post('/', authorization, async (r, s) => {
  try {
    const not_valid = await checkParamsValid(
      r.body.name,
      r.body.description,
      r.body.beneficiary,
      r.body.goal,
      r.body.category
    )

    if (not_valid) {
      return s.status(412).json({
        status: 'Precondition Failed',
        message: 'Some parameters should not be null or be empty'
      })
    }

    const project = await Project.create(r.body)
    return s.status(200).json({
      status: 'Project Created',
      data: project
    })
  } catch (error) {
    return s.status(400).json({
      status: 'Failed',
      message: error
    })
  }
})