diff --git a/server/routes/apps/[id].delete.ts b/server/routes/apps/[id].delete.ts index c2f10d3..90eab08 100644 --- a/server/routes/apps/[id].delete.ts +++ b/server/routes/apps/[id].delete.ts @@ -1,9 +1,9 @@ import AppServices from '~~/server/services/appServices'; export default defineEventHandler(async (event) => { - const deleted = await new AppServices(event).delete( + await new AppServices(event).delete( event.context.params?.id ?? '' ); - return deleted; + return null; }); diff --git a/server/routes/models/[id].delete.ts b/server/routes/models/[id].delete.ts index 05de52a..bd9c262 100644 --- a/server/routes/models/[id].delete.ts +++ b/server/routes/models/[id].delete.ts @@ -10,10 +10,10 @@ export default defineEventHandler(async (event) => { const { appId } = await extractAppKey(event, query.apiKey); const modelId = event.context.params?.id ?? ''; - const model = await new ModelServices(event).delete({ + await new ModelServices(event).delete({ id: modelId, appId, }); - return model; + return null; }); diff --git a/server/routes/models/[id]/model-data.delete.ts b/server/routes/models/[id]/model-data.delete.ts index 0e9df70..8bef645 100644 --- a/server/routes/models/[id]/model-data.delete.ts +++ b/server/routes/models/[id]/model-data.delete.ts @@ -13,10 +13,10 @@ export default defineEventHandler(async (event) => { const ids = query.ids.split(','); - const deleted = await new ModelDataServices(event).bulkDelete({ + await new ModelDataServices(event).bulkDelete({ ids, modelId: event.context.params?.id ?? '', }); - return deleted; + return null; }); diff --git a/server/services/appServices.ts b/server/services/appServices.ts index 6f33509..0d8ad17 100644 --- a/server/services/appServices.ts +++ b/server/services/appServices.ts @@ -22,24 +22,20 @@ export default class AppServices extends SupabaseService { async delete(id: string) { const apps = await this.client .from('apps') - .update({ - deleted_at: new Date().toISOString(), - }) - .eq('id', id) - .select('*'); + .delete() + .eq('id', id); if (apps.error !== null) { throw ErrorResponse.supabase(apps.error); } - return apps.data[0]; + return null; } async find(id: string) { const apps = await this.client .from('apps') .select('*') - .is('deleted_at', null) .eq('id', id) .eq('user_id', this.user.id); @@ -58,7 +54,6 @@ export default class AppServices extends SupabaseService { const app = await this.client .from('apps') .select('*') - .is('deleted_at', null) .eq('title', title) .eq('user_id', this.user.id); @@ -73,7 +68,6 @@ export default class AppServices extends SupabaseService { const apps = await this.client .from('apps') .select('id, title, description, app_keys(api_key)') - .is('deleted_at', null) .is('app_keys.deleted_at', null) .eq('user_id', this.user.id) .order('created_at', { ascending: false }); diff --git a/server/services/modelDataServices.ts b/server/services/modelDataServices.ts index 69c8422..7462cd6 100644 --- a/server/services/modelDataServices.ts +++ b/server/services/modelDataServices.ts @@ -21,12 +21,9 @@ export default class ModelDataService extends SupabaseService { params.ids.map((id) => { return this.client .from('model_data') - .update({ - deleted_at: new Date().toISOString(), - }) + .delete() .eq('id', id) - .eq('model_id', params.modelId) - .select('*'); + .eq('model_id', params.modelId); }) ); } @@ -35,7 +32,6 @@ export default class ModelDataService extends SupabaseService { const modelData = await this.client .from('model_data') .select('*', { count: 'exact', head: true }) - .is('deleted_at', null) .eq('model_id', modelId) .order('created_at', { ascending: false }); @@ -46,11 +42,17 @@ export default class ModelDataService extends SupabaseService { return modelData.count ?? 0; } + async deleteByModelId(modelId: string) { + return await this.client + .from('model_data') + .delete() + .eq('model_id', modelId); + } + async list(modelId: string) { const modelData = await this.client .from('model_data') .select('id, schema') - .is('deleted_at', null) .eq('model_id', modelId) .order('created_at', { ascending: false }); diff --git a/server/services/modelServices.ts b/server/services/modelServices.ts index 1c8a1ce..e1d4641 100644 --- a/server/services/modelServices.ts +++ b/server/services/modelServices.ts @@ -25,26 +25,22 @@ export default class ModelServices extends SupabaseService { async delete(params: { id: string; appId: string }) { const model = await this.client .from('models') - .update({ - deleted_at: new Date().toISOString(), - }) + .delete() .eq('id', params.id) .eq('app_id', params.appId) - .eq('user_id', this.user.id) - .select('*'); + .eq('user_id', this.user.id); if (model.error !== null) { throw ErrorResponse.supabase(model.error); } - return model.data[0]; + return null; } async findByName(params: { name: string; appId: string }) { const models = await this.client .from('models') .select('*') - .is('deleted_at', null) .eq('name', params.name) .eq('app_id', params.appId) .eq('user_id', this.user.id); @@ -60,7 +56,6 @@ export default class ModelServices extends SupabaseService { const models = await this.client .from('models') .select('*') - .is('deleted_at', null) .eq('id', id) .eq('user_id', this.user.id); @@ -79,7 +74,6 @@ export default class ModelServices extends SupabaseService { const models = await this.client .from('models') .select('id, name, schema') - .is('deleted_at', null) .eq('app_id', appId) .eq('user_id', this.user.id) .order('created_at', { ascending: false }); diff --git a/supabase/migrations/20240616150923_remove_deleted_at.sql b/supabase/migrations/20240616150923_remove_deleted_at.sql new file mode 100644 index 0000000..183044f --- /dev/null +++ b/supabase/migrations/20240616150923_remove_deleted_at.sql @@ -0,0 +1,3 @@ +alter table models drop column deleted_at; +alter table model_data drop column deleted_at; +alter table apps drop column deleted_at;