-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.coffee
41 lines (37 loc) · 1.16 KB
/
user.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# User Class - Handles all user functions
config = require './config.coffee'
cradle = require 'cradle'
class User
constructor: (host, port, collection) ->
@.connect = new cradle.Connection host, port, {
secure: false
auth: {
username: config.mainDBUser
password: config.mainDBPass
}
cache: true
raw: false
}
@.db = @.connect.database collection
findByTwitterId: (mykey, callback) ->
@.db.view 'spark-user/byTwitterId', {key: JSON.stringify(mykey)}, (err, res) ->
if (err)
callback err, null
else
if res.length>0
callback null, res[0]
else
callback null, res
findById: (mykey, callback) ->
@.db.view 'spark-user/byid', {key: JSON.stringify(mykey)}, (err, res) ->
if (err)
callback err, null
else
if res.length>0
callback null, res[0]
else
callback null, res
saveById: (id, data, callback) ->
@.db.save id, data, (err, res) ->
callback err, res
exports.User = User