Permalink
Browse files

updated shops

  • Loading branch information...
iLimas committed Feb 14, 2020
0 parents commit 4c69977846736338032ac7181903c0ff99e5942f
Showing 703 changed files with 137,416 additions and 0 deletions.
@@ -0,0 +1 @@
node_modules
@@ -0,0 +1,73 @@
/* Step 1 import express
*
*/
const express = require('express')


/* Step 2
*
* Import the api files from the models
*
* TODO: change the file path to the models file you'll need to use.
* TODO: rename this from `shopsApi` to something more sensible (e.g:
* `shopsAPI`)
*
* NOTE: You may need to import more than one API to create the
* controller you need.
*
*/
const shopsApi = require('../models/shop.js')

/* Step 3
*
* Create a new router.
*
* the router will "contain" all the request handlers that you define in this file.
* TODO: rename this from shopRouter to something that makes sense. (e.g:
* `shopRouter`)
*/
const shopRouter = express.Router()


/* Step 4
*
*/
//localhost:3000/shops/ will display at this path because it is set in server.js
shopRouter.get('/', function(req,res) {
res.render('/shops/shops',{shops: shopsApi.getShops()});
})

shopRouter.get('/new', function(req, res) {
res.render('/shops/create',{shop: shopsApi.getShop()});
})

shopRouter.get('/:index', function(req,res){
res.render('/shops/shops',{shop: shopsApi.getShop(req.params.index)});
})

shopRouter.post('/', function(req,res){
shopsApi.addShop(req.body);
res.status(200).end();
res.redirect('/shops/');
})

shopRouter.put('/:index', function(req,res){
shopsApi.updateShop(req.params.index, req.body);
res.status(200).end();
})

shopRouter.delete('/:index', function(req,res){
shopsApi.deleteShop(req.params.index)
res.status(200).end();
})


/* Step 6
*
* Export the router from the file.
*
*/
module.exports = {
shopRouter
}

@@ -0,0 +1,51 @@
/*
* Place all functions, classes, and/or DB schemas here for a single
* model.
*/
global.shops = [];

/*
* TODO: delete this it's just a sample
*
*/
function createShop() {
return {
name: "",
employees: 0,
currentlyOpen: false
};
}

function getShops() {
return global.shops;
}

function getShop(i) {
return global.shops[i];
}

function addShop(newShop) {
global.shops.push(newShop);
}

function updateShop(i, shop) {
global.shops[i] = shop;
}

function deleteShop(i) {
global.shops.splice(i, 1);
}

/* Step 1
*
* TODO: export all functions from this file by adding their names as keys to this
* object
*/
module.exports = {
add: addShop,
create: createShop,
delete: deleteShop,
getShop: getShop,
getShops: getShops,
update: updateShop,
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 4c69977

Please sign in to comment.