1- import { supabase } from './supabase'
1+ import { getSupabase } from './supabase'
22import { Project , Task , ProjectWithStats , ChatMessage } from '@/types'
33
44export class SupabaseService {
5+ private static get supabase ( ) {
6+ return getSupabase ( )
7+ }
58 // Project operations
69 static async getProjects ( ) : Promise < ProjectWithStats [ ] > {
7- const { data, error } = await supabase
10+ const { data, error } = await this . supabase
811 . from ( 'projects' )
912 . select ( `
1013 *,
@@ -35,10 +38,10 @@ export class SupabaseService {
3538 settings ?: any
3639 } ) : Promise < Project > {
3740 // Get current authenticated user
38- const { data : { user } } = await supabase . auth . getUser ( )
41+ const { data : { user } } = await this . supabase . auth . getUser ( )
3942 if ( ! user ) throw new Error ( 'No authenticated user' )
4043
41- const { data, error } = await supabase
44+ const { data, error } = await this . supabase
4245 . from ( 'projects' )
4346 . insert ( [ { ...projectData , user_id : user . id } ] )
4447 . select ( )
@@ -49,7 +52,7 @@ export class SupabaseService {
4952 }
5053
5154 static async updateProject ( id : number , updates : Partial < Project > ) : Promise < Project > {
52- const { data, error } = await supabase
55+ const { data, error } = await this . supabase
5356 . from ( 'projects' )
5457 . update ( updates )
5558 . eq ( 'id' , id )
@@ -61,7 +64,7 @@ export class SupabaseService {
6164 }
6265
6366 static async deleteProject ( id : number ) : Promise < void > {
64- const { error } = await supabase
67+ const { error } = await this . supabase
6568 . from ( 'projects' )
6669 . delete ( )
6770 . eq ( 'id' , id )
@@ -70,7 +73,7 @@ export class SupabaseService {
7073 }
7174
7275 static async getProject ( id : number ) : Promise < Project | null > {
73- const { data, error } = await supabase
76+ const { data, error } = await this . supabase
7477 . from ( 'projects' )
7578 . select ( '*' )
7679 . eq ( 'id' , id )
@@ -86,10 +89,10 @@ export class SupabaseService {
8689 // Task operations
8790 static async getTasks ( projectId ?: number ) : Promise < Task [ ] > {
8891 // Get current authenticated user
89- const { data : { user } } = await supabase . auth . getUser ( )
92+ const { data : { user } } = await this . supabase . auth . getUser ( )
9093 if ( ! user ) throw new Error ( 'No authenticated user' )
9194
92- let query = supabase
95+ let query = this . supabase
9396 . from ( 'tasks' )
9497 . select ( `
9598 *,
@@ -113,7 +116,7 @@ export class SupabaseService {
113116 }
114117
115118 static async getTask ( id : number ) : Promise < Task | null > {
116- const { data, error } = await supabase
119+ const { data, error } = await this . supabase
117120 . from ( 'tasks' )
118121 . select ( `
119122 *,
@@ -142,10 +145,10 @@ export class SupabaseService {
142145 chat_messages ?: ChatMessage [ ]
143146 } ) : Promise < Task > {
144147 // Get current authenticated user
145- const { data : { user } } = await supabase . auth . getUser ( )
148+ const { data : { user } } = await this . supabase . auth . getUser ( )
146149 if ( ! user ) throw new Error ( 'No authenticated user' )
147150
148- const { data, error } = await supabase
151+ const { data, error } = await this . supabase
149152 . from ( 'tasks' )
150153 . insert ( [ {
151154 ...taskData ,
@@ -161,7 +164,7 @@ export class SupabaseService {
161164 }
162165
163166 static async updateTask ( id : number , updates : Partial < Task > ) : Promise < Task > {
164- const { data, error } = await supabase
167+ const { data, error } = await this . supabase
165168 . from ( 'tasks' )
166169 . update ( updates )
167170 . eq ( 'id' , id )
@@ -174,7 +177,7 @@ export class SupabaseService {
174177
175178 static async addChatMessage ( taskId : number , message : ChatMessage ) : Promise < Task > {
176179 // First get the current task to get existing messages
177- const { data : task , error : fetchError } = await supabase
180+ const { data : task , error : fetchError } = await this . supabase
178181 . from ( 'tasks' )
179182 . select ( 'chat_messages' )
180183 . eq ( 'id' , taskId )
@@ -185,7 +188,7 @@ export class SupabaseService {
185188 const existingMessages = ( task . chat_messages as unknown as ChatMessage [ ] ) || [ ]
186189 const updatedMessages = [ ...existingMessages , message ]
187190
188- const { data, error } = await supabase
191+ const { data, error } = await this . supabase
189192 . from ( 'tasks' )
190193 . update ( {
191194 chat_messages : updatedMessages as any ,
@@ -201,15 +204,15 @@ export class SupabaseService {
201204
202205 // User operations
203206 static async getCurrentUser ( ) {
204- const { data : { user } } = await supabase . auth . getUser ( )
207+ const { data : { user } } = await this . supabase . auth . getUser ( )
205208 return user
206209 }
207210
208211 static async getUserProfile ( ) {
209- const { data : { user } } = await supabase . auth . getUser ( )
212+ const { data : { user } } = await this . supabase . auth . getUser ( )
210213 if ( ! user ) return null
211214
212- const { data, error } = await supabase
215+ const { data, error } = await this . supabase
213216 . from ( 'users' )
214217 . select ( '*' )
215218 . eq ( 'id' , user . id )
@@ -228,10 +231,10 @@ export class SupabaseService {
228231 github_token ?: string
229232 preferences ?: any
230233 } ) {
231- const { data : { user } } = await supabase . auth . getUser ( )
234+ const { data : { user } } = await this . supabase . auth . getUser ( )
232235 if ( ! user ) throw new Error ( 'No authenticated user' )
233236
234- const { data, error } = await supabase
237+ const { data, error } = await this . supabase
235238 . from ( 'users' )
236239 . update ( updates )
237240 . eq ( 'id' , user . id )
0 commit comments