feat: add signature api function

This commit is contained in:
Methapon2001 2025-03-26 15:48:05 +07:00
parent ee8bd14f48
commit 5d7129b858
2 changed files with 31 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import {
import axios from 'axios'; import axios from 'axios';
import useBranchStore from '../branch'; import useBranchStore from '../branch';
import { Branch } from '../branch/types'; import { Branch } from '../branch/types';
import { getSignature, setSignature } from './signature';
const branchStore = useBranchStore(); const branchStore = useBranchStore();
@ -327,6 +328,9 @@ const useUserStore = defineStore('api-user', () => {
addAttachment, addAttachment,
deleteAttachment, deleteAttachment,
getSignature,
setSignature,
typeStats, typeStats,
}; };
}); });

View file

@ -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<Blob>('/user/' + userId + '/signature', {
responseType: 'blob',
});
return await new Promise<string>((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 });
}