From edde6181f73555568247ca4ca1190ccd1f16841d Mon Sep 17 00:00:00 2001 From: xion Date: Thu, 19 Dec 2024 23:54:33 +0800 Subject: [PATCH] clear --- src-apps/demo/index.ts | 130 ------------------------------------- src-apps/favorite/index.ts | 129 ------------------------------------ tsconfig.json | 5 +- 3 files changed, 1 insertion(+), 263 deletions(-) delete mode 100644 src-apps/demo/index.ts delete mode 100644 src-apps/favorite/index.ts diff --git a/src-apps/demo/index.ts b/src-apps/demo/index.ts deleted file mode 100644 index ef608a1..0000000 --- a/src-apps/demo/index.ts +++ /dev/null @@ -1,130 +0,0 @@ -import type { App, RouteContext } from '@kevisual/router'; -import { DataTypes, Model } from 'sequelize'; - -type AppContext = { - import: any; - sequelize: any; -}; -type Ctx = RouteContext; - -class AppModel extends Model { - declare id: string; - declare title: string; - declare description: string; - declare cover: string; - declare url: string; - declare share: boolean; - declare tags: string[]; - declare uid: string; - declare username: string; -} -export const getModel = async (ctx: Ctx) => { - const sequelize = ctx.sequelize; - if (!sequelize) { - ctx.throw?.('sequelize instance not found'); - } - AppModel.init( - { - id: { - type: DataTypes.UUID, - primaryKey: true, - defaultValue: DataTypes.UUIDV4, - }, - cover: { - type: DataTypes.TEXT, - allowNull: true, - defaultValue: '', - }, - title: { - type: DataTypes.TEXT, - allowNull: false, - defaultValue: '', - }, - description: { - type: DataTypes.TEXT, - allowNull: true, - }, - url: { - type: DataTypes.TEXT, - allowNull: false, - }, - share: { - type: DataTypes.BOOLEAN, - defaultValue: false, - }, - tags: { - type: DataTypes.JSONB, - defaultValue: [], - }, - uid: { - type: DataTypes.UUID, - allowNull: false, - }, - username: { - type: DataTypes.TEXT, - allowNull: false, - defaultValue: '', - }, - }, - { - sequelize, - modelName: 'apps_demo', - }, - ); - return AppModel; -}; -/** - * 初始化模型 - * @param ctx - */ -export const initModel = async (ctx: RouteContext) => { - try { - const AppModel = await getModel(ctx); - const res = await AppModel.sync({ alter: true }); - ctx.body = 'success'; - } catch (error) { - console.error(error); - ctx.throw?.(error.message); - } -}; -export const render = (app: App) => { - app - .route({ - path: 'apps-demo', - key: 'init', - middleware: ['auth'], - }) - .define(initModel) - .addTo(app); - - app - .route({ - path: 'apps-demo', - key: 'list', - }) - .define(async (ctx) => { - const AppModel = await getModel(ctx); - const res = await AppModel.findAll(); - ctx.body = res; - }) - .addTo(app); - - app - .route({ - path: 'apps-demo', - key: 'delete', - }) - .define(async (ctx) => { - ctx.body = 'success'; - }) - .addTo(app); - app - .route({ - path: 'apps-demo', - key: 'update', - }) - .define(async (ctx) => { - ctx.body = 'update success'; - }) - .addTo(app); -}; diff --git a/src-apps/favorite/index.ts b/src-apps/favorite/index.ts deleted file mode 100644 index 0f11e73..0000000 --- a/src-apps/favorite/index.ts +++ /dev/null @@ -1,129 +0,0 @@ -import type { App, RouteContext } from '@kevisual/router'; -import { DataTypes, Model } from 'sequelize'; - -type AppContext = { - import: any; - sequelize: any; -}; -type Ctx = RouteContext; - -class Favorite extends Model { - declare id: string; - declare title: string; - declare description: string; - declare cover: string; - declare url: string; - declare share: boolean; - declare tags: string[]; - declare uid: string; - declare username: string; -} -export const getModel = async (ctx: Ctx) => { - const sequelize = ctx.sequelize; - if (!sequelize) { - ctx.throw?.('sequelize instance not found'); - } - Favorite.init( - { - id: { - type: DataTypes.UUID, - primaryKey: true, - defaultValue: DataTypes.UUIDV4, - }, - cover: { - type: DataTypes.TEXT, - allowNull: true, - defaultValue: '', - }, - title: { - type: DataTypes.TEXT, - allowNull: false, - defaultValue: '', - }, - description: { - type: DataTypes.TEXT, - allowNull: true, - }, - url: { - type: DataTypes.TEXT, - allowNull: false, - }, - share: { - type: DataTypes.BOOLEAN, - defaultValue: false, - }, - tags: { - type: DataTypes.JSONB, - defaultValue: [], - }, - uid: { - type: DataTypes.UUID, - allowNull: false, - }, - username: { - type: DataTypes.TEXT, - allowNull: false, - defaultValue: '', - }, - }, - { - sequelize, - modelName: 'apps_favorite', - }, - ); - return Favorite; -}; -/** - * 初始化模型 - * @param ctx - */ -export const initModel = async (ctx: RouteContext) => { - try { - const Favorite = await getModel(ctx); - const res = await Favorite.sync({ alter: true }); - ctx.body = 'success'; - } catch (error) { - console.error(error); - ctx.throw?.(error.message); - } -}; -export const render = (app: App) => { - app - .route({ - path: 'nav', - key: 'init', - middleware: ['auth'], - }) - .define(initModel) - .addTo(app); - - app - .route({ - path: 'nav', - key: 'list', - }) - .define(async (ctx) => { - const Favorite = await getModel(ctx); - const res = await Favorite.findAll(); - ctx.body = res; - }) - .addTo(app); - - app - .route({ - path: 'nav', - key: 'delete', - }) - .define(async (ctx) => { - ctx.body = 'success'; - }) - .addTo(app); - app - .route({ - path: 'nav', - key: 'update', - }) - .define(async (ctx) => { - ctx.body = 'update success'; - }).addTo(app); -}; diff --git a/tsconfig.json b/tsconfig.json index 3adba37..f1e1324 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "baseUrl": "./", "typeRoots": [ "node_modules/@types", - "src/@types" + "node_modules/@kevisual/type" ], "declaration": true, "noEmit": false, @@ -23,9 +23,6 @@ "paths": { "@/*": [ "src/*" - ], - "*": [ - "types/*" ] } },