Skip to content

Handle delete properly in client-side #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/modal/createApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
title: values.title,
},
{
onSuccess: (key: string) => {
onSuccess: (key?: string) => {
if (!key) {
throw new Error('Key not provided in onSuccess callback.');
}

emit('success', key);
handleClose();
},
Expand Down
4 changes: 1 addition & 3 deletions server/routes/apps/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import AppServices from '~~/server/services/appServices';

export default defineEventHandler(async (event) => {
await new AppServices(event).delete(
event.context.params?.id ?? ''
);
await new AppServices(event).delete(event.context.params?.id ?? '');

return null;
});
5 changes: 1 addition & 4 deletions server/services/appServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export default class AppServices extends SupabaseService {
}

async delete(id: string) {
const apps = await this.client
.from('apps')
.delete()
.eq('id', id);
const apps = await this.client.from('apps').delete().eq('id', id);

if (apps.error !== null) {
throw ErrorResponse.supabase(apps.error);
Expand Down
6 changes: 3 additions & 3 deletions server/services/modelDataServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default class ModelDataService extends SupabaseService {

async deleteByModelId(modelId: string) {
return await this.client
.from('model_data')
.delete()
.eq('model_id', modelId);
.from('model_data')
.delete()
.eq('model_id', modelId);
}

async list(modelId: string) {
Expand Down
6 changes: 3 additions & 3 deletions stores/useApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type UpdateProps = {
};

type Options = {
onSuccess?: (key: string) => void;
onSuccess?: (key?: string) => void;
};

export default defineStore('apps', () => {
Expand Down Expand Up @@ -55,11 +55,11 @@ export default defineStore('apps', () => {
await $fetch(`/apps/${id}`, {
method: 'DELETE',
async onResponse({ response }) {
if (response.status === 200) {
if (response.status === 204) {
toast.success('Deleted the app!');

if (typeof options.onSuccess === 'function') {
options.onSuccess(response._data);
options.onSuccess();
}

await refresh();
Expand Down
2 changes: 1 addition & 1 deletion stores/useModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default defineStore('models', () => {
method: 'DELETE',
query: { apiKey: apiKey.value },
async onResponse({ response }) {
if (response.status === 200) {
if (response.status === 204) {
toast.success('Deleted the model!');

await refresh();
Expand Down
2 changes: 1 addition & 1 deletion stores/useModelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineStore('model-data', () => {
method: 'DELETE',
query: { ids, apiKey: apiKey.value },
async onResponse({ response }) {
if (response.status === 200) {
if (response.status === 204) {
toast.success('Deleted the model data!');

await refresh();
Expand Down
Loading