fix: แก้ function การสร้าง

This commit is contained in:
Net 2024-04-18 13:56:22 +07:00
parent 17b9450b47
commit 0458c33266
3 changed files with 17 additions and 15 deletions

View file

@ -64,18 +64,15 @@ const useBranchContactStore = defineStore('api-branch-contact', () => {
async function create( async function create(
branchId: string, branchId: string,
data: BranchContactCreate, data: BranchContactCreate,
qrCodeImage?: File | null, // required but not strict
flow?: { flow?: {
sessionId: string; sessionId: string;
refTransactionId: string; refTransactionId: string;
transactionId: string; transactionId: string;
}, },
) { ) {
const { ...payload } = data;
const res = await api.post< const res = await api.post<
BranchContact & { qrCodeImageUploadUrl: string } BranchContact & { qrCodeImageUploadUrl: string }
>(`/branch/${branchId}/contact`, payload, { >(`/branch/${branchId}/contact`, data, {
headers: { headers: {
'X-Session-Id': flow?.sessionId, 'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId, 'X-Rtid': flow?.refTransactionId,
@ -83,14 +80,6 @@ const useBranchContactStore = defineStore('api-branch-contact', () => {
}, },
}); });
qrCodeImage &&
(await axios
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
headers: { 'Content-Type': qrCodeImage.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e)));
if (!res) return false; if (!res) return false;
return res.data; return res.data;

View file

@ -4,6 +4,7 @@ import { Pagination } from '../types';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { Branch, BranchCreate } from './types'; import { Branch, BranchCreate } from './types';
import { BranchContact } from '../branch-contact/types'; import { BranchContact } from '../branch-contact/types';
import axios from 'axios';
type BranchId = string; type BranchId = string;
@ -123,9 +124,11 @@ const useBranchStore = defineStore('api-branch', () => {
transactionId: string; transactionId: string;
}, },
) { ) {
const { qrCodeImage, ...payload } = branch;
const res = await api.post< const res = await api.post<
Branch & { qrCodeImageUrl: string; qrCodeImageUploadUrl: string } Branch & { qrCodeImageUrl: string; qrCodeImageUploadUrl: string }
>('/branch', branch, { >('/branch', payload, {
headers: { headers: {
'X-Session-Id': flow?.sessionId, 'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId, 'X-Rtid': flow?.refTransactionId,
@ -133,6 +136,13 @@ const useBranchStore = defineStore('api-branch', () => {
}, },
}); });
qrCodeImage &&
(await axios
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
headers: { 'Content-Type': qrCodeImage.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e)));
if (!res) return false; if (!res) return false;
return res.data; return res.data;

View file

@ -42,14 +42,17 @@ export type BranchCreate = {
address: string; address: string;
zipCode: string; zipCode: string;
email: string; email: string;
contactName: string;
telephoneNo: string | string[];
longitude: string; longitude: string;
latitude: string; latitude: string;
subDistrictId?: string | null; subDistrictId?: string | null;
districtId?: string | null; districtId?: string | null;
provinceId?: string | null; provinceId?: string | null;
headOfficeId?: string | null; headOfficeId?: string | null;
telephoneNo: string;
contactName: string;
contact: string;
qrCodeImage: File;
lineId: string;
}; };
export type BranchUserStats = { export type BranchUserStats = {