Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final Presentation and Demo Lock #28

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
47634c1
first skeleton commit
okkalinardi Mar 20, 2020
87ba947
Added mongoose to dependencies
okkalinardi Mar 20, 2020
db51a9e
added unggah and aws-sdk to dependencies
okkalinardi Mar 20, 2020
465b67f
Added mongoose connect to skeleton
okkalinardi Mar 20, 2020
0329072
1. add user controller - crud
kirwanm Mar 20, 2020
9e208e5
add testing user - ongoing
kirwanm Mar 20, 2020
566c11f
Merge pull request #1 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 20, 2020
8e7903d
Resolved Routing Conflict
okkalinardi Mar 20, 2020
25ea231
Resolved Routing Conflict
okkalinardi Mar 20, 2020
df71dd1
Finished transaction route
okkalinardi Mar 20, 2020
bdf77fb
Merge pull request #3 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 20, 2020
0d6fe36
Add Event Api
onesinus Mar 20, 2020
9e90c79
Merge pull request #4 from Splitter-SplitTheBill/feat-api-events
onesinus Mar 20, 2020
12bab76
Memindahkan fungsi fungsi ke controller
onesinus Mar 20, 2020
03769cc
Merge pull request #5 from Splitter-SplitTheBill/feat-api-events
onesinus Mar 20, 2020
9d48814
1. add route and controller add & remove account
kirwanm Mar 22, 2020
76e6ddc
modified user.test.js
kirwanm Mar 22, 2020
c2af588
Merge pull request #6 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 22, 2020
9913497
Add photo, and change schema participant and account
onesinus Mar 22, 2020
c5ec49a
Merge pull request #7 from Splitter-SplitTheBill/enhc-api-events
onesinus Mar 22, 2020
4f4f2fb
modified user.test.js adding add and remove account and friend
kirwanm Mar 22, 2020
1a6daf0
modified controller response and testing
kirwanm Mar 22, 2020
36b5cfe
modified controller response and testing
kirwanm Mar 22, 2020
90650e3
remove coverage
kirwanm Mar 22, 2020
f61cc87
remove coverage
kirwanm Mar 22, 2020
206b44a
Remove coverage folder on development
okkalinardi Mar 22, 2020
9e9ad00
Merge pull request #9 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 22, 2020
84f3498
Menambahkan fungsi split text dari gambar
onesinus Mar 22, 2020
2be38c4
Merge pull request #10 from Splitter-SplitTheBill/feat-ocr-helper
onesinus Mar 22, 2020
8fdbfe0
Menambahkan middleware unggah
onesinus Mar 22, 2020
9432eba
Merge pull request #11 from Splitter-SplitTheBill/feat-ocr-helper
onesinus Mar 22, 2020
8f547a6
modified user controller
kirwanm Mar 22, 2020
1ea7d33
Merge pull request #12 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 22, 2020
841bf25
Membuat endpoint untuk ocr / mendapatkan array of object item dari bill
onesinus Mar 22, 2020
89ee1e0
Merge pull request #13 from Splitter-SplitTheBill/feat-ocr-helper
onesinus Mar 22, 2020
ecd7b52
modified user model and testing
kirwanm Mar 23, 2020
b2bfab7
Merge pull request #14 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 23, 2020
2b3bc82
Resolved eventController conflict
okkalinardi Mar 22, 2020
3d83176
Finished integrating with event route
okkalinardi Mar 23, 2020
8c4549a
Merge pull request #15 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 23, 2020
a946d2e
Update helper untuk referensi lebih banyak struk
onesinus Mar 24, 2020
5450621
Merge pull request #16 from Splitter-SplitTheBill/enhc-ocr-bill-refer…
onesinus Mar 24, 2020
d3c4482
Update file google vision json
onesinus Mar 24, 2020
d4b4f5d
Merge pull request #17 from Splitter-SplitTheBill/enhc-ocr-bill-refer…
onesinus Mar 24, 2020
c0030f9
modified user controller and testing
kirwanm Mar 24, 2020
fbbdcba
Merge pull request #18 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 24, 2020
f666b68
Fixed response of transactions and events route
okkalinardi Mar 24, 2020
572b2ff
Merge pull request #19 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 24, 2020
892f97c
Fixed populate for events
okkalinardi Mar 24, 2020
a559ba0
Merge pull request #20 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 24, 2020
feced24
Fixed Populate on transaction route
okkalinardi Mar 24, 2020
7dae9b7
Merge pull request #21 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 24, 2020
a86c840
modified user controller: response object user for add & remove accou…
kirwanm Mar 24, 2020
40c6b11
Merge pull request #22 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 24, 2020
c8ee633
Added 2 way confirmation feature
okkalinardi Mar 25, 2020
9fd983d
Merge pull request #23 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 25, 2020
82785c4
Change upload bill to gcs
onesinus Mar 25, 2020
6ea5b96
Merge branch 'development' into enhc-scan-bill
onesinus Mar 25, 2020
079da68
Merge pull request #24 from Splitter-SplitTheBill/enhc-scan-bill
onesinus Mar 25, 2020
6f2b3a3
97% testing result
onesinus Mar 25, 2020
cbb71bc
Merge pull request #25 from Splitter-SplitTheBill/testing-enhc-events
onesinus Mar 25, 2020
1db5fb2
Added authentication to addEvent middleware
okkalinardi Mar 26, 2020
af841ab
Merge pull request #26 from Splitter-SplitTheBill/feat-transactions-api
okkalinardi Mar 26, 2020
7bc0300
modified testing event and transaction
kirwanm Mar 25, 2020
64982ef
modified testing
kirwanm Mar 26, 2020
6dea4ab
Merge pull request #27 from Splitter-SplitTheBill/feat-api-users
kirwanm Mar 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.env
config
coverage
secret_keys
31 changes: 31 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if(process.env.NODE_ENV == 'development' || process.env.NODE_ENV == 'test') {
require('dotenv').config()
}

