-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_extend.ts
127 lines (58 loc) · 3.6 KB
/
index_extend.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//type bool = boolean; type str = string; type int = number;
type SERVER_MAINS_T = { app:any, db:any, Firestore:any, sheets:any, notifications:any, sse:any, appversion:number, validate_request:(res:any, req:any)=>Promise<string> }
const SERVER_MAINS:SERVER_MAINS_T = { app:{}, db:{}, Firestore:{}, sheets:{}, notifications:{}, sse:{}, appversion: 0, validate_request: (_req:any) => Promise.resolve("") }
import Finance from "./finance.js"
import Admin_Firestore from "./admin/admin_firestore.js"
function Set_Server_Mains(app:any, db:any, sheets:any, notifications:any, appversion:number, validate_request:any) {
SERVER_MAINS.app = app
SERVER_MAINS.db = db
SERVER_MAINS.sheets = sheets
SERVER_MAINS.notifications = notifications
SERVER_MAINS.appversion = appversion
SERVER_MAINS.validate_request = validate_request
}
function Set_Routes() {
SERVER_MAINS.app.get( '/api/xen/finance/grab_em', grab_em)
SERVER_MAINS.app.get( '/api/xen/finance/ynab_sync_categories', finance_ynab_sync_categories)
SERVER_MAINS.app.get( '/api/xen/finance/get_ynab_raw_transactions', get_ynab_raw_transactions)
SERVER_MAINS.app.post( '/api/xen/finance/save_transactions_and_delete_ynab_records', finance_save_transactions_and_delete_ynab_records)
SERVER_MAINS.app.post( '/api/xen/finance/save_month_snapshots', finance_save_month_snapshots)
SERVER_MAINS.app.get( '/api/xen/admin/firestore_misc_update', admin_firestore_misc_update)
}
// -- ROUTE HANDLERS --
async function grab_em(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const r = await Finance.Grab_Em(SERVER_MAINS.db, SERVER_MAINS.Firestore)
res.status(200).send(JSON.stringify(r))
}
async function finance_ynab_sync_categories(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const categories = await Finance.YNAB_Sync_Categories(SERVER_MAINS.db, SERVER_MAINS.Firestore)
res.status(200).send(JSON.stringify(categories))
}
async function get_ynab_raw_transactions(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const response = await Finance.Get_YNAB_Raw_Transactions(SERVER_MAINS.db)
res.status(200).send(JSON.stringify(response))
}
async function finance_save_transactions_and_delete_ynab_records(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const r = await Finance.Save_Transactions_And_Delete_YNAB_Records(SERVER_MAINS.db, req.body)
res.status(200).send(JSON.stringify(r))
}
async function finance_save_month_snapshots(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const r = await Finance.Save_Month_Snapshots(SERVER_MAINS.db, req.body)
res.status(200).send(JSON.stringify(r))
}
async function admin_firestore_misc_update(req:any, res:any) {
if (! await SERVER_MAINS.validate_request(res, req)) return
const results = await Admin_Firestore.Misc_Update(SERVER_MAINS.db)
res.status(200).send(JSON.stringify(results))
}
const INSTANCEID = "xen"
const PROJECTID = "xenition"
const KEYJSONFILE = "/Users/dave/.ssh/xenition_local.json"
const SHEETS_KEYJSONFILE = "/Users/dave/.ssh/xenition-sheets-244e0733ca64.json"
const IDENTITY_PLATFORM_API = "AIzaSyDfXcwqyiRGGO6pMBsG8CvNEtDIhdspKRI"
export default { INSTANCEID, PROJECTID, KEYJSONFILE, IDENTITY_PLATFORM_API, SHEETS_KEYJSONFILE, Set_Server_Mains, Set_Routes};