Giter VIP home page Giter VIP logo

locus-backend's People

Contributors

jadnco avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

locus-backend's Issues

Diagrams

Apparently, GitHub does not support relative SVG images.

This issue will be used to upload images and get absolute URLs.

Clean up Spot routes

This issue mostly has to do with this:

router.route('/users/:id/spots')
  .get((req, res) => {
    User.getSpots(req.params.id, req, res);
  })
  .post((req, res) => {
    Spot.create(req.params.id, req, res);
  })
  .delete((req, res) => {
    Spot.remove(req.params.id, req, res);
  });

What I need to figure out is:

  • Does a new Spot get created at users/:id/spots or just /spots
  • Does the spotter id association come from the :id in the URL or is it sent as part of the body.

Look into async flow

The backend is now at a point where there are many associated relationships between models, this is introducing a new problem regarding asynchronous flow.

This is the current state of the User.create method. As associations grow, promises end up being called within promises.

I'm not liking where this is heading, I can only imagine having to add more relationships โ€“ which will make this code even harder to keep track of.

I think it's worth it to look into ES6 generators โ€“ static *create() { yield; }. Also looking into this will help in understanding iterators in general.

static create(req: Object, res: Object): void {
    let user = new User(req.body.user);
    let followers = new Followers();
    let spots = new Spots();

    // Define user -> followers association
    user.users = followers._id;
    followers.user = user._id;

    // Define user -> spots association
    user.spots = spots._id;
    spots.user = user._id;

    // Persist the user record
    user.save()
      .then(_user => {

        // Persist the associated followers record
        followers.save()
          .then(() => {

            // Persist the associated spots record
            spots.save()
              .then(() => res.json({ user: _user }))
              .catch(err => res.send(err));
          })
          .catch(err => res.send(err));
      })
      .catch(err => res.send(err));
  }

User authentication

A login system needs to be set up for users. I don't think it's necessary to have a custom system for this, being able to login with either Twitter or Facebook would suffice.

This Passport middleware for Express should make things super easy: https://github.com/jaredhanson/passport

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.