refactor: add map to contact store

This commit is contained in:
Methapon-Frappet 2024-04-13 16:50:06 +07:00
parent f91bb46c6b
commit 05d13e5620

View file

@ -1,12 +1,26 @@
import axios from 'axios';
import { ref } from 'vue';
import { ref, watch } from 'vue';
import { defineStore } from 'pinia';
import { BranchContact, BranchContactCreate } from './types';
import { Pagination } from '../types';
import { api } from 'src/boot/axios';
type BranchContactId = string;
const useBranchContactStore = defineStore('api-branch-contact', () => {
const data = ref<Pagination<BranchContact[]>>();
const data = ref<Pagination<BranchContact[]>>({
result: [],
page: 0,
pageSize: 0,
total: 0,
});
const map = ref<Record<BranchContactId, BranchContact>>({});
watch(data, () => {
data.value.result.forEach((v) => {
map.value[v.id] = v;
});
});
async function fetchList(
branchId: string,
@ -146,6 +160,8 @@ const useBranchContactStore = defineStore('api-branch-contact', () => {
}
return {
data,
map,
fetchList,
create,
editById,