From 1743d13f0fb2f1b139c8c21d9c4e60df36648e27 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Mon, 5 Dec 2022 23:10:44 -0800 Subject: [PATCH] feat: :sparkles: Add delete all lists --- package.json | 2 +- packages/backend/src/server/api/endpoints.ts | 2 ++ .../api/endpoints/users/lists/delete-all.ts | 36 +++++++++++++++++++ packages/client/src/pages/my-lists/index.vue | 12 +++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/server/api/endpoints/users/lists/delete-all.ts diff --git a/package.json b/package.json index c5540850a..f72b1b335 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calckey", - "version": "12.119.0-calc.19-b4", + "version": "12.119.0-calc.19-b5", "codename": "aqua", "repository": { "type": "git", diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index d662d53af..d56dd316e 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -306,6 +306,7 @@ import * as ep___users_groups_transfer from './endpoints/users/groups/transfer.j import * as ep___users_groups_update from './endpoints/users/groups/update.js'; import * as ep___users_lists_create from './endpoints/users/lists/create.js'; import * as ep___users_lists_delete from './endpoints/users/lists/delete.js'; +import * as ep___users_lists_delete_all from './endpoints/users/lists/delete-all.js'; import * as ep___users_lists_list from './endpoints/users/lists/list.js'; import * as ep___users_lists_pull from './endpoints/users/lists/pull.js'; import * as ep___users_lists_push from './endpoints/users/lists/push.js'; @@ -631,6 +632,7 @@ const eps = [ ['users/groups/update', ep___users_groups_update], ['users/lists/create', ep___users_lists_create], ['users/lists/delete', ep___users_lists_delete], + ['users/lists/delete-all', ep___users_lists_delete_all], ['users/lists/list', ep___users_lists_list], ['users/lists/pull', ep___users_lists_pull], ['users/lists/push', ep___users_lists_push], diff --git a/packages/backend/src/server/api/endpoints/users/lists/delete-all.ts b/packages/backend/src/server/api/endpoints/users/lists/delete-all.ts new file mode 100644 index 000000000..9bea5c164 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/users/lists/delete-all.ts @@ -0,0 +1,36 @@ +import { UserLists } from '@/models/index.js'; +import define from '../../../define.js'; +import { ApiError } from '../../../error.js'; + +export const meta = { + tags: ['lists'], + + requireCredential: true, + + kind: 'write:account', + + description: 'Delete all lists of users.', + + errors: { + noSuchList: { + message: 'No such list.', + code: 'NO_SUCH_LIST', + id: '78436795-db79-42f5-b1e2-55ea2cf19166', + }, + }, +} as const; + +export const paramDef = { + type: 'object', +} as const; + +// eslint-disable-next-line import/no-default-export +export default define(meta, paramDef, async (ps, user) => { + while (await UserLists.findOneBy({ userId: user.id }) != null) { + const userList = await UserLists.findOneBy({ userId: user.id }); + if (userList == null) { + throw new ApiError(meta.errors.noSuchList); + } + await UserLists.delete(userList.id); + } +}); diff --git a/packages/client/src/pages/my-lists/index.vue b/packages/client/src/pages/my-lists/index.vue index f959929ff..53c5ef70e 100644 --- a/packages/client/src/pages/my-lists/index.vue +++ b/packages/client/src/pages/my-lists/index.vue @@ -4,6 +4,7 @@
{{ i18n.ts.createList }} + {{ i18n.ts.deleteAll }} @@ -41,6 +42,17 @@ async function create() { pagingComponent.reload(); } +async function deleteAll() { + const { canceled } = await os.confirm({ + type: 'warning', + text: i18n.t('removeAreYouSure', { x: 'all lists' }), + }); + if (canceled) return; + + await os.api('users/lists/delete-all'); + os.success(); +} + const headerActions = $computed(() => []); const headerTabs = $computed(() => []);