refactor: util fn

This commit is contained in:
Methapon Metanipat 2024-10-30 11:36:30 +07:00
parent 19428bef81
commit 77bc4973a9

View file

@ -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<T extends unknown[]>(
arr: T,
idx: number,
offset: number,
) {
arr.splice(idx + offset, 0, ...arr.splice(idx, 1));
}
export function moveItemUp<T extends unknown[]>(items: T, index: number) {
moveItem(items, index, -1);
arr.move(items, index, -1);
}
export function moveItemDown<T extends unknown[]>(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<T extends string>(
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;