From 5d7129b8588c567dff07c455503e3b06557e796d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Mar 2025 15:48:05 +0700 Subject: [PATCH] feat: add signature api function --- src/stores/user/index.ts | 4 ++++ src/stores/user/signature.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/stores/user/signature.ts diff --git a/src/stores/user/index.ts b/src/stores/user/index.ts index 455e1a5b..2cd894a4 100644 --- a/src/stores/user/index.ts +++ b/src/stores/user/index.ts @@ -15,6 +15,7 @@ import { import axios from 'axios'; import useBranchStore from '../branch'; import { Branch } from '../branch/types'; +import { getSignature, setSignature } from './signature'; const branchStore = useBranchStore(); @@ -327,6 +328,9 @@ const useUserStore = defineStore('api-user', () => { addAttachment, deleteAttachment, + getSignature, + setSignature, + typeStats, }; }); diff --git a/src/stores/user/signature.ts b/src/stores/user/signature.ts new file mode 100644 index 00000000..5ee30ed9 --- /dev/null +++ b/src/stores/user/signature.ts @@ -0,0 +1,27 @@ +import { api } from 'src/boot/axios'; +import { getUserId } from 'src/services/keycloak'; + +export async function getSignature() { + const userId = getUserId(); + + if (!userId) return; + + const response = await api.get('/user/' + userId + '/signature', { + responseType: 'blob', + }); + + return await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('error', reject); + reader.addEventListener('load', () => resolve(reader.result as string)); + reader.readAsDataURL(response.data); + }); +} + +export async function setSignature(image: string) { + const userId = getUserId(); + + if (!userId) return; + + return await api.put('/user/' + userId + '/signature', { data: image }); +}