-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from frontinbh/add-staff
Add staff
- Loading branch information
Showing
17 changed files
with
407 additions
and
37 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
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
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
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 @@ | ||
const aws = require('aws-sdk') | ||
aws.config.region = 'us-east-1' | ||
|
||
module.exports = (req, res) => { | ||
const s3 = new aws.S3(); | ||
const fileName = `${new Date().getTime()}-${req.query['file-name']}`; | ||
const fileType = req.query['file-type']; | ||
const s3Params = { | ||
Bucket: process.env.S3_BUCKET, | ||
Key: fileName, | ||
Expires: 60, | ||
ContentType: fileType, | ||
ACL: 'public-read' | ||
}; | ||
|
||
s3.getSignedUrl('putObject', s3Params, (err, data) => { | ||
if(err){ | ||
console.log(err); | ||
return res.end(); | ||
} | ||
const returnData = { | ||
signedRequest: data, | ||
url: `https://${process.env.S3_BUCKET}.s3.amazonaws.com/${fileName}` | ||
}; | ||
res.write(JSON.stringify(returnData)); | ||
res.end(); | ||
}); | ||
} |
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,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') }) | ||
}) | ||
}) | ||
} |
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,27 @@ | ||
const MongoClient = require('mongodb').MongoClient | ||
const ObjectId = require('mongodb').ObjectId | ||
const assert = require('assert') | ||
const url = process.env.MONGO_DB; | ||
|
||
const insert = (db, body, callback) => { | ||
const collection = db.collection('staff') | ||
collection.insertOne({ staff: body.staff, pricing: parseFloat(body.pricing), url: body.url }, (err, result) => { | ||
db.close() | ||
callback(err, result) | ||
}) | ||
} | ||
|
||
module.exports = (req, res) => { | ||
MongoClient.connect(url, function(err, db) { | ||
if (req.body.staff) { | ||
insert(db, req.body, (err, result) => { | ||
if (err) { | ||
return res.send({ status: false, message: result }) | ||
} | ||
return res.send({ status: true, message: result }) | ||
}) | ||
} else { | ||
return res.send({ status: false, message: result }) | ||
} | ||
}) | ||
} |
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
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
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,61 @@ | ||
import React from 'react' | ||
|
||
export default class extends React.Component { | ||
state = { | ||
results: [ | ||
{ | ||
name: 'Receitas', | ||
tr: 0, | ||
tp: 0 | ||
}, | ||
{ | ||
name: 'Despesas', | ||
tr: 0, | ||
tp: 0 | ||
}, | ||
{ | ||
name: 'Reembolsos', | ||
tr: 0, | ||
tp: 0 | ||
} | ||
], | ||
countStaff: 4 | ||
} | ||
|
||
componentDidMount() { | ||
fetch('/api/dashboard').then(response => { | ||
return response.json() | ||
}).then(data => { | ||
const { results } = data | ||
this.setState({ results }) | ||
}) | ||
} | ||
|
||
handleChange = (e) => { | ||
const countStaff = e.target.value | ||
this.setState({ countStaff }) | ||
} | ||
|
||
render() { | ||
const revenues = this.state.results.filter(r => r.name === 'Receitas') | ||
const expenses = this.state.results.filter(r => r.name === 'Despesas') | ||
const cashback = this.state.results.filter(r => r.name === 'Reembolsos') | ||
const totalSplitReal = (revenues[0].tr - cashback[0].tr) - expenses[0].tr | ||
const totalSplit = (revenues[0].tp - cashback[0].tp) - expenses[0].tp | ||
return ( | ||
<div> | ||
<input type="number" value={this.state.countStaff} onChange={this.handleChange} /> | ||
<p> | ||
Real <br /> | ||
{(totalSplitReal / this.state.countStaff) | ||
.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })} | ||
</p> | ||
<p> | ||
Previsto <br /> | ||
{(totalSplit / this.state.countStaff) | ||
.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' })} | ||
</p> | ||
</div> | ||
) | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.