sails.js

sails.js - how can I acess session data in Model hook beforeCreate

匆匆过客 提交于 2019-11-30 21:02:27
I want to update a field 'owner' of a Model. The owner needs to be fetched from the session which contains the user who is currently logged in and is creating the Model. I want something like this: Model = { attributes: { }, beforeCreate(values,next) { var owner_user_id = req.session.user_id; values.owner = owner_user_id; next(); } } Are you sure a lifecycle callback is the right place to do it? Because it's really not. What if tomorrow you'll need to use your model in a CLI task or something else sessionless? Besides, with the associations API coming, there will be, probably, a more elegant

Sails.js Model: create 2 association to self failed

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:27:14
I'm pretty new on Nodejs and sails. I'm implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fields are association of the model 'user' itself. My question is when the model have only 1 association, either follower or following, it works. However, when both follower and following included, there would be en error. The code is something like this: module.exports = { attributes: { alias: { type:'string', required: true, primaryKey: true }, pwd: { type: 'string', required: true }, follower: { collection: 'user', via: 'alias

sails-mysql schema datatypes

喜夏-厌秋 提交于 2019-11-30 19:40:59
anyone used node's sails framework using mysql as DB ( https://github.com/balderdashy/sails-mysql )? I am stuck in models, I can't create the database structure.The datatypes that I need to use to create the schema doesn't work. I've searched everywhere for some documentation, but i can't find anything that can help me. Sail's documentation is not yet complete, i guess. http://sailsjs.org/#documentation/models Can anyone please help me in creating models. I would highly appreciate if you can help me create the simple schema below using sails-mysql. Thanks in advance! module.exports = {

Sails.js rolling sessions

血红的双手。 提交于 2019-11-30 18:20:29
问题 A rolling session is a session that expires in a set amount of time should there be no user activity(excluding websockets live updating data). If the user visits another part of the site before expiry, the expiry should then be extended. How would I do this with Sails.js? Setting maxAge and expires under cookie in /config/session.js does not have the desired effect. The expiry does not get extended with another page load. It stays constant. EDIT: Will this be resolved once Sails.js upgrades

Architecture of an app when using CouchDB/PouchDB

蹲街弑〆低调 提交于 2019-11-30 17:52:59
问题 I am wondering how the architecture should look like when using PouchDB as a local storage in a mobile app instead of localStorage . At this moment I am used to cache my app's data into localStorage and when needed I perform an API call to the backend to request or post data. The backend is holding all logic. Such as: Does this user has the correct permission/role to do this action? Any other logic needed to check if action can be done All data is then stored into a relational database. I

Sails workaround for deep populate

房东的猫 提交于 2019-11-30 17:25:42
问题 I'm trying to deep populate a collection. For example // UnitType.js name: { type: 'string' } // Unit.js unitType: { model: 'unitType', via: '_id', required: true, index: true } // Product.js unit: { model: 'unit', via: '_id', required: true, index: true }, The problem is, that - as far I know from internet research deep populate like Product.find().populate('unit.unitType'); is currently not supported in sails. To achieve the result I want I currently query Products with populate unit query

I am confused with Sails.js waterline one-to-one association logic

风格不统一 提交于 2019-11-30 15:39:19
So the reason why im confused, because I am a PHP developer and used Laravel and FuelPHP alot What i dont really understand is the association it self. What i mean, i wanted to create a basic hasOne / BelongsTo logic, with the following User has one profile Profile belongs to an user I am used to the following build up (Laravel style) Users table id | username | email | password --------------------------------------- 1 | My Username | My email | 1234568 Users_profile table user_id | first_name | last_name ---------------------------------------- 1 | My First name | My Last name Then i just

Sails.js: How to actually run tests

余生长醉 提交于 2019-11-30 14:21:17
I'm completely new to sails, node and js in general so I might be missing something obvious. I'm using sails 0.10.5 and node 0.10.33. In the sails.js documentation there's a page about tests http://sailsjs.org/#/documentation/concepts/Testing , but it doesn't tell me how to actually run them. I've set up the directories according to that documentation, added a test called test/unit/controllers/RoomController.test.js and now I'd like it to run. There's no 'sails test' command or anything similar. I also didn't find any signs on how to add a task so tests are always run before a 'sails lift'.

Argument must be a string in nodejs

孤者浪人 提交于 2019-11-30 13:51:33
I'm having the following code: var objectid = infos[i].id; var name = infos[i].name; return collection.aggregate([ {$match: {app: new ObjectId(objectid)}}, {$group: {_id: "$uid", amt: {$sum: 1}}} ]) Previously this code was working fine, but recently I started getting the below stacktrace in sails: error: TypeError: Argument must be a string at TypeError (native) at Buffer.write (buffer.js:791:21) at serializeObjectId (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:242:10) at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo

Specify returned fields in Node.js / Waterline?

自闭症网瘾萝莉.ら 提交于 2019-11-30 13:43:57
I want to make a request like: User.find().exec(function(){}); I know I can use toJSON in the model however I don't like this approach since sometimes I need different parameters. For instance if it's the logged in user I will return their email and other parameters. However if it the request fort he same data is made by a different user it would not include the email and a smaller subset of parameters. I've also tried using: User.find({}, {username:1}) ... User.find({}, {fields: {username:1}}); But not having any luck. How can I specify the fields I need returned? So actually found a weird