O227CEAV7BTKSE3SSC7XHC5IWEBXZL2AOOKJMBMOOFNTLINBLQMAC
QADKFHAR3KWQCNYU25Z7PJUGMD5WL26IU3DOAHBTRN2A7NKPUPKAC
NEDDHXUK3GNFMOFO3KLU7NRIHCTYNWBT3D6HTKZAOXFDE6HMDZ6AC
IZEVQF627FA7VV25KJAWYWGGC35LZUUBBQRPN5ZAINTQLPEDRTEAC
Y3LIJ5USPMYBG7HKCIQBE7MWVGLQJPJSQD3KPZCTKXP22GOB535QC
73NDXDEZRMK672GHSTC3CI6YHXFZ2GGJI5IKQGHKFDZKTNSQXLLQC
3QVT6MA6I2CILQH3LUZABS4YQ7MN6CNRYTDRVS376OOHTPLYTFJAC
O5FVTOM6YFBLEPF3S576K6IMT6ZZ5VQCSB3YVXNS4CKBITKCRZ7AC
DFOBMSAODB3NKW37B272ZXA2ML5HMIH3N3C4GT2DPEQS7ZFK4SNAC
64C6AWH66FDKU6UE6Z6JPX2J2GBM2JOPTH2GL6LHKAIUBGNGDZ5AC
QMRKFEPGFBCEWAIXPEIG5ILKAJ2JH5L3TOITHR4HNJXK5FN3KXBQC
HALRDT2F22DAQ54M334YSKD2XJCAXDXEZPDKGMOWKH7XELBAS6MAC
Z3MK2PJ5U222DXRS22WCDHVPZ7HVAR3HOCUNXIGX6VMEPBQDF6PQC
NLZ3JXLOOIL37O3RRQWXHNPNSNEOOLPD6MCB754BEBECQB3KGR2AC
W35DDBFYF6Z4ZPCFEO5RPAONZLYCSNTXUSTS6FIUUVZHCI6Q7GHAC
O722AOKEWXWJPRHGJREU6QPW7HEFPPRETZIAADZ2RMAXHARCNEKAC
7VGYLTMURLVSVUYFW7TCRZTDQ6RE2EPSPPA43XKHDOBFWYVVSJHQC
GCVQD44VRPQVKPZEPIC4AOIXLJIG2ZMV3QI2Y7KALUT6NVUBSGSAC
storeEvent (CreateBillable _) = error "Not implemented"
storeEvent (CreateSubscription _ _) = error "Not implemented"
storeEvent (CreatePaymentRequest _) = error "Not implemented"
storeEvent (CreatePayment _) = error "Not implemented"
storeEvent (CreateBillable uid b) =
Just $ storeEventJSON uid "create_billable" (billableJSON b)
storeEvent (CreateSubscription uid bid) =
Just $ storeEventJSON uid "create_subscription" (subscriptionJSON uid bid)
storeEvent (CreatePaymentRequest _ _) = error "Not implemented"
storeEvent (CreatePayment _ _) = error "Not implemented"
type EventType = Text
storeEventJSON :: UserId -> EventType -> Value -> QDBM EventId
storeEventJSON uid t v = do
timestamp <- liftIO C.getCurrentTime
pinsert EventId
"INSERT INTO aftok_events \
\(event_time, created_by, event_type, event_json) \
\VALUES (?, ?, ?, ?) RETURNING id"
(fromThyme timestamp, uid ^. _UserId, t, v)
createBillable :: Billable -> DBProg BillableId
createBillable b = withProjectAuth (b ^. B.project) (b ^. B.creator) $ CreateBillable b
createBillable :: UserId -> Billable -> DBProg BillableId
createBillable uid b =
withProjectAuth (b ^. B.project) uid $ CreateBillable uid b
billableJSON :: B.Billable -> Value
billableJSON b = v1 $
obj [ "projectId" .= tshow (b ^. (B.project . _ProjectId))
, "name" .= (b ^. B.name)
, "description" .= (b ^. B.description)
, "recurrence" .= recurrenceJSON' (b ^. B.recurrence)
]
recurrenceJSON' :: B.Recurrence -> Value
recurrenceJSON' B.Annually = object [ "annually" .= Null ]
recurrenceJSON' (B.Monthly i) = object [ "monthly " .= object [ "months" .= i ] ]
recurrenceJSON' B.SemiMonthly = object [ "semimonthly" .= Null ]
recurrenceJSON' (B.Weekly i) = object [ "weekly " .= object [ "weeks" .= i ] ]
recurrenceJSON' B.OneTime = object [ "onetime" .= Null ]