const Boom = require('boom');
const hostService = require('../../domain/services/host-service');
const eventService = require('../../domain/services/event-service');

module.exports = {
    create(request, reply) {
        const { user } = request.payload;
        const { event } = request.payload;

        return hostService
            .createHost(user)
            .then((userId) => {
                const eventDetails = Object.assign({}, { userId }, event);
                return eventService.createEvent(eventDetails);
            });
    }
};
@@ -220,25 +220,51 @@
     
-const %7B user %7D = 
+return hostService%0A            .createHost(
 requ
@@ -274,17 +274,22 @@
 .payload
-;
+.user)
 %0A       
@@ -293,99 +293,181 @@
     
-const %7B event %7D = request.payload;%0A%0A        return hostService%0A            .createHost(user
+    .then((%7B _id: userId %7D) =%3E %7B%0A                return eventService.createEvent(userId, request.payload.event);%0A            %7D)%0A            .then(url =%3E reply(url).code(201)
 )%0A  
@@ -481,20 +481,18 @@
    .
-then((userId
+catch((err
 ) =%3E
@@ -520,144 +520,191 @@
 nst 
-eventDetails = Object.assign(%7B%7D, %7B userId %7D, event);%0A                return eventService.createEvent(eventDetails);%0A            %7D);%0A    %7D%0A%7D;
+statusCode = _getErrorStatusCode(err);%0A                reply(err).code(statusCode);%0A            %7D);%0A    %7D%0A%7D;%0A%0Afunction _getErrorStatusCode(err) %7B%0A    return ('name' in err) ? 500 : 422;%0A%7D

Add little error management in event route