feat: up code test

This commit is contained in:
Thanaphon Frappet 2025-03-10 15:47:24 +07:00 committed by puriphatt
parent ed9e0cf757
commit 841f1157b1
5 changed files with 592 additions and 2 deletions

View file

@ -0,0 +1,71 @@
import { ref } from 'vue';
import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import { PaginationResult } from 'src/types';
import { Status } from '../types';
import { Property } from './types';
export const useProperty = defineStore('property-store', () => {
const data = ref<Property[]>([]);
const page = ref<number>(1);
const pageMax = ref<number>(1);
const pageSize = ref<number>(30);
async function getProperty(id: string) {
const res = await api.get<Property[]>(`/property/${id}`);
if (res.status >= 400) return null;
return res.data;
}
async function getPropertyList(params?: {
page?: number;
pageSize?: number;
query?: string;
status?: Status;
activeOnly?: boolean;
}) {
const res = await api.get<PaginationResult<Property[]>>('/property', {
params,
});
if (res.status >= 400) return null;
return res.data;
}
async function creatProperty(data: Property) {
const res = await api.post<Property>('/property', data);
if (res.status >= 400) return null;
return res;
}
async function editProperty(data: Property & { id: string }) {
const res = await api.put<Property>(`/property/${data.id}`, {
...data,
id: undefined,
});
if (res.status >= 400) return null;
return res;
}
async function deleteProperty(id: string) {
const res = await api.delete<Property>(`/property/${id}`);
if (res.status >= 400) return null;
return res;
}
return {
data,
page,
pageSize,
pageMax,
getProperty,
getPropertyList,
creatProperty,
editProperty,
deleteProperty,
};
});

View file

@ -0,0 +1,5 @@
export type Property = {
name: string;
nameEn: string;
type: Record<string, any>;
};