feat: add types and list change

This commit is contained in:
2024-09-18 05:19:20 +08:00
parent 0a9e5c1d4f
commit 99f6f58f52
8 changed files with 127 additions and 271 deletions

View File

@@ -1,5 +1,5 @@
import { app } from '../../app.ts';
import { ContainerModel, ContainerData } from './models/index.ts';
import { ContainerModel, ContainerData, Container } from './models/index.ts';
const list = app.route({
path: 'container',
@@ -15,27 +15,49 @@ list.addTo(app);
const add = app.route({
path: 'container',
key: 'add',
key: 'update',
});
add.run = async (ctx) => {
// const data = ctx.query;
const data: ContainerData = {
className: 'name',
style: {
color: 'red',
const data = ctx.query.data;
const _data: Container = {
title: '',
description: '',
code: '',
source: '',
type: '',
sourceType: '',
data: {
className: '',
style: {},
showChild: true,
shadowRoot: false,
},
showChild: true,
shadowRoot: false,
};
const container = await ContainerModel.create({
title: 'title',
data: data as ContainerData,
description: 'description',
code: `console.log('hello world')`,
source: 'source',
type: 'typescript',
});
ctx.body = container;
const container = {
..._data,
...data,
};
let containerModel: any = null;
if (container.id) {
containerModel = await ContainerModel.findByPk(container.id);
if (containerModel) {
containerModel.update(container);
containerModel.save();
}
} else {
try{
containerModel = await ContainerModel.create({
...container,
});
} catch (e) {
console.log('error', e);
}
console.log('containerModel', container);
}
ctx.body = containerModel;
return ctx;
};
add.addTo(app);