Return external data in ctx.send from custom controller

I figured it out, using returns to resolve the promise and then returning that again, see below works:

module.exports = {

    async index(ctx) {

        const tourId = ctx.params.id;

         let tour = new Promise((resolve, reject)=> {
            TourCMS.showTour({
                channelId: channelId,
                tourId: tourId,
                callback: (response) => {
                    resolve(response)
                }
            });
         })

        return tour.then(response => {
            return response;
        }).catch(error => {
            console.log(error);
        })            
    }
};
1 Like