53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { type BlockSchema } from '@vtj/core';
|
|
import instance from './instance';
|
|
import { fi } from 'element-plus/es/locale/index.mjs';
|
|
|
|
export type LowCodeFileSchema = {
|
|
project_id: number;
|
|
publish: boolean;
|
|
active: boolean;
|
|
dsl: BlockSchema;
|
|
file_path?: string;
|
|
file_id?: string;
|
|
};
|
|
|
|
function transformFile(file: LowCodeFileSchema): LowCodeFileSchema {
|
|
return {
|
|
project_id: file.project_id,
|
|
publish: file.publish,
|
|
active: file.active,
|
|
// @ts-ignore
|
|
dsl: JSON.stringify(file.dsl),
|
|
file_path: file.file_path,
|
|
file_id: file.file_id
|
|
};
|
|
}
|
|
|
|
export const getFileList = async () => {
|
|
const response = await instance.get('/api/v1/files');
|
|
return response.data;
|
|
};
|
|
|
|
export const getFile = async (id: string) => {
|
|
const response = await instance.get(`/api/v1/files/${id}`);
|
|
return response.data;
|
|
};
|
|
|
|
export const createFile = async (data: LowCodeFileSchema) => {
|
|
const response = await instance.post('/api/v1/files', transformFile(data));
|
|
return response.data;
|
|
};
|
|
|
|
export const updateFile = async (id: string, data: LowCodeFileSchema) => {
|
|
const response = await instance.put(
|
|
`/api/v1/files/${id}`,
|
|
transformFile(data)
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
export const deleteFile = async (id: string) => {
|
|
const response = await instance.delete(`/api/v1/files/${id}`);
|
|
return response.data;
|
|
};
|