Git Product home page Git Product logo

locus-backend's Introduction

Locus Backend

This repository serves as the backend API for the Locus app. Everything is written in ES6+, so Babel is used to transpile into ES5.

Getting Started

The API uses MongoDB, so make sure it's installed.

Run a new instance of MongoDB:

sudo mongod

Start running the server:

npm start

The API listens onto a dynamic IP address for development. This address will be given after running the above command.

Development

Flow is being used to allow for statically typed JavaScript, make sure it's installed globally.

After creating new methods, run the following command and deal with any output properly:

flow

No unit or integration tests have been written yet, however they will be using Mocha and Chai.

To run unit tests:

npm test

Production

Since ES6+ is not understood natively, a transpiled build needs to be created before pushing to a live production server. To create this build, run the following command:

npm run build

This command will generate a new build directory with files in ES5.

API

Model Notes

Stats

Property Description Type Default Value
msrp Manufacturer's suggested retail price in local currency. Number

Location

  • lat, long
  • address eg. 123 Main Street

locus-backend's People

Contributors

jadnco avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

locus-backend's Issues

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));
  }

Diagrams

Apparently, GitHub does not support relative SVG images.

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

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.