Some decisions regarding the lua env
it will be in the app environment because it serves the app, will think about it later
This commit is contained in:
@@ -1,4 +1,39 @@
|
||||
local cjson = require("cjson")
|
||||
-- This scripts needs to do 2 things:
|
||||
-- Update the expenses where the owner doesn't have shares or payments to have
|
||||
-- some of his
|
||||
-- Normalize the shares
|
||||
|
||||
local json = require("json")
|
||||
|
||||
local function printTable(t)
|
||||
for key, value in pairs(t) do
|
||||
if type(value) == "table" then
|
||||
printTable(value)
|
||||
else
|
||||
print(key, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function isOwnerInShares(exp)
|
||||
for _, share in pairs(exp.Shares) do
|
||||
if share.User.UserID == exp.Owner.UserID then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function isOwnerInPayments(exp)
|
||||
for _, paym in pairs(exp.Payments) do
|
||||
if paym.User.UserID == exp.Owner.UserID then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
local expenses, err = GetAllExpenses()
|
||||
@@ -8,7 +43,18 @@ end
|
||||
|
||||
for i = 1, #expenses do
|
||||
local eJson = expenses[i].expense
|
||||
local e = cjson.decode(eJson)
|
||||
local e = json.decode(eJson)
|
||||
|
||||
print(e)
|
||||
if not isOwnerInShares(e) then
|
||||
-- Insert a share in the owner user into shares as 0.0
|
||||
end
|
||||
|
||||
if not isOwnerInPayments(e) then
|
||||
-- Insert a share in the owner user into shares as 0.0
|
||||
end
|
||||
|
||||
normalizedExpense = NormalizeShare(eJson)
|
||||
if eJson == normalizedExpense then
|
||||
print "This one needs to be updated"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user