Skip to content

Commit

Permalink
list cashback
Browse files Browse the repository at this point in the history
  • Loading branch information
keppelen committed Sep 26, 2017
1 parent f37a07a commit 812f7df
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
24 changes: 24 additions & 0 deletions api/staff/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const MongoClient = require('mongodb').MongoClient
const ObjectId = require('mongodb').ObjectId
const assert = require('assert')
const _ = require('lodash')
const url = process.env.MONGO_DB;

const findAll = (db, callback) => {
const collection = db.collection('staff')
collection.find({}).toArray((err, result) => {
db.close()
callback(err, result)
})
}

module.exports = (req, res) => {
MongoClient.connect(url, function(err, db) {
findAll(db, (err, result) => {
if (err) {
return res.send({ status: false, message: result })
}
return res.send({ status: true, result: _.groupBy(result, 'staff') })
})
})
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"aws-sdk": "^2.94.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"lodash": "^4.17.4",
"mongodb": "^2.2.30",
"next": "^3.0.1-beta.8",
"react": "^15.6.1",
Expand Down
3 changes: 0 additions & 3 deletions pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export default class Dashboard extends React.Component {
<div className="col-6">
<Chart name="Despesas" data={this.state.expensesForecast} />
</div>
<div className="col-6">
<Chart name="Reembolsos" data={this.state.cashbacks} />
</div>
</div>

</div>
Expand Down
31 changes: 30 additions & 1 deletion pages/staff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import StaffSplit from '../components/staff-split'
import 'whatwg-fetch'

export default class Dashboard extends React.Component {
state = { message: '', staff: '', pricing: 0 }
state = { message: '', staff: '', pricing: 0, listStaffs: null }
componentDidMount() {
document.getElementById("file-input").onchange = () => {
const files = document.getElementById('file-input').files
Expand All @@ -16,6 +16,15 @@ export default class Dashboard extends React.Component {
}
this.getSignedRequest(file)
}

fetch('/api/staff').then(response => {
return response.json()
}).then(data => {
const { result, status } = data
if (status) {
this.setState({ listStaffs: result })
}
})
}

handleChange = (e) => {
Expand Down Expand Up @@ -113,6 +122,26 @@ export default class Dashboard extends React.Component {
<h4>{this.state.message}</h4>
</div>
</div>
{
this.state.listStaffs &&
<div>
{Object.keys(this.state.listStaffs).map(name => {
return (
<div style={{ marginBottom: 30, borderBottom: '2px solid #ccc' }}>
<h4>{name} - {this.state.listStaffs[name].map(i => parseInt(i.pricing, 10)).reduce((a, b) => a + b, 0).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })}</h4>
{this.state.listStaffs[name].map(i => {
return (
<div style={{ display: 'inline-block', margin: '0 5px 10px 0' }}>
<p>{i.pricing.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })}</p>
<a href={i.url} target='_blank'><img src={i.url} width='270' /></a>
</div>
)
})}
</div>
)
})}
</div>
}
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ app.prepare()
server.get('/api/forecast/revenue', require('./api/forecast/revenue'))

server.post('/api/staff', require('./api/staff'))
server.get('/api/staff', require('./api/staff/get'))
server.get('/api/sign-s3', require('./api/s3'));

server.get('/api/dashboard', require('./api/dashboard'))
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ locate-path@^2.0.0:
p-locate "^2.0.0"
path-exists "^3.0.0"

lodash@^4.0.0, lodash@^4.14.0, lodash@^4.16.4, lodash@^4.2.0, lodash@^4.5.1, lodash@^4.6.1, lodash@~4.17.4:
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.16.4, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.5.1, lodash@^4.6.1, lodash@~4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down

0 comments on commit 812f7df

Please sign in to comment.