feat: menu agencies (#65)
* feat: agencies => add agencies menu --------- Co-authored-by: Methapon Metanipat <methapon@frappet.com>
This commit is contained in:
parent
f6479cc72d
commit
b87e15301f
12 changed files with 1305 additions and 18 deletions
75
src/stores/institution/index.ts
Normal file
75
src/stores/institution/index.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { Institution, InstitutionPayload } from './types';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { PaginationResult } from 'src/types';
|
||||
|
||||
export const useInstitution = defineStore('institution-store', () => {
|
||||
const data = ref<Institution[]>([]);
|
||||
const page = ref<number>(1);
|
||||
const pageMax = ref<number>(1);
|
||||
const pageSize = ref<number>(30);
|
||||
|
||||
async function getInstitution(id: string) {
|
||||
const res = await api.get<Institution>(`/institution/${id}`);
|
||||
if (res.status < 400) {
|
||||
return res.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getInstitutionList(params?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
query?: string;
|
||||
group?: string;
|
||||
}) {
|
||||
const res = await api.get<PaginationResult<Institution>>('/institution', {
|
||||
params,
|
||||
});
|
||||
if (res.status < 400) {
|
||||
return res.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function createInstitution(data: InstitutionPayload) {
|
||||
const res = await api.post('/institution', data);
|
||||
if (res.status < 400) {
|
||||
return res.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function editInstitution(data: InstitutionPayload & { id: string }) {
|
||||
const res = await api.put(`/institution/${data.id}`, {
|
||||
...data,
|
||||
id: undefined,
|
||||
});
|
||||
if (res.status < 400) {
|
||||
return res.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function deleteInstitution(id: string) {
|
||||
const res = await api.delete(`/institution/${id}`);
|
||||
if (res.status < 400) {
|
||||
return res.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
page,
|
||||
pageMax,
|
||||
pageSize,
|
||||
|
||||
getInstitution,
|
||||
getInstitutionList,
|
||||
createInstitution,
|
||||
editInstitution,
|
||||
deleteInstitution,
|
||||
};
|
||||
});
|
||||
45
src/stores/institution/types.ts
Normal file
45
src/stores/institution/types.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { District, Province, SubDistrict } from '../address';
|
||||
|
||||
export type Institution = {
|
||||
id: string;
|
||||
code: string;
|
||||
group: string;
|
||||
name: string;
|
||||
nameEN: string;
|
||||
|
||||
addressEN: string;
|
||||
address: string;
|
||||
soi: string | null;
|
||||
soiEN: string | null;
|
||||
moo: string | null;
|
||||
mooEN: string | null;
|
||||
street: string | null;
|
||||
streetEN: string | null;
|
||||
province?: Province;
|
||||
district?: District;
|
||||
subDistrict?: SubDistrict;
|
||||
|
||||
subDistrictId: string;
|
||||
districtId: string;
|
||||
provinceId: string;
|
||||
};
|
||||
|
||||
export type InstitutionPayload = {
|
||||
code: string;
|
||||
name: string;
|
||||
nameEN: string;
|
||||
group?: string;
|
||||
|
||||
addressEN: string;
|
||||
address: string;
|
||||
soi?: string | null;
|
||||
soiEN?: string | null;
|
||||
moo?: string | null;
|
||||
mooEN?: string | null;
|
||||
street?: string | null;
|
||||
streetEN?: string | null;
|
||||
|
||||
subDistrictId: string;
|
||||
districtId: string;
|
||||
provinceId: string;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue