feat: add container page api

This commit is contained in:
2024-09-18 23:12:30 +08:00
parent 99f6f58f52
commit 0571863839
6 changed files with 212 additions and 110 deletions

View File

@@ -1,3 +1,4 @@
import { CustomError } from '@abearxiong/router';
import { app } from '../../app.ts';
import { ContainerModel, ContainerData, Container } from './models/index.ts';
@@ -13,6 +14,21 @@ list.run = async (ctx) => {
list.addTo(app);
app
.route({
path: 'container',
key: 'get',
})
.define(async (ctx) => {
const id = ctx.query.id;
if (!id) {
throw new CustomError('id is required');
}
ctx.body = await ContainerModel.findByPk(id);
return ctx;
})
.addTo(app);
const add = app.route({
path: 'container',
key: 'update',
@@ -46,8 +62,7 @@ add.run = async (ctx) => {
containerModel.save();
}
} else {
try{
try {
containerModel = await ContainerModel.create({
...container,
});