feat: add workflow template store
This commit is contained in:
parent
0bc7aac41f
commit
6381048ea7
2 changed files with 103 additions and 0 deletions
64
src/stores/workflow-template/index.ts
Normal file
64
src/stores/workflow-template/index.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { PaginationResult } from 'src/types';
|
||||
import { WorkflowTemplate } from './types';
|
||||
|
||||
export const useWorkflowTemplate = defineStore('workkflow-store', () => {
|
||||
const data = ref<WorkflowTemplate[]>([]);
|
||||
const page = ref<number>(1);
|
||||
const pageMax = ref<number>(1);
|
||||
const pageSize = ref<number>(30);
|
||||
|
||||
async function getWorkflowTemplate(id: string) {
|
||||
const res = await api.get<WorkflowTemplate>(`/workflow-template/${id}`);
|
||||
|
||||
if (res.status >= 400) return null;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function getWorkflowTemplateList(query?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}) {
|
||||
const res = await api.get<PaginationResult<WorkflowTemplate>>(
|
||||
'/workflow-template',
|
||||
{ params: query },
|
||||
);
|
||||
|
||||
if (res.status >= 400) return null;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function editWorkflowTemplate(data: WorkflowTemplate & { id: string }) {
|
||||
const res = await api.put<WorkflowTemplate>(
|
||||
`/workflow-template/${data.id}`,
|
||||
{
|
||||
...data,
|
||||
id: undefined,
|
||||
},
|
||||
);
|
||||
if (res.status >= 400) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
async function deleteWorkflowTemplate(id: string) {
|
||||
const res = await api.delete(`/workflow-template/${id}`);
|
||||
if (res.status >= 400) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
page,
|
||||
pageSize,
|
||||
pageMax,
|
||||
|
||||
getWorkflowTemplate,
|
||||
getWorkflowTemplateList,
|
||||
editWorkflowTemplate,
|
||||
deleteWorkflowTemplate,
|
||||
};
|
||||
});
|
||||
39
src/stores/workflow-template/types.ts
Normal file
39
src/stores/workflow-template/types.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { CreatedBy, Status } from '../types';
|
||||
|
||||
export type WorkflowStep = {
|
||||
id: string;
|
||||
order: number;
|
||||
name: string;
|
||||
type: string | null;
|
||||
|
||||
// NOTE: for list like type only
|
||||
value: string[];
|
||||
|
||||
// NOTE: for step that needs confirm
|
||||
responsiblePerson: {
|
||||
userId: string;
|
||||
user: CreatedBy;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type WorkflowTemplate = {
|
||||
id: string;
|
||||
name: string;
|
||||
step: WorkflowStep[];
|
||||
status: Status;
|
||||
statusOrder: number;
|
||||
createdAt: string;
|
||||
createdByUserId: string | null;
|
||||
updatedAt: string;
|
||||
updatedByUserId: string;
|
||||
};
|
||||
|
||||
export type WorkflowTemplatePayload = {
|
||||
name: string;
|
||||
step: {
|
||||
name: string;
|
||||
type?: string;
|
||||
value?: string[];
|
||||
responseiblePersonId?: string[];
|
||||
}[];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue