-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1a1f93
commit 6635ab5
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
home: last 50 sales [date, customers.fname, customer.lname, passport, price] | ||
search: { | ||
vendor: fname or lnames | ||
customer: passsport | ||
} | ||
|
||
item de result: click -> detail : customer, vendor, etc. | ||
|
||
vendors: | ||
ABM: | ||
click vendor -> All sales | ||
stats: total money | ||
total sales |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const http = require('http'); | ||
const express = require('express'); | ||
const mongojs = require('mongojs'); | ||
const exphbs = require('express-handlebars'); | ||
const db = mongojs('mongodb://localhost:27017/sales', ['vendors', 'customers', 'sales']); | ||
const app = express(); | ||
|
||
app.engine('.hbs', exphbs({defaultLayout: 'main', extname: '.hbs'})); | ||
app.set('view engine', '.hbs'); | ||
|
||
const server = http.createServer(app); | ||
app.use( express.static('./public') ); | ||
|
||
|
||
app.get('/', (req, res)=>{ | ||
const qtype = req.query.qtype || null; | ||
const query = {}; | ||
if(qtype){ | ||
switch(qtype){ | ||
case 'vendor': | ||
query['$or'] = [{'vendor.fname' : req.query.param}, {'vendor.lname' : req.query.param}]; | ||
break | ||
case 'passport': | ||
query['customer.passport'] = req.query.param; | ||
break; | ||
} | ||
} | ||
db.sales.find(query, {}).sort({_id: 1}).limit(50, (err, sales)=>{ | ||
res.render('home', {sales}); | ||
}); | ||
|
||
}); | ||
|
||
|
||
app.get('/vendors', (req, res)=>{ | ||
const query = {}; | ||
if(req.query.param){ | ||
query['$or'] = [{'fname' : req.query.param}, {'lname' : req.query.param}]; | ||
} | ||
|
||
db.vendors.find(query, {}, (err, vendors)=>{ | ||
res.render('vendors', {vendors}); | ||
}); | ||
|
||
}); | ||
|
||
server.listen(5000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "sales", | ||
"version": "1.0.0", | ||
"description": "sales abm and stats", | ||
"main": "app.js ", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"keywords": [ | ||
"expressjs", | ||
"mongodb", | ||
"mongojs", | ||
"sales", | ||
"stats" | ||
], | ||
"author": "Cesar Casas <cesarcasas@bsdsolutions.com.ar> (https://ar.linkedin.com/in/cesarcasas)", | ||
"license": "ISC", | ||
"dependencies": { | ||
"body-parser": "^1.17.1", | ||
"compress": "^0.99.0", | ||
"express": "^4.15.2", | ||
"express-handlebars": "^3.0.0", | ||
"helmet": "^3.6.0", | ||
"mongojs": "^2.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
<form method="get" action="/"> | ||
<input type="text" name="param" placeholder="Query? " /> | ||
<select name="qtype"> | ||
<option value="vendor">Vendor</option> | ||
<option value="passport">Passport</option> | ||
</select> | ||
<input type="submit" value="Search" /> | ||
</form> | ||
<table> | ||
|
||
<tr> | ||
<th>Date</th> | ||
<th>Fname</th> | ||
<th>Lname</th> | ||
<th>Passport</th> | ||
<th>Price</th> | ||
</tr> | ||
{{#each sales}} | ||
<tr> | ||
<td>{{this.date}}</td> | ||
<th>{{this.customer.fname}}</th> | ||
<th>{{this.customer.lname}}</th> | ||
<th>{{this.customer.passport}}</th> | ||
<th>{{this.price}}</th> | ||
</tr> | ||
{{/each}} | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
|
||
<head> | ||
|
||
</head> | ||
<body> | ||
{{{body}}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<form method="get" action="/vendors"> | ||
<input type="text" name="param" placeholder="Query? " /> | ||
<input type="submit" value="Search" /> | ||
</form> | ||
|
||
<table> | ||
<tr> | ||
<th>Fname</th> | ||
<th>Lname</th> | ||
<th>Age</th> | ||
</tr> | ||
{{#each vendors}} | ||
<tr> | ||
<th>{{this.fname}}</th> | ||
<th>{{this.lname}}</th> | ||
<th>{{this.age}}</th> | ||
</tr> | ||
{{/each}} | ||
</table> |