From 77bc4973a92e6d033a3bd484dee2d3f23e23215d Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Wed, 30 Oct 2024 11:36:30 +0700 Subject: [PATCH] refactor: util fn --- src/stores/utils/index.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 35fa356e..117f4679 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -4,6 +4,7 @@ import axios, { AxiosInstance, AxiosProgressEvent } from 'axios'; import { ComposerTranslation } from 'vue-i18n'; import { defineStore } from 'pinia'; +import arr from 'src/utils/arr'; import { getRole } from 'src/services/keycloak'; import GlobalDialog from 'components/GlobalDialog.vue'; @@ -96,20 +97,12 @@ export function notify( } } -export function moveItem( - arr: T, - idx: number, - offset: number, -) { - arr.splice(idx + offset, 0, ...arr.splice(idx, 1)); -} - export function moveItemUp(items: T, index: number) { - moveItem(items, index, -1); + arr.move(items, index, -1); } export function moveItemDown(items: T, index: number) { - moveItem(items, index, 1); + arr.move(items, index, 1); } export function deleteItem(items: unknown[], index: number) { @@ -266,6 +259,12 @@ export function manageAttachment( if (res.status >= 400) return false; return res.data; }, + headAttachment: async (opts: { parentId: string; fileId: string }) => { + const url = `/${base}/${opts.parentId}/attachment/${opts.fileId}`; + const res = await api.head(url); + if (res.status < 400) return res.headers; + return false; + }, getAttachment: async (opts: { parentId: string; name: string; @@ -337,6 +336,12 @@ export function manageFile( if (res.status >= 400) return false; return res.data; }, + headFile: async (opts: { group: T; parentId: string; fileId: string }) => { + const url = `/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`; + const res = await api.head(url); + if (res.status < 400) return res.headers; + return false; + }, getFile: async (opts: { group: T; parentId: string;