From e608cfd7730741189a4f370e55e9fb482a43c0bc Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 6 Oct 2020 00:16:33 +0300 Subject: [PATCH 1/4] show work amount for homie on Dashboard --- client/src/cash/Cash.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/src/cash/Cash.js b/client/src/cash/Cash.js index c3e2aac..86fbf8f 100644 --- a/client/src/cash/Cash.js +++ b/client/src/cash/Cash.js @@ -4,8 +4,8 @@ import './Cash.css'; import axios from 'axios'; import { MAKE_MONEY_MOVE } from '../RouteNames'; import { withRouter } from 'react-router-dom'; -import { formatMoney } from '../common/formatting'; -import InputModal from "../common/InputModal"; +import { formatMoney, formatTime } from '../common/formatting'; +import YesNoModal from "../common/YesNoModal"; import { errorToast } from "../common/errorHelpers"; import M from 'materialize-css'; @@ -16,7 +16,7 @@ const Cash = (props) => { useEffect( () => { const getCashForHomies = async () => { try { - const cash = await axios.get(`/api/homies/cash`); + const cash = await axios.get(`/api/homies/info`); setHomiesCash(cash.data); } catch (e) { console.log("Error fetching", e); @@ -45,6 +45,9 @@ const Cash = (props) => { { homieLine.homie.name } + + { formatTime(homieLine.work) } + { formatMoney(homieLine.amount) } @@ -71,6 +74,9 @@ const Cash = (props) => { Homie + + Work + Cash From 3d63a796bdc66e3a723c3245e7ba170caf954ae9 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 6 Oct 2020 00:17:21 +0300 Subject: [PATCH 2/4] send total work hrs for homie --- app/controllers/homies_controller.rb | 8 ++++---- app/models/homie.rb | 10 ++++++---- config/routes.rb | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/homies_controller.rb b/app/controllers/homies_controller.rb index 86ecc92..5380f48 100644 --- a/app/controllers/homies_controller.rb +++ b/app/controllers/homies_controller.rb @@ -21,9 +21,9 @@ class HomiesController < ApplicationController end end - def cash - importance = params[:importance].present? ? params[:importance].to_i : -1 - json_response(Homie.cash(importance)) + def info + importance = params[:importance].to_i + json_response(Homie.info(importance)) end def settle @@ -32,7 +32,7 @@ class HomiesController < ApplicationController homie = Homie.find(homie_id) if homie.settle(amount) - cash + info else error_response :bad_request end diff --git a/app/models/homie.rb b/app/models/homie.rb index 1c1efa4..be5ef9d 100644 --- a/app/models/homie.rb +++ b/app/models/homie.rb @@ -3,12 +3,14 @@ class Homie < ApplicationRecord has_many :work belongs_to :chip - def self.cash(importance) - totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount) + def self.info(importance) + cash_totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount) + work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount) Homie.where(["importance > ?", importance]).map do |homie| - total = totals.fetch(homie.id, 0) - { homie: homie, amount: total } + cash_total = cash_totals.fetch(homie.id, 0) + work_total = work_totals.fetch(homie.id, 0) + { homie: homie, amount: cash_total, work: work_total } end end diff --git a/config/routes.rb b/config/routes.rb index 7094a56..dbd5365 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Rails.application.routes.draw do resources :chip_values, only: %i[create update destroy] resources :homies, param: :homie_id do collection do - get 'cash' + get 'info' end member do post 'settle' From 2cff843e881e64875b369557a26c81b33ab800d9 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 6 Oct 2020 09:55:59 +0300 Subject: [PATCH 3/4] rebase fix --- client/src/cash/Cash.js | 2 +- client/src/cash/MakeMoneyMove.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cash/Cash.js b/client/src/cash/Cash.js index 86fbf8f..a59ccd3 100644 --- a/client/src/cash/Cash.js +++ b/client/src/cash/Cash.js @@ -5,7 +5,7 @@ import axios from 'axios'; import { MAKE_MONEY_MOVE } from '../RouteNames'; import { withRouter } from 'react-router-dom'; import { formatMoney, formatTime } from '../common/formatting'; -import YesNoModal from "../common/YesNoModal"; +import InputModal from "../common/InputModal"; import { errorToast } from "../common/errorHelpers"; import M from 'materialize-css'; diff --git a/client/src/cash/MakeMoneyMove.js b/client/src/cash/MakeMoneyMove.js index b1b5ca0..8b8ccd5 100644 --- a/client/src/cash/MakeMoneyMove.js +++ b/client/src/cash/MakeMoneyMove.js @@ -16,7 +16,7 @@ const MakeMoneyMove = (props) => { useEffect(() => { const getCashForHomies = async () => { try { - const cash = await axios.get(`/api/homies/cash`); + const cash = await axios.get(`/api/homies/info`); setHomiesCash(cash.data); } catch (e) { console.log("Error fetching", e); From 30fac5237186787821c17822e6cf06bbe2202c56 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 6 Oct 2020 09:58:09 +0300 Subject: [PATCH 4/4] fix rebase --- app/controllers/homies_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homies_controller.rb b/app/controllers/homies_controller.rb index 5380f48..f93d5e9 100644 --- a/app/controllers/homies_controller.rb +++ b/app/controllers/homies_controller.rb @@ -22,7 +22,7 @@ class HomiesController < ApplicationController end def info - importance = params[:importance].to_i + importance = params[:importance].present? ? params[:importance].to_i : -1 json_response(Homie.info(importance)) end