feat: add userType filter on fetch list

This commit is contained in:
Methapon2001 2024-04-17 17:20:48 +07:00
parent a6ad08ce84
commit 776600c19b

View file

@ -15,7 +15,7 @@ import axios from 'axios';
import useBranchStore from '../branch';
import { Branch } from '../branch/types';
const branchStore = useBranchStore()
const branchStore = useBranchStore();
const useUserStore = defineStore('api-user', () => {
const userOption = ref<UserOption>({
@ -34,10 +34,15 @@ const useUserStore = defineStore('api-user', () => {
],
responsibleAreaOpts: [
{ label: 'เขตพื้นที่ 1 บางรัก ปทุมวัน ยานนาวสาทร และบางคอแหลม' },
{ label: 'เขตพื้นที่ 2 จอมทอง ทุ่งครุ บางขุนเทียน บางบอน และราษฎร์บูรณะ' },
{
label: 'เขตพื้นที่ 2 จอมทอง ทุ่งครุ บางขุนเทียน บางบอน และราษฎร์บูรณะ',
},
{ label: 'เขตพื้นที่ 3 คลองเตย บางนา ประเวศ พระโขนง วัฒนา และสวนหลวง' },
{ label: 'เขตพื้นที่ 4 คันนายาว บางกะปิ ลาดพร้าว บึงกุ่ม และวังทางหลาง' },
{ label: 'เขตพื้นที่ 5 คลองสามวา มีนบุรี ลาดกระบัง สะพานสูง หนองจอก และสายไหม' },
{
label:
'เขตพื้นที่ 5 คลองสามวา มีนบุรี ลาดกระบัง สะพานสูง หนองจอก และสายไหม',
},
{ label: 'เขตพื้นที่ 6 คลองสาน ธนบุรี บางกอกน้อย บางกอกใหญ่ และบางพลัด' },
{ label: 'เขตพื้นที่ 7 ตลิ่งชัน ทวีวัฒนา บางแค ภาษีเจริญ และหนองแขม' },
{ label: 'เขตพื้นที่ 8 ดุสิต พระนครป้อมปราบศัตรูพ่าย และสัมพันธวงศ์' },
@ -70,13 +75,16 @@ const useUserStore = defineStore('api-user', () => {
const ageDate = new Date(diff);
const years = ageDate.getUTCFullYear() - 1970;
const result = `${years} ปี`
const result = `${years} ปี`;
return result;
}
async function fetchHqOption() {
if (userOption.value.hqOpts.length === 0) {
const res = await branchStore.fetchList({ pageSize: 999, filter: 'head' });
const res = await branchStore.fetchList({
pageSize: 999,
filter: 'head',
});
if (res) {
res.result.map((item) => {
userOption.value.hqOpts.push({
@ -88,7 +96,6 @@ const useUserStore = defineStore('api-user', () => {
}
}
async function fetchBrOption(id: string) {
const res = await branchStore.fetchById(id, {
includeSubBranch: true,
@ -229,6 +236,7 @@ const useUserStore = defineStore('api-user', () => {
zipCode?: string;
query?: string;
includeBranch?: boolean;
userType?: string;
},
flow?: {
sessionId: string;
@ -245,6 +253,7 @@ const useUserStore = defineStore('api-user', () => {
if (opts?.zipCode) params.append('zipCode', opts.zipCode);
if (opts?.query) params.append('query', opts.query);
if (opts?.includeBranch) params.append('includeBranch', 'true');
if (opts?.userType) params.append('userType', opts.userType);
const query = params.toString();
@ -332,7 +341,7 @@ const useUserStore = defineStore('api-user', () => {
transactionId: string;
},
) {
const { profileImage, ...payload } = data
const { profileImage, ...payload } = data;
const res = await api.put<User & { profileImageUploadUrl: string }>(
`/user/${id}`,
payload,