{"id":103,"date":"2015-02-08T03:56:36","date_gmt":"2015-02-08T03:56:36","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=103"},"modified":"2015-02-08T03:56:36","modified_gmt":"2015-02-08T03:56:36","slug":"csmsc-create-sailsjs-model-and-controller-w-node-command-line-2","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=103","title":{"rendered":"csmsc \u2013 Create SailsJS Model and Controller w Node Command Line"},"content":{"rendered":"<p>Published a node command module to automate the creation of Models and Controllers for a SailsJS api.<\/p>\n<h1>csmsc<\/h1>\n<p>This is a node.js command line utility that creates SailsJS base Models and Controllers for API use.<\/p>\n<h2>Installation<\/h2>\n<p>This utility is available on npm. Globally install it by using the <strong>-g<\/strong> flag:<\/p>\n<p><code>bash<br \/>\nnpm install -g csmsc<\/code><\/p>\n<h2>Usage<\/h2>\n<p>To use it, <code>cd<\/code> into a project directory, and run <code>csmsc<\/code> with -n and -f args to represent model name and properties respectively.<\/p>\n<h3>Examples<\/h3>\n<p>Make a model and controller for &#8216;modelName&#8217; with properties &#8216;primaryproperty&#8217;, &#8216;anotherproperty&#8217; and &#8216;aThirdproperty&#8217;:<\/p>\n<p><code>bash<br \/>\ncsmsc -n ModelName -f firstprop,secondprop,thirdprop<\/code><\/p>\n<p><code>bash<br \/>\ncsmsc -n ModelName -f title,url,subtitle,text,author -c tags -m company<\/code><\/p>\n<h3>Notes<\/h3>\n<p>SailsJS expects controllers and models to be created using Pascal Case please appropriately name Models with the first character uppercase to ensure compatibility.<\/p>\n<p>csmsc will write the model into the api\/models\/ folder. csmsc will write the controller into the api\/controllers\/ folder.<\/p>\n<p>Existing files will be over written.<\/p>\n<p>Model properties are string by default, modify as needed.<\/p>\n<p>MongoDb will add the following<\/p>\n<pre><code>_id as a unique identifier.\ncreatedAt date created.\nupdatedAt date last updated.\n<\/code><\/pre>\n<p>csmsc will add the following<\/p>\n<pre><code>createdBy user that created the record.\nupdatedBy user that last updated the record.\n<\/code><\/pre>\n<p>createdBy and updatedBy values must be passed to the api or will default to &#8216;admin&#8217;<\/p>\n<h3>Additional Notes<\/h3>\n<h4>GENERATE model and Sails controller for SailsJS api<\/h4>\n<pre><code>-n is the name of the model and controller.\n-f is a list of comma separated fields\n-c is a list of comma separated collections (one to many)\n-m is a list of comma separated models (one to one)\n<\/code><\/pre>\n<p>the first field in the field list is considered the primary field.<\/p>\n<h4>CREATE Sails model and Sails controller EXAMPLE FROM COMMAND LINE<\/h4>\n<pre><code>csmsc -n NewModel -f one,two,three \n<\/code><\/pre>\n<h4>MODEL &#8211; Returns model definition for frontend Validation Error Checking<\/h4>\n<pre><code>http:\/\/localhost:1337\/newmodel\/model\/\n<\/code><\/pre>\n<h4>DISPLAYORDER &#8211; Returns list of fields for ordered Dynamic view presentation<\/h4>\n<pre><code>http:\/\/localhost:1337\/newmodel\/displayOrder\/\n<\/code><\/pre>\n<h4>GET &#8211; Returns ID AND PRIMARY fields for dropdowns \/ suggestive lists<\/h4>\n<pre><code>http:\/\/localhost:1337\/newmodel\/get\/\n<\/code><\/pre>\n<p>mongodb&#8217;s auto generated id will be used as the key primaryFild will be the value for that key<\/p>\n<h4>SEARCH &#8211; Returns results after searching primary or specified field for string<\/h4>\n<pre><code>http:\/\/localhost:1337\/newmodel\/search\/la?field=ObjectName\n<\/code><\/pre>\n<p>Search string follows the slash<\/p>\n<p>Field string is optional and follows ?field=<\/p>\n<p>Using a search string without a field name will search the primary field \/ node of the object.<\/p>\n<p>Using a search string with a field name specified will search the specified field \/ node for the string provided.<\/p>\n<h4>LIMIT, SKIP<\/h4>\n<pre><code>Limit\n\n    &amp;limit=\n\nSkip\n\n    &amp;skip= \n<\/code><\/pre>\n<h4>SORT<\/h4>\n<p>Implementation is not complete, this is a placeholder.<\/p>\n<p>https:\/\/www.npmjs.com\/package\/csmsc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Published a node command module to automate the creation of Models and Controllers for a SailsJS api. csmsc This is a node.js command line utility that creates SailsJS base Models and Controllers for API use. Installation This utility is available on npm. Globally install it by using the -g flag: bash npm install -g csmsc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":2,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":105,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/105"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}