implement soft delete for money moves

This commit is contained in:
Bilal
2020-10-09 16:12:44 +03:00
parent f2af0639f3
commit 722fc71f17
5 changed files with 17 additions and 3 deletions

View File

@@ -22,6 +22,14 @@ class MoneyMovesController < ApplicationController
error_response(:bad_request) error_response(:bad_request)
end end
def destroy
money_move = MoneyMove.find(params[:id])
money_move.update!(deleted_at: DateTime.now)
index
rescue StandardError
error_response :bad_request
end
def money_move_params def money_move_params
params.require(:money_move).permit( params.require(:money_move).permit(
:description, :description,

View File

@@ -7,7 +7,7 @@ class Homie < ApplicationRecord
def self.info(importance, gang) def self.info(importance, gang)
# TODO: This can be improved # TODO: This can be improved
cash_totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount) cash_totals = Homie.all.joins(:money_moves).where(money_moves: { deleted_at: nil}).group(:id).order(:id).sum(:amount)
work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount) work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount)
Homie.where(['importance > ? and gang_id = ?', importance, gang]).map do |homie| Homie.where(['importance > ? and gang_id = ?', importance, gang]).map do |homie|

View File

@@ -8,10 +8,10 @@ Rails.application.routes.draw do
end end
member do member do
post 'settle' post 'settle'
resources :money_moves
end end
end end
end end
resources :money_moves
resources :work resources :work
resources :chips, only: %i[index create destroy] resources :chips, only: %i[index create destroy]
resources :chip_values, only: %i[create update destroy] resources :chip_values, only: %i[create update destroy]

View File

@@ -0,0 +1,5 @@
class AddDeletedAtToMoneyMoves < ActiveRecord::Migration[5.2]
def change
add_column :money_moves, :deleted_at, :timestamp
end
end

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_10_07_213411) do ActiveRecord::Schema.define(version: 2020_10_09_114126) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -63,6 +63,7 @@ ActiveRecord::Schema.define(version: 2020_10_07_213411) do
t.integer "homie_id", null: false t.integer "homie_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.datetime "deleted_at"
end end
create_table "work", force: :cascade do |t| create_table "work", force: :cascade do |t|