jadnco / locus-backend Goto Github PK
View Code? Open in Web Editor NEWRESTful API for car spotting app
RESTful API for car spotting app
Apparently, GitHub does not support relative SVG images.
This issue will be used to upload images and get absolute URLs.
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:
users/:id/spots
or just /spots
spotter
id association come from the :id
in the URL or is it sent as part of the body.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));
}
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
Before this app goes live (or if it goes live) the images should just be able to get uploaded and saved onto my personal machine.
Obviously, this shouldn't be an issue because I will be the only person using it.
Using the module multer
will make this easy; https://www.terlici.com/2015/05/16/uploading-files-locally.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.