2

I´m trying to figure out how to use Sails.js with the node-machine-syntax. This is the list action of my flights, simple, nothing crazy. I´m trying this:

/**
* FlightsController
*
* @description :: Server-side actions for handling incoming requests.
* @help        :: See https://sailsjs.com/docs/concepts/actions
*/

module.exports = {

 friendlyName: 'flights list',


 description: 'list all flights',

 exits: {
   success: {
     responseType: 'view',
     viewTemplatePath: 'pages/list'
   },
   notFound: {
     description: 'No flight was found in the database.',
     responseType: 'notFound'
   }
 },

 fn: async function (exits) {

   var flights = await Flights.find({});

   // If no flight was found, respond "notFound" (like calling `res.notFound()`)
   if (!flights) { return exits.notFound(); }

   // Display the hompage view.
   return exits.success({flights});
  }
};

But when I try to reach the page /list it shows me the 500 server-error page with this message: "TypeError: exits.success is not a function". I really dont understand it because thats the syntax the want you to use.. Its missing the "input" object, but I deleted it becouse I dont really need it, just want to output the flights in my datastore.. And it doesnt seems to fix the problem anyways.

Any ideas? Thank You!

My flight model it something like this:

module.exports = {

 attributes: {
   company:{
     type: 'string',
     required: true
   },
   takeoff:{
     type: 'string',
     required: false
   }
 },

};

And my page list.ejs literally shows the word 'LIST', just like that.

1 Answers1

1

You need to put also the inputs object, like this:

/**
* FlightsController
*
* @description :: Server-side actions for handling incoming requests.
* @help        :: See https://sailsjs.com/docs/concepts/actions
*/

module.exports = {

 friendlyName: 'flights list',


 description: 'list all flights',

 inputs: {},

 exits: {
   success: {
     responseType: 'view',
     viewTemplatePath: 'pages/list'
   },
   notFound: {
     description: 'No flight was found in the database.',
     responseType: 'notFound'
   }
 },

 fn: async function (inputs, exits) {

   var flights = await Flights.find({});

   // If no flight was found, respond "notFound" (like calling `res.notFound()`)
   if (!flights) { return exits.notFound(); }

   // Display the hompage view.
   return exits.success({flights});
  }
};
Dave
  • 1,912
  • 4
  • 16
  • 34