diff --git a/.vscode/launch.json b/.vscode/launch.json index 1020bed..9f1c4dd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,17 @@ { - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "cwd": "${workspaceFolder}", - "name": "Serverless", - "runtimeExecutable": "npm", - "runtimeArgs": [ - "run", - "debug" - ], - "port": 9229 - } - ] - } \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "cwd": "${workspaceFolder}", + "name": "Serverless", + "runtimeExecutable": "npm", + "runtimeArgs": [ + "run", + "debug" + ], + "port": 9229 + } + ] +} diff --git a/client/src/App.css b/client/src/App.css index 0a349fe..8a3eb2f 100644 --- a/client/src/App.css +++ b/client/src/App.css @@ -408,4 +408,10 @@ background: linear-gradient(to right, #414345, #232526) !important; /* W3C, IE 1 .add-new-budget{ cursor: pointer; display: inline-block; +} + +.budget-label{ + display: block; + margin-right: 10px; + margin-top: 5px; } \ No newline at end of file diff --git a/client/src/components/HomeContainer.js b/client/src/components/HomeContainer.js index d0ff657..5daa7e5 100644 --- a/client/src/components/HomeContainer.js +++ b/client/src/components/HomeContainer.js @@ -190,7 +190,7 @@ class HomeComponent extends React.Component {
{ categories && categories.map((item, index) => { - const [category] = user && user.categories && user.categories.filter(category => category.label === item.name) + const [category] = user && user.categories && user.categories.filter(category => category.value === item.name) const progressValue = category && category.budget && category.budget.progress ? category.budget.progress : 0 let color = 'success' diff --git a/client/src/components/ProfileContainer/ProfileContainer.jsx b/client/src/components/ProfileContainer/ProfileContainer.jsx index 270bfd3..3e991ed 100644 --- a/client/src/components/ProfileContainer/ProfileContainer.jsx +++ b/client/src/components/ProfileContainer/ProfileContainer.jsx @@ -71,7 +71,7 @@ class ProfileContainer extends React.Component { const { user = {}, banks } = this.props const { categories = [] } = user const categoriesWithBudgets = categories.filter(cat => { - return cat.budget && cat.budget > 0 + return cat.budget && cat.budget.value > 0 }) return (
@@ -115,7 +115,7 @@ class ProfileContainer extends React.Component {


{categoriesWithBudgets && categoriesWithBudgets.map((category) => ( - + ))}
diff --git a/serverless.yml b/serverless.yml index 3be69a7..033d008 100644 --- a/serverless.yml +++ b/serverless.yml @@ -274,7 +274,7 @@ functions: arn: ${file(./config/${opt:stage}.json):USER_POOL_ARN} claims: - sub - + AddBudgetCategory: handler: API/Functions/Users.addBudgetCategory name: UserRepo-Categories-budget-POST-${opt:stage} diff --git a/shared/database/repos/payment.repo.js b/shared/database/repos/payment.repo.js index 41aad50..ebbcab8 100644 --- a/shared/database/repos/payment.repo.js +++ b/shared/database/repos/payment.repo.js @@ -6,12 +6,12 @@ module.exports.create = async (PaymentBody) => { try { await connect(); const { categories, sub } = await getUser({ _id: PaymentBody.user }) - const results = categories.filter(category => category.label = PaymentBody.category) + const results = categories.filter(category => category.value === PaymentBody.category) let category = results[0] const current = category.budget.current + PaymentBody.amount - const result = await updateBudget( + await updateBudget( { sub, 'categories.value': category.value @@ -33,15 +33,15 @@ module.exports.createMultiple = async (PaymentBodies = []) => { await connect(); for (const PaymentBody of PaymentBodies) { const { categories, sub } = await getUser({ _id: PaymentBody.user }) - const results = categories.filter(category => category.label = PaymentBody.category) + const results = categories.filter(category => category.value === PaymentBody.category) let category = results[0] const current = category.budget.current + PaymentBody.amount - const result = await updateBudget( + await updateBudget( { sub, - 'categories.value': category.value + 'categories': { $elemMatch: { value: category.value } } }, { 'categories.$.budget': { current } @@ -71,7 +71,7 @@ module.exports.create = async (PaymentBody) => { module.exports.getAllByDate = async ({ userId, date }) => { if (!userId) return []; await connect() - const result = await Payments.find( + return await Payments.find( { createdAt: { $gte: new Date(date) }, user: userId, @@ -79,7 +79,7 @@ module.exports.getAllByDate = async ({ userId, date }) => { }, { amount: 1, description: 1, createdAt: 1, category: 1, isAccepted: 1 } ).sort({ createdAt: -1 }); - return result; + }; //get all prepayments without category @@ -109,15 +109,15 @@ module.exports.updatePayment = async (Payment) => { const { categories, sub } = await getUser({ _id: Payment.user }) - const results = categories.filter(category => category.label === Payment.category) + const results = categories.filter(category => category.value === Payment.category) let category = results[0] const current = category.budget.current + amount - + await updateBudget( { sub, - 'categories.value': category.value + 'categories': { $elemMatch: { value: category.value } } }, { 'categories.$.budget': { current } diff --git a/shared/database/repos/user.repo.js b/shared/database/repos/user.repo.js index cf9a4ae..073321d 100644 --- a/shared/database/repos/user.repo.js +++ b/shared/database/repos/user.repo.js @@ -45,7 +45,7 @@ module.exports.updateUser = async (filter, newDocument, single) => { }; module.exports.createCategory = async (userCriteria, category) => { - if (!category.value || !category.label || !Object.keys(userCriteria).length) return null; + if (!category.value || !category.value || !Object.keys(userCriteria).length) return null; await connect() const result = await userModel.updateOne({ ...userCriteria }, { @@ -61,9 +61,9 @@ module.exports.updateCategory = async (searchCriteria, update) => { const [{ categories }] = await userModel.find(searchCriteria, { categories: 1 }); - const [category] = categories.filter(category => category.label === searchCriteria['categories.value']) + const [category] = categories.filter(category => category.value === searchCriteria['categories.value']) - if (category.budget.value !== update.value) { + if (category && category.budget && category.budget.value !== update.value) { const newValue = update['categories.$.budget']['value']; update['categories.$.budget']['progress'] = (category.budget.current / newValue) * 100 update['categories.$.budget']['current'] = category.budget.current @@ -79,15 +79,14 @@ module.exports.updateBudget = async (searchCriteria, update) => { const [{ categories }] = await userModel.find(searchCriteria, { categories: 1 }); - const [category] = categories.filter(category => category.label === searchCriteria['categories.value']) + const [category] = categories.filter(category => category.value === searchCriteria.categories.$elemMatch.value) - if (category.budget.current !== update['categories.$.budget'].current) { + if (category && category.budget.current !== update['categories.$.budget'].current) { update['categories.$.budget']['progress'] = (update['categories.$.budget'].current / category.budget.value) * 100 update['categories.$.budget']['value'] = category.budget.value } const result = await userModel.updateOne({ ...searchCriteria }, update) - return result.nModified > 0 } \ No newline at end of file