Skip to content

Instantly share code, notes, and snippets.

@jkresner
Created July 16, 2015 20:57
Show Gist options
  • Save jkresner/b5b1774e957f1ecbcb94 to your computer and use it in GitHub Desktop.
Save jkresner/b5b1774e957f1ecbcb94 to your computer and use it in GitHub Desktop.
Aliasing anonymous to identified users
var ViewsCollection = require('../models/view').collection
var viewSvc = {
getByUserId(userId, cb)
{
if (logging) $log('views.getByUserId'.trace, userId)
ViewsCollection.find({userId}).sort({_id:-1}).toArray((e, r) => cb(r))
},
getByAnonymousId(anonymousId, cb)
{
if (logging) $log('views.getByAnonymousId'.trace, anonymousId)
ViewsCollection.find({anonymousId}).sort({_id:-1}).toArray((e, r) => cb(r))
},
alias(anonymousId, userId, cb)
{
if (logging) $log('views.alias'.trace, anonymousId, userId)
userId = ObjectId(userId)
ViewsCollection.update({anonymousId}, {$set:{userId}}, { multi: true }, cb)
},
create(o, cb)
{
if (logging) $log('views.create'.trace, o)
ViewsCollection.insert(o, cb)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment