Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'findOne' method doesn't work by following examples #142

Open
jmcartlamy opened this issue May 11, 2017 · 0 comments
Open

'findOne' method doesn't work by following examples #142

jmcartlamy opened this issue May 11, 2017 · 0 comments

Comments

@jmcartlamy
Copy link

jmcartlamy commented May 11, 2017

Issue

By following example on kakapo.js and others to use findOne method, it seems that it doesn't work as well as expected.

It return an empty object instead of my selected data. To fix that, i have to replace

db.findOne('users', userId );

with

db.findOne('users', user => user.id === +userId );

Complete example

export default (router, database) => {
  database.register('users', () => ({
    name: 'Henry',
    phone:  1234567890,
  }));

  database.create('users', 5);

  router.get('/users/:userId', (req, db) => {
    const userId = req.params.userId;
    return db.findOne('users', user => user.id === +userId );
  });
};
import { Database, Router, Server } from 'kakapo';
import mockUsers from './users';

const db = new Database();
const router = new Router();
const server = new Server();

mockUsers(router, db);

server.use(db);
server.use(router);
fetch('/users/2', user => {
  console.log(user);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant