Skip to content

Commit

Permalink
Fixed all the routes I broke
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvautin committed Feb 5, 2018
1 parent 8cbfce1 commit bf67621
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-cart",
"version": "1.1.4",
"version": "1.1.5",
"description": "A fully functioning Node.js shopping cart with Stripe, PayPal and Authorize.net payments.",
"private": false,
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions routes/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ router.post('/customer/create', (req, res) => {
});

// render the customer view
router.get('/customer/view/:id?', common.restrict, (req, res) => {
router.get('/admin/customer/view/:id?', common.restrict, (req, res) => {
const db = req.app.db;

db.customers.findOne({_id: common.getId(req.params.id)}, (err, result) => {
Expand All @@ -82,7 +82,7 @@ router.get('/customer/view/:id?', common.restrict, (req, res) => {
});

// customers list
router.get('/customers', common.restrict, (req, res) => {
router.get('/admin/customers', common.restrict, (req, res) => {
const db = req.app.db;

db.customers.find({}).limit(20).sort({created: -1}).toArray((err, customers) => {
Expand All @@ -100,7 +100,7 @@ router.get('/customers', common.restrict, (req, res) => {
});

// Filtered customers list
router.get('/customers/filter/:search', common.restrict, (req, res, next) => {
router.get('/admin/customers/filter/:search', common.restrict, (req, res, next) => {
const db = req.app.db;
let searchTerm = req.params.search;
let customersIndex = req.app.customersIndex;
Expand Down
20 changes: 10 additions & 10 deletions routes/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require('fs');
const path = require('path');
const router = express.Router();

router.get('/products', common.restrict, (req, res, next) => {
router.get('/admin/products', common.restrict, (req, res, next) => {
const db = req.app.db;
// get the top results
db.products.find({}).sort({'productAddedDate': -1}).limit(10).toArray((err, topResults) => {
Expand All @@ -26,7 +26,7 @@ router.get('/products', common.restrict, (req, res, next) => {
});
});

router.get('/products/filter/:search', common.restrict, (req, res, next) => {
router.get('/admin/products/filter/:search', (req, res, next) => {
const db = req.app.db;
let searchTerm = req.params.search;
let productsIndex = req.app.productsIndex;
Expand Down Expand Up @@ -56,7 +56,7 @@ router.get('/products/filter/:search', common.restrict, (req, res, next) => {
});

// insert form
router.get('/product/new', common.restrict, (req, res) => {
router.get('/admin/product/new', common.restrict, common.checkAccess, (req, res) => {
res.render('product_new', {
title: 'New product',
session: req.session,
Expand All @@ -74,7 +74,7 @@ router.get('/product/new', common.restrict, (req, res) => {
});

// insert new product form action
router.post('/product/insert', common.restrict, (req, res) => {
router.post('/admin/product/insert', common.restrict, (req, res) => {
const db = req.app.db;

let doc = {
Expand Down Expand Up @@ -145,7 +145,7 @@ router.post('/product/insert', common.restrict, (req, res) => {
});

// render the editor
router.get('/product/edit/:id', common.restrict, (req, res) => {
router.get('/admin/product/edit/:id', common.restrict, (req, res) => {
const db = req.app.db;

common.getImages(req.params.id, req, res, (images) => {
Expand Down Expand Up @@ -176,7 +176,7 @@ router.get('/product/edit/:id', common.restrict, (req, res) => {
});

// Update an existing product form action
router.post('/product/update', common.restrict, (req, res) => {
router.post('/admin/product/update', common.restrict, (req, res) => {
const db = req.app.db;

db.products.findOne({_id: common.getId(req.body.frmProductId)}, (err, product) => {
Expand Down Expand Up @@ -256,7 +256,7 @@ router.post('/product/update', common.restrict, (req, res) => {
});

// delete product
router.get('/product/delete/:id', common.restrict, (req, res) => {
router.get('/admin/product/delete/:id', common.restrict, (req, res) => {
const db = req.app.db;

// remove the article
Expand All @@ -283,7 +283,7 @@ router.get('/product/delete/:id', common.restrict, (req, res) => {
});

// update the published state based on an ajax call from the frontend
router.post('/product/published_state', common.restrict, (req, res) => {
router.post('/admin/product/published_state', common.restrict, (req, res) => {
const db = req.app.db;

db.products.update({_id: common.getId(req.body.id)}, {$set: {productPublished: req.body.state}}, {multi: false}, (err, numReplaced) => {
Expand All @@ -299,7 +299,7 @@ router.post('/product/published_state', common.restrict, (req, res) => {
});

// set as main product image
router.post('/product/setasmainimage', common.restrict, (req, res) => {
router.post('/admin/product/setasmainimage', common.restrict, (req, res) => {
const db = req.app.db;

// update the productImage to the db
Expand All @@ -313,7 +313,7 @@ router.post('/product/setasmainimage', common.restrict, (req, res) => {
});

// deletes a product image
router.post('/product/deleteimage', common.restrict, (req, res) => {
router.post('/admin/product/deleteimage', common.restrict, (req, res) => {
const db = req.app.db;

// get the productImage from the db
Expand Down
13 changes: 7 additions & 6 deletions routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const express = require('express');
const common = require('../lib/common');
const colors = require('colors');
const bcrypt = require('bcryptjs');
const url = require('url');
const router = express.Router();

router.get('/users', common.restrict, (req, res) => {
router.get('/admin/users', common.restrict, (req, res) => {
const db = req.app.db;
db.users.find({}).toArray((err, users) => {
if(err){
Expand All @@ -25,7 +26,7 @@ router.get('/users', common.restrict, (req, res) => {
});

// edit user
router.get('/user/edit/:id', common.restrict, (req, res) => {
router.get('/admin/user/edit/:id', common.restrict, (req, res) => {
const db = req.app.db;
db.users.findOne({_id: common.getId(req.params.id)}, (err, user) => {
if(err){
Expand Down Expand Up @@ -54,7 +55,7 @@ router.get('/user/edit/:id', common.restrict, (req, res) => {
});

// users new
router.get('/user/new', common.restrict, (req, res) => {
router.get('/admin/user/new', common.restrict, (req, res) => {
res.render('user_new', {
title: 'User - New',
admin: true,
Expand All @@ -67,7 +68,7 @@ router.get('/user/new', common.restrict, (req, res) => {
});

// delete user
router.get('/user/delete/:id', common.restrict, (req, res) => {
router.get('/admin/user/delete/:id', common.restrict, (req, res) => {
const db = req.app.db;
if(req.session.isAdmin === 'true'){
db.users.remove({_id: common.getId(req.params.id)}, {}, (err, numRemoved) => {
Expand All @@ -86,7 +87,7 @@ router.get('/user/delete/:id', common.restrict, (req, res) => {
});

// update a user
router.post('/user/update', common.restrict, (req, res) => {
router.post('/admin/user/update', common.restrict, (req, res) => {
const db = req.app.db;

let isAdmin = req.body.user_admin === 'on' ? 'true' : 'false';
Expand Down Expand Up @@ -133,7 +134,7 @@ router.post('/user/update', common.restrict, (req, res) => {
});

// insert a user
router.post('/user/insert', common.restrict, (req, res) => {
router.post('/admin/user/insert', common.restrict, (req, res) => {
const db = req.app.db;

// set the account to admin if using the setup form. Eg: First user account
Expand Down

0 comments on commit bf67621

Please sign in to comment.