TransforMap / data.transformap.co

Here you find a Node.js daemon to serve the public TransforMap web service.
https://data.transformap.co
GNU Affero General Public License v3.0
7 stars 2 forks source link

Search by username #47

Closed jum-s closed 7 years ago

jum-s commented 7 years ago

A user type is created. Posting a new user through  breq.post(CONFIG.server.url() + '/user', newUser) is working. But how to look for a user thing that has the name "foo" ? Is it possible with those methods in build_lib My best try without documentation was something like db.viewByKey('byAttributes',['user', 'name'])

jum-s commented 7 years ago

everything is in this file, so far a mocked user is the answer but i would like to create this findOneByUsername

  findOneByUsername: function (username) {
    // Fake user
    const wannabeUser = {
      journal: 'bcf4f3ff325d7c8c7a5f67320e01a3f0',
      data:
       { name: 'moleculor',
         email: 'vincent.jumeaux@riseup.net',
         provider: 'https://lab.allmende.io/u/moleculor' },
      author: 'Douglas Adams',
      description: 'Have fun, and thanks for all the fish!',
      context: 'version',
      timestamp: 1504438602552
    }
    if (wannabeUser.data.name == username) {
      _.success(wannabeUser.data.name, 'existing user')
      return promises_.resolve(wannabeUser)
    } else {
      _.error('user not found')
      // not returning an Error object as it triggers a 500 response
      return promises_.reject(wannabeUser)
    }
  }
maxlath commented 7 years ago

there is no trace of a users CouchDB database being initialized in db/init.js dbsList: it could be simply something like { name: 'users', designDocs: [ 'users' ] }.

Then couchInit will be looking for the file db/design_docs/users.json that you need to create. See CouchDB Design docs documentation, but read only about views, the other functions - reduce, re-reduce, list, show - aren't much needed (the last two being mostly legacy). You can take inspiration on the existing journals design doc or inventaire's own users design doc.

maxlath commented 7 years ago

Then, as for things, you can have a lib file that handles all the interactions with the users database, thus initializing a db object like so:

const db = __.require('lib', 'db/db')('users', 'users')
jum-s commented 7 years ago

great answer thx