Skip to content

Commit

Permalink
Merge branch 'master' into process_emails_ses
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresMorelos committed Jul 5, 2021
2 parents 20c7f0a + 357e749 commit 6639aef
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 36 deletions.
32 changes: 16 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"name": "Serverless",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"debug"
],
"port": 9229
}
]
}
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"name": "Serverless",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"debug"
],
"port": 9229
}
]
}
6 changes: 6 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion client/src/components/HomeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class HomeComponent extends React.Component {
<div className="categories-container">
{
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'
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ProfileContainer/ProfileContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="profile-container">
Expand Down Expand Up @@ -115,7 +115,7 @@ class ProfileContainer extends React.Component {
</p>
<br />
{categoriesWithBudgets && categoriesWithBudgets.map((category) => (
<Label className="budget-label">{category.label} - {formatCash(category.budget)}</Label>
<Label color="default" className="budget-label">{category.label} - {formatCash(category.budget.value)}</Label>
))}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
20 changes: 10 additions & 10 deletions shared/database/repos/payment.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down Expand Up @@ -71,15 +71,15 @@ 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,
type: "EXPENSE",
},
{ amount: 1, description: 1, createdAt: 1, category: 1, isAccepted: 1 }
).sort({ createdAt: -1 });
return result;

};

//get all prepayments without category
Expand Down Expand Up @@ -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 }
Expand Down
11 changes: 5 additions & 6 deletions shared/database/repos/user.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }, {
Expand All @@ -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
Expand All @@ -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
}

0 comments on commit 6639aef

Please sign in to comment.