Permalink
Browse files

corrected Shop forms

  • Loading branch information...
mekaala committed Feb 14, 2020
1 parent ee929cf commit 9a8e84fb2ce7993a7c0f7818d8178f13ddf1d2fb
Showing with 26 additions and 11 deletions.
  1. +1 −1 controllers/shop.js
  2. +12 −1 models/shop.js
  3. +1 −1 server.js
  4. +5 −3 views/shops/create.hbs
  5. +2 −2 views/shops/shop.hbs
  6. +5 −3 views/shops/shops.hbs
@@ -45,7 +45,7 @@ shopRouter.get('/:index', (req,res) => {
res.render('shops/shop', { shop: shopsApi.getShop(index), index } )
})

shopRouter.post('/', function(req,res){
shopRouter.post('/', (req,res) => {
shopsApi.addShop(req.body);
res.redirect('/shops')
})
@@ -2,7 +2,18 @@
* Place all functions, classes, and/or DB schemas here for a single
* model.
*/
global.shops = [];
global.shops = [
{
'name': 'Starbucks (c)',
'employees': 100000,
'currentlyOpen': true
},
{
'name': 'Dancing Goats Cafe',
'employees': 100,
'currentlyOpen': false
}
];

/*
* TODO: delete this it's just a sample
@@ -35,7 +35,7 @@ app.use(express.urlencoded())
* ...to parse the body of the HTTP requests from a JSON string
* replace the above line with this
*/
app.use(express.json())
// app.use(express.json())

/* Step 3.b
*
@@ -1,12 +1,14 @@
<form method="POST" action="/shops">
<form action="/shops" method="POST">

<!--
Template for creating input form for a string object key called stringMember
NOTE: for numeric input fields use `type="number"`
--->
<input type="text" value="{{<TODO: model.stringMember (e.g: account.name)}}" placeholder="name" name="<TODO: stringMember (e.g: name)>" />
Name: <input type="text" name="name" value="{{ shop.name }}"/>

<input type="checkbox" name="<TODO: model.booleanMember (e.g: account.isActive)" value="true" />
Employees: <input type="number" name="employee" value="{{ shop.employees }}"/>

Currently Open: <input type="checkbox" name="currentlyOpen" {{#if shop.currentlyOpen }} checked {{/if }}/>

<input type="submit" value="Create Shop" />
</form>
@@ -4,12 +4,12 @@
Template for creating input form for a string object key called stringMember
NOTE: for numeric input fields use `type="number"`
-->
<input type="text" value="{{<TODO: model.stringMember>}}" name="<TODO: stringMember (e.g: name)>" />
<input type="text" value="{{ shop.name }}" name="name" />

<!--
Template for creating input form for a boolean object member
-->
<input type="checkbox" name="<TODO: booleanMember (e.g: isActive)>" value="true" {{#if <TODO: model.booleanMember (e.g: account.isActive)}}checked{{/if}} />
<input type="checkbox" name="currentlyOpen" value="true" {{#if shop.currentlyOpen }}checked{{/if}} />

<input type="submit" value="Update Shop" />
</form>
@@ -1,5 +1,7 @@
<ul>
{{#each name}}
<a href="/shops/{{@index}}"><li>{{ name }}</li></a>
{{/each}}
{{#each shops}}
<li>
<a href="/shops/{{ @index }}"> {{ name }} </a>
</li>
{{/each}}
</ul>

0 comments on commit 9a8e84f

Please sign in to comment.