Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Sails.js example #109

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Created Sails.js example #109

wants to merge 5 commits into from

Conversation

neonexus
Copy link
Contributor

@neonexus neonexus commented Dec 6, 2023

This is a stripped-down version, of my working example I've been cultivating for a bit now, on my open-source repo (terrible name I know, but it gets the point across): sails-react-bootstrap-webpack.

START RANT

I've spent time on this, mostly because I feel like Sails doesn't get enough credit / recognition. The Node-Machine idea that @mikermcneil came up with years ago I always felt was better than TypeScript. It's what drives Sails' main features, and looks like this:

module.exports = {
    friendlyName: 'Create User',

    description: 'Create a new user.',

    inputs: {
        firstName: {
            type: 'string',
            required: true,
            maxLength: 70
        },

        lastName: {
            type: 'string',
            required: true,
            maxLength: 70
        },

        password: {
            type: 'string',
            maxLength: 70
        },

        email: {
            type: 'string',
            isEmail: true,
            required: true,
            maxLength: 191
        }
    },

    exits: {
        created: {
            responseType: 'created'
        },
        badRequest: {
            responseType: 'badRequest'
        },
        serverError: {
            responseType: 'serverError'
        }
    },

    fn: (inputs, exits) => {
           // Run your main controller code here; using `inputs` as pre-validated inputs, and exits as if `async` by default.

            return exits.created({user});
        });
    }
};

It's easily human and computer readable. Can very simply be consumed by documentation generation. Why the world decided TypeScript was better is beyond me.

END RANT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant