sails.js

Sails.js + Waterline: Many-to-Many through association

 ̄綄美尐妖づ 提交于 2019-12-07 03:09:31
问题 I'm new to Sails.js (v0.10.5) and Waterline ORM. I have 3 tables in database: users (id, name), roles(id, alias) and join table users_roles(user_id, role_id). It's important not to change table names and field names in database. I want Policy entity to be a join entity between User and Role. Here is some mapping code: //User.js module.exports = { tableName: 'users', autoCreatedAt: false, autoUpdatedAt: false, attributes: { id: { type: 'integer', required: true }, name: { type: 'string' },

Sails JS forbidden POST request

99封情书 提交于 2019-12-07 02:18:23
问题 I'm trying to learn Sails JS and obviously REST API. I've created a user model wich I think works fine (it communicates datas with my db). I've also created a signup controller with 4 needed inputs to store a new record in my user collection. (Some other datas are generated by this controller to complete the record at the moment of the registration) I would like to test this controller with POSTMAN, so I go to my routes.js and see : 'POST /api/v1/entrance/signup': { action: 'entrance/signup'

How to set local timezone in Sails.js or Express.js

烈酒焚心 提交于 2019-12-07 01:56:48
问题 When I create or update record on sails it write this at updateAt: updatedAt: 2014-07-06T15:00:00.000Z but I'm in GMT+2 hours (in this season) and update are performed at 16:00. I have the same problem with all datetime fields declared in my models. How can I set the right timezone on Sails (or eventually Express) ? 回答1: The way I handled the problem after hours of research : Put process.env.TZ = 'UTC'; //whatever timezone you want in config/bootstrap.js 回答2: I solved the problem, you should

how to use the attribute type like 'array' and 'json' in sails

為{幸葍}努か 提交于 2019-12-07 00:54:05
问题 Sails have support very convenient model througth Waterline, and I have used the 'array' attribute type in the way storing many string, but now I want to store more complex object, Although I can store the raw data in mongo by 'array' type, I don't know if it is safe and I want define the object type in the array, like mongoose's style. for example, I need a model "Products" and I want define it as a 'array' but the object stored in the array only model "Book", what I can do like this, but I

Sails js route static html

扶醉桌前 提交于 2019-12-07 00:07:34
I want to completely separate the client and server sides in my sails js app. If I remove the '/' route, automatically it will serve a file named index.html from the 'assets' folder. I want to serve another file from the assets folder, how can I do it? hawkcurry If you look at the middlewares that sails uses config/http.js order: [ 'startRequestTimer', 'cookieParser', 'session', 'myRequestLogger', 'bodyParser', 'handleBodyParserError', 'compress', 'methodOverride', 'poweredBy', '$custom', 'router', 'www', 'favicon', '404', '500' ], We can see that it tries to match the current request with the

Sails.js + Passport.js getting current logged in user

寵の児 提交于 2019-12-07 00:06:12
问题 I have a sails app that I'm working with and I'm using passport.js for user auth. I have login working, along with policies that protect my pages, all systems go. On one of my pages the user is inputting information, so I need to get the current logged in user's id. I struggled with this but eventually came up with using a route In the controller $scope.$on('sailsSocket:connect', function(ev, data) { sailsSocket.get( '/get_user', {}, function(response) { $scope.team_id = response.user;

How to embed and write mongo objects in Sails.js (more than one level deep)?

偶尔善良 提交于 2019-12-06 23:47:07
问题 From sails.js example, // Person.js var Person = { attributes: { firstName: 'STRING', lastName: 'STRING', age: { type: 'INTEGER', max: 150, required: true } birthDate: 'DATE', phoneNumber: { type: 'STRING', defaultsTo: '111-222-3333' } emailAddress: { type: 'email', // Email type will get validated by the ORM required: true } } }; Now how would I add emailAddress to have a home and office as embedded fields? Tried to do it this way: emailAddress: { { work: { type: 'email', }, personal: { type

npm not install underscore packages

寵の児 提交于 2019-12-06 15:43:04
I want to install packages with npm : my packages file is: "dependencies": { "express": "~3.3.6", "socket.io": "0.9.16", "jade": "~0.35.0", "less-middleware": "~0.1.12", "redis": "~0.8.4", "connect-redis": "~1.4.5", "longjohn": "~0.2.1", "mongoose": "~3.6.20", "json-stringify-safe": "~5.0.0" }, "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "~0.2.2", "grunt-nodemon": "~0.1.0", "grunt-contrib-jshint": "~0.6.3", "grunt-contrib-less": "~0.7.0", "grunt-ngmin": "0.0.3" } } but i have this error : npm http 304 https://registry.npmjs.org/underscore.string npm ERR! Error: No

Setting selected item in angular md-select with multiple option

佐手、 提交于 2019-12-06 15:33:36
问题 Setting selected item in angular md-select with multiple option <md-select multiple ng-model="Reg.roles" placeholder="Please select roles" required> <md-option ng-repeat="role in roles" value="{{role.value}}" ng-selected="{{ role.value === '<%= data.roles %>' ? 'true' : 'false' }}">{{ role.name }}</md-option> </md-select> in my controller $scope.roles = [{ "name": "Account Admin", "value": "account_admin" }, { "name": "Developer", "value": "developer" }, { "name": "Analyst", "value": "analyst

whitespaces when adding partial template using EJS

眉间皱痕 提交于 2019-12-06 14:39:11
I am using SailsJS with EJS engine. When I add partials using <% include partials/template.ejs %> or <% partial('partials/template.ejs') in the layout file, I get whitespaces before the compiled HTML code (template.ejs). Note that when I copy paste the template.ejs content in the layout (not using include/partials) the whitespaces are gone. See images below: 1st part: code. 2nd part: chrome DOM. 3rd part: whitespace element inspection (DOM properties) I have faced the same problem. What I did was very simple. Go to ejs module index.js file. Find partial function. Find this part of code: var