summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/lib/star.js
blob: 5b7ab4afe9059d4bebc45ee81f61cbea8bc1d7a9 (plain)
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

module.exports = star

function star (package, starred, cb) {
  if (!this.conf.get('username')) return cb(new Error(
    "Must be logged in to star/unstar packages"))

  var users = {}

  this.request("GET", package, function (er, fullData) {
    if (er) return cb(er)

    fullData = { _id: fullData._id
               , _rev: fullData._rev
               , users: fullData.users || {} }

    if (starred) {
      this.log.info("starring", fullData._id)
      fullData.users[this.conf.get('username')] = true
      this.log.verbose("starring", fullData)
    } else {
      delete fullData.users[this.conf.get('username')]
      this.log.info("unstarring", fullData._id)
      this.log.verbose("unstarring", fullData)
    }

    return this.request("PUT", package, fullData, cb)
  }.bind(this))
}