const express = require('express')
const app = express()
const router = require('./routes')
const cors = require('cors')
const errorHandler = require('./middlewares/errorHandler')
const mongoose = require('mongoose')
const mongodb = process.env.MONGO_ATLAS || 'mongodb://localhost:27017/'
let dbName

if (process.env.NODE_ENV == 'development' || process.env.NODE_ENV == 'test') {
dbName = 'splitter-' + process.env.NODE_ENV
}

mongoose.connect(mongodb+dbName, {useNewUrlParser:true, useUnifiedTopology: true})
.then(success => {
console.log('connected to MongoDb on ' + mongodb+dbName)
})


app
.use(cors())
.use(express.json())
.use(express.urlencoded({extended: true}))
.use('/', router)
.use(errorHandler)

module.exports = app
6 changes: 6 additions & 0 deletions bin/www.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const app = require('../app')
const port = process.env.PORT || 3000

app.listen(port, () => {
console.log('server is running on port ' + port)
})
124 changes: 124 additions & 0 deletions controllers/EventController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
const Event = require('../models/event');
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
const { getItems } = require('../helpers/extractText');
const transactionModel = require('../models/transaction')

class EventController {
static listEvents(req, res, next) {
let createdUserId = req.userLoggedIn ? req.userLoggedIn._id : "123456789012";
Event.find({createdUserId})
.populate('createdUserId', 'name email username image_url')
.populate('participants.transactionId')
.populate('participants.participantId', 'name email username image_url')
.then(events => {
res.status(200).json({
events
});
})
.catch(next);
}

static findEventById(req, res, next) {
Event.findOne({_id: ObjectId(req.params.id)})
.populate('createdUserId', 'name email username image_url')
.populate('participants.transactionId')
.populate('participants.participantId', 'name email username image_url')
.then(event => {
res.status(200).json({
event
});
})
.catch(next);
}

static addEvent(req, res, next) {
let newEvent
let returnTransactions
const { name, photo, accounts, createdUserId } = req.body;
const event = new Event({ name, photo, status: false, participants: [], accounts, createdUserId });

event.save()
.then((createdEvent) => {
newEvent = createdEvent
let transactions = []
req.body.participants.forEach(participant => {
let totalTransaction = 0
participant.items.forEach(item => {
totalTransaction += item.price
})
transactions.push(transactionModel.create({
userId: participant.userId,
items: participant.items,
total: totalTransaction,
status: 'unpaid',
paymentSelection: newEvent.accounts,
eventId: newEvent._id
}))
})
return Promise.all(transactions)
})
.then(createdTransactions => {
returnTransactions = createdTransactions
let fixedParticipants = []
createdTransactions.forEach(transaction => {
fixedParticipants.push({participantId: transaction.userId, transactionId: transaction._id})
})
return Event.updateOne({
_id: newEvent._id
}, {
participants: fixedParticipants
})
})
.then(updatedData => {
return Event.findOne({
_id: newEvent._id
})
.populate('participants.transactionId')
.populate('participants.participantId', 'name email username image_url')
})
.then(finalEventData => {
res.status(201).json({
event: finalEventData,
transactions: returnTransactions
})
})
.catch(next)
}

static updateEvent(req, res, next) {
const { name, photo, status, participants, accounts, createdUserId } = req.body;

Event.updateOne({_id: ObjectId(req.params.id)}, { name, photo, status, participants, accounts, createdUserId })
.then(resUpdate => {
res.status(200).json({
resUpdate
});
})
.catch(next);
}

static deleteEvent(req, res, next) {
Event.deleteOne({_id: ObjectId(req.params.id)})
.then(resDelete => {
res.status(200).json({resDelete});
})
.catch(next);
}

static imgToArrTransactions(req, res, next) {
// console.log(req.body.photo)
getItems(req.body.photo)
// getItems('https://storage.cloud.google.com/forocrtest/1585043446579-test.jpg')
.then(transactions => {
// console.log(transactions)
res.status(200).json({
transactions,
photo: req.body.photo
});
})
.catch(next)
}
}

module.exports = EventController;
Loading