feat: add Container and Page Module
This commit is contained in:
56
src/routes/container/list.ts
Normal file
56
src/routes/container/list.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { app } from '../../app.ts';
|
||||
import { ContainerModel, ContainerData } from './models/index.ts';
|
||||
|
||||
const list = app.route({
|
||||
path: 'container',
|
||||
key: 'list',
|
||||
});
|
||||
list.run = async (ctx) => {
|
||||
const list = await ContainerModel.findAll();
|
||||
ctx.body = list;
|
||||
return ctx;
|
||||
};
|
||||
|
||||
list.addTo(app);
|
||||
|
||||
const add = app.route({
|
||||
path: 'container',
|
||||
key: 'add',
|
||||
});
|
||||
add.run = async (ctx) => {
|
||||
// const data = ctx.query;
|
||||
const data: ContainerData = {
|
||||
className: 'name',
|
||||
style: {
|
||||
color: 'red',
|
||||
},
|
||||
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;
|
||||
return ctx;
|
||||
};
|
||||
add.addTo(app);
|
||||
|
||||
const deleteRoute = app.route({
|
||||
path: 'container',
|
||||
key: 'delete',
|
||||
});
|
||||
deleteRoute.run = async (ctx) => {
|
||||
const id = ctx.query.id;
|
||||
const container = await ContainerModel.findByPk(id);
|
||||
if (container) {
|
||||
await container.destroy();
|
||||
}
|
||||
ctx.body = container;
|
||||
return ctx;
|
||||
};
|
||||
deleteRoute.addTo(app);
|
||||
Reference in New Issue
Block a user