'use strict';

const Boom = require('boom');
const Organization = require('../model/Organization');

const internals = {};

internals.validateObjectId = require('../helpers/validateObjectId');

internals.fieldsToReturn = require('../helpers/fieldsToReturn');

internals.getOrganizationById = function (id) {

    return Organization.findById(id, internals.fieldsToReturn)
      .then((org) => {

          return org;
      })
      .catch((err) => {

          return Boom.badImplementation(err);
      });
};

internals.requestHandler = function (request, reply) {

    const id = request.params.id;

    if (!internals.validateObjectId(id)){
        return reply(Boom.badRequest('Must provide a valid organization id'));
    }
    return reply(internals.getOrganizationById(request.params.id));
};

module.exports = {
    path: '/api/organizations/{id}',
    method: 'GET',
    handler: internals.requestHandler
};

@@ -381,32 +381,112 @@
 hen((org) =%3E %7B%0A%0A
+          if (org === null) %7B%0A              return Boom.notFound();%0A          %7D%0A
           return

Fix GetById should return 404