Last active
August 29, 2015 14:17
-
-
Save wayne-o/48c2dfe8d4d4cf5ddba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ListingEvent.js | |
module.exports = { | |
tableName: 'listingEvent', | |
attributes: { | |
name: { type: 'string' }, | |
start: { type: 'date' }, | |
end: { type: 'date' }, | |
eventInstanceSlug: { type: 'string' }, | |
location: { | |
model:'location' | |
}, | |
artists: { | |
collection: 'artist', | |
via: 'listingEvents' | |
}, | |
users: { | |
collection: 'user', | |
via: 'listingEvents' | |
} | |
} | |
}; | |
//User.js | |
module.exports = { | |
attributes: require('waterlock').models.user.attributes({ | |
email: 'string', | |
username: 'string', | |
images: { | |
collection: 'image', | |
via: 'user' | |
}, | |
avatarImage: { | |
model: 'image' | |
}, | |
listingEvents: { | |
collection: 'listingEvent', | |
via: 'users' | |
} | |
}), | |
beforeCreate: require('waterlock').models.user.beforeCreate, | |
beforeUpdate: require('waterlock').models.user.beforeUpdate | |
}; | |
/** | |
* FilteredLineupController | |
* | |
* @description :: Server-side logic for managing Filteredlineups | |
* @help :: See http://links.sailsjs.org/docs/controllers | |
*/ | |
var winston = require('winston'); | |
module.exports = { | |
find: function(req, res) { | |
var name = req.param("name"); | |
var currentUserAttending = req.param("currentUserAttending"); | |
var location = req.param("location"); | |
var sort = req.param("sort"); | |
var eventInstanceSlug = req.param("eventInstanceSlug"); | |
var limit = req.param("limit"); | |
var skip = req.param("skip"); | |
var userId = req.session.user != null ? req.session.user.id : null; | |
User.findOne().where({ | |
id: userId | |
}) | |
.populate('listingEvents') | |
.then(function(user) { | |
var attendingIds = new Array(); | |
if (user !== undefined && user != null) { | |
for (var i = 0; i < user.listingEvents.length; i++) { | |
var le = user.listingEvents[i]; | |
attendingIds.push(le.id); | |
} | |
} | |
var q = ListingEvent.find().where({ | |
eventInstanceSlug: eventInstanceSlug | |
}); | |
q.populate('users'); | |
q.populate('location'); | |
if (name != undefined && name != null && name !== '') { | |
q.where({ | |
name: { | |
startsWith: name | |
} | |
}); | |
} | |
if (location != undefined && location != null && location !== '') { | |
q.where({ | |
location: { | |
name: { | |
startsWith: location | |
} | |
} | |
}); | |
} | |
//fails | |
if (currentUserAttending === 'true' && req.session.user != undefined && req.session.user != null) { | |
q.where({ | |
users: { | |
id: req.session.user.id | |
} | |
}); | |
} | |
q.skip(skip); | |
q.limit(limit); | |
q.exec(function(err, results) { | |
if (err) { | |
winston.error(err); | |
} | |
/*if (user !== null) { | |
for (var i = 0; i < results.length; i++) { | |
if (attendingIds.indexOf(results[i].id) > -1) { | |
results[i].currentUserAttending = true; | |
} | |
} | |
}*/ | |
return res.ok(results); | |
}); | |
}); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the error: