Skip to content

Commit 0878f8a

Browse files
committed
[dewbee-function] master
v0.4.0 1. 주간 소비 집계 함수 구현 2. 일간 소비 집계 함수 개선 - 타입 개선
1 parent f8009b9 commit 0878f8a

File tree

5 files changed

+817
-6
lines changed

5 files changed

+817
-6
lines changed

supabase/functions/create-daily-result/filter-types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Database } from './types'
2-
31
export type Json =
42
| string
53
| number
@@ -8,7 +6,7 @@ export type Json =
86
| { [key: string]: Json | undefined }
97
| Json[]
108

11-
export type FilterDatabase = {
9+
export type Database = {
1210
filter: {
1311
Tables: {
1412
currency: {

supabase/functions/create-daily-result/index.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { serve } from 'https://deno.land/[email protected]/http/server.ts'
22
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
33

44
import type { Database } from './types'
5-
import type { FilterDatabase } from './filter-types'
5+
import type { Database as FilterDatabase } from './filter-types'
66

77
console.log('🏅 init Daily Spend Result Function')
88

@@ -11,6 +11,17 @@ const supabase = createClient(
1111
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
1212
)
1313

14+
type UserProfiles = Database['public']['Views']['viewProfiles']['Row'] & {
15+
currency: FilterDatabase['filter']['Tables']['currency']['Row']
16+
endDate: FilterDatabase['filter']['Tables']['endDate']['Row']
17+
}
18+
19+
type ViewSpendList = Database['public']['Views']['viewSpendList']['Row'] & {
20+
profiles: Database['public']['Tables']['profiles']['Row']
21+
currency: FilterDatabase['filter']['Tables']['currency']['Row']
22+
spendCategory: FilterDatabase['filter']['Tables']['spendCategory']['Row']
23+
}
24+
1425
serve(async (req) => {
1526
const payload: { time: string } = await req.json()
1627

@@ -28,7 +39,7 @@ serve(async (req) => {
2839

2940
if (allUsersError) throw allUsersError
3041

31-
for (const user of allUsers) {
42+
for (const user of allUsers as UserProfiles[]) {
3243
const userId = user.id
3344
const userCurrencyId = user.currency.id ?? ''
3445
const userCurrencyCode = user.currency.code ?? ''
@@ -49,7 +60,7 @@ serve(async (req) => {
4960

5061
let dailySummaryAmount = 0
5162

52-
for (const spend of spendList) {
63+
for (const spend of spendList as ViewSpendList[]) {
5364
const amount = spend.amount ?? 0
5465
const currencyCode = spend.currency.code ?? ''
5566

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
export type Json =
2+
| string
3+
| number
4+
| boolean
5+
| null
6+
| { [key: string]: Json | undefined }
7+
| Json[]
8+
9+
export type Database = {
10+
filter: {
11+
Tables: {
12+
currency: {
13+
Row: {
14+
code: string | null
15+
code_name: string | null
16+
created_at: string
17+
deleted: boolean | null
18+
id: string
19+
index: number | null
20+
update_user_id: string | null
21+
updated_at: string | null
22+
}
23+
Insert: {
24+
code?: string | null
25+
code_name?: string | null
26+
created_at?: string
27+
deleted?: boolean | null
28+
id?: string
29+
index?: number | null
30+
update_user_id?: string | null
31+
updated_at?: string | null
32+
}
33+
Update: {
34+
code?: string | null
35+
code_name?: string | null
36+
created_at?: string
37+
deleted?: boolean | null
38+
id?: string
39+
index?: number | null
40+
update_user_id?: string | null
41+
updated_at?: string | null
42+
}
43+
Relationships: []
44+
}
45+
endDate: {
46+
Row: {
47+
code: string | null
48+
code_name: string | null
49+
created_at: string
50+
deleted: boolean | null
51+
id: string
52+
index: number | null
53+
update_user_id: string | null
54+
updated_at: string | null
55+
}
56+
Insert: {
57+
code?: string | null
58+
code_name?: string | null
59+
created_at?: string
60+
deleted?: boolean | null
61+
id?: string
62+
index?: number | null
63+
update_user_id?: string | null
64+
updated_at?: string | null
65+
}
66+
Update: {
67+
code?: string | null
68+
code_name?: string | null
69+
created_at?: string
70+
deleted?: boolean | null
71+
id?: string
72+
index?: number | null
73+
update_user_id?: string | null
74+
updated_at?: string | null
75+
}
76+
Relationships: []
77+
}
78+
plan: {
79+
Row: {
80+
code: string | null
81+
code_name: string | null
82+
created_at: string
83+
deleted: boolean | null
84+
id: string
85+
index: number | null
86+
update_user_id: string | null
87+
updated_at: string | null
88+
}
89+
Insert: {
90+
code?: string | null
91+
code_name?: string | null
92+
created_at?: string
93+
deleted?: boolean | null
94+
id?: string
95+
index?: number | null
96+
update_user_id?: string | null
97+
updated_at?: string | null
98+
}
99+
Update: {
100+
code?: string | null
101+
code_name?: string | null
102+
created_at?: string
103+
deleted?: boolean | null
104+
id?: string
105+
index?: number | null
106+
update_user_id?: string | null
107+
updated_at?: string | null
108+
}
109+
Relationships: []
110+
}
111+
spendCategory: {
112+
Row: {
113+
code: string | null
114+
code_name: string | null
115+
created_at: string
116+
deleted: boolean | null
117+
icon_name: string | null
118+
id: string
119+
index: number | null
120+
update_user_id: string | null
121+
updated_at: string | null
122+
}
123+
Insert: {
124+
code?: string | null
125+
code_name?: string | null
126+
created_at?: string
127+
deleted?: boolean | null
128+
icon_name?: string | null
129+
id?: string
130+
index?: number | null
131+
update_user_id?: string | null
132+
updated_at?: string | null
133+
}
134+
Update: {
135+
code?: string | null
136+
code_name?: string | null
137+
created_at?: string
138+
deleted?: boolean | null
139+
icon_name?: string | null
140+
id?: string
141+
index?: number | null
142+
update_user_id?: string | null
143+
updated_at?: string | null
144+
}
145+
Relationships: []
146+
}
147+
}
148+
Views: {
149+
[_ in never]: never
150+
}
151+
Functions: {
152+
[_ in never]: never
153+
}
154+
Enums: {
155+
[_ in never]: never
156+
}
157+
CompositeTypes: {
158+
[_ in never]: never
159+
}
160+
}
161+
}
162+
163+
type PublicSchema = Database[Extract<keyof Database, "public">]
164+
165+
export type Tables<
166+
PublicTableNameOrOptions extends
167+
| keyof (PublicSchema["Tables"] & PublicSchema["Views"])
168+
| { schema: keyof Database },
169+
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
170+
? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
171+
Database[PublicTableNameOrOptions["schema"]]["Views"])
172+
: never = never,
173+
> = PublicTableNameOrOptions extends { schema: keyof Database }
174+
? (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
175+
Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends {
176+
Row: infer R
177+
}
178+
? R
179+
: never
180+
: PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] &
181+
PublicSchema["Views"])
182+
? (PublicSchema["Tables"] &
183+
PublicSchema["Views"])[PublicTableNameOrOptions] extends {
184+
Row: infer R
185+
}
186+
? R
187+
: never
188+
: never
189+
190+
export type TablesInsert<
191+
PublicTableNameOrOptions extends
192+
| keyof PublicSchema["Tables"]
193+
| { schema: keyof Database },
194+
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
195+
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
196+
: never = never,
197+
> = PublicTableNameOrOptions extends { schema: keyof Database }
198+
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
199+
Insert: infer I
200+
}
201+
? I
202+
: never
203+
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
204+
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
205+
Insert: infer I
206+
}
207+
? I
208+
: never
209+
: never
210+
211+
export type TablesUpdate<
212+
PublicTableNameOrOptions extends
213+
| keyof PublicSchema["Tables"]
214+
| { schema: keyof Database },
215+
TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
216+
? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
217+
: never = never,
218+
> = PublicTableNameOrOptions extends { schema: keyof Database }
219+
? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
220+
Update: infer U
221+
}
222+
? U
223+
: never
224+
: PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
225+
? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
226+
Update: infer U
227+
}
228+
? U
229+
: never
230+
: never
231+
232+
export type Enums<
233+
PublicEnumNameOrOptions extends
234+
| keyof PublicSchema["Enums"]
235+
| { schema: keyof Database },
236+
EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
237+
? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
238+
: never = never,
239+
> = PublicEnumNameOrOptions extends { schema: keyof Database }
240+
? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
241+
: PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
242+
? PublicSchema["Enums"][PublicEnumNameOrOptions]
243+
: never
244+
245+
export type CompositeTypes<
246+
PublicCompositeTypeNameOrOptions extends
247+
| keyof PublicSchema["CompositeTypes"]
248+
| { schema: keyof Database },
249+
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
250+
schema: keyof Database
251+
}
252+
? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"]
253+
: never = never,
254+
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
255+
? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName]
256+
: PublicCompositeTypeNameOrOptions extends keyof PublicSchema["CompositeTypes"]
257+
? PublicSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions]
258+
: never

0 commit comments

Comments
 (0)