feat: add types and list change
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -7,6 +7,16 @@ export interface ContainerData {
|
||||
showChild?: boolean;
|
||||
shadowRoot?: boolean;
|
||||
}
|
||||
export type Container = {
|
||||
id?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
type?: string;
|
||||
code?: string;
|
||||
source?: string;
|
||||
sourceType?: string;
|
||||
data?: ContainerData;
|
||||
};
|
||||
export class ContainerModel extends Model {
|
||||
declare id: string;
|
||||
declare title: string;
|
||||
@@ -14,6 +24,7 @@ export class ContainerModel extends Model {
|
||||
declare type: string;
|
||||
declare code: string;
|
||||
declare source: string;
|
||||
declare sourceType: string;
|
||||
declare data: ContainerData;
|
||||
}
|
||||
ContainerModel.init(
|
||||
@@ -37,13 +48,17 @@ ContainerModel.init(
|
||||
defaultValue: '',
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: '',
|
||||
},
|
||||
source: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
sourceType: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: {},
|
||||
|
||||
1
src/routes/types.ts
Normal file
1
src/routes/types.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './container/type.ts'
|
||||
@@ -1,3 +1,5 @@
|
||||
import { CodeManager } from './admin/dashboard/load.ts';
|
||||
import { ContainerData } from './routes/types.ts';
|
||||
|
||||
export { CodeManager };
|
||||
export { ContainerData };
|
||||
|
||||
Reference in New Issue
Block a user