feat: add admin router manager
This commit is contained in:
55
src/models/code.ts
Normal file
55
src/models/code.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { sequelize } from '../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
export type RouterCode = {
|
||||
id: string;
|
||||
path: string;
|
||||
key: string;
|
||||
active: boolean;
|
||||
project: string;
|
||||
code: string;
|
||||
};
|
||||
|
||||
export class RouterCodeModel extends Model {
|
||||
declare id: string;
|
||||
path: string;
|
||||
key: string;
|
||||
active: boolean;
|
||||
project: string;
|
||||
public code: string;
|
||||
}
|
||||
RouterCodeModel.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
comment: '用户id',
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
key: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
project: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: 'default',
|
||||
},
|
||||
code: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'cf_router_code',
|
||||
},
|
||||
);
|
||||
// RouterCodeModel.sync({ alter: true });
|
||||
63
src/models/user.ts
Normal file
63
src/models/user.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { sequelize } from '@/modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
export class User extends Model {
|
||||
declare id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
salt: string;
|
||||
remark: string;
|
||||
}
|
||||
User.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
salt: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
remark: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'cf_user',
|
||||
},
|
||||
);
|
||||
// User.sync({ alter: true });
|
||||
|
||||
export const initializeUser = async () => {
|
||||
const w = await User.findOne();
|
||||
const password = '2e8a305521bba54f49638ed25e46adf3';
|
||||
const salt = '123';
|
||||
const users = [
|
||||
{ username: 'admin' },
|
||||
{ username: 'user' },
|
||||
{ username: 'root' },
|
||||
];
|
||||
if (!w) {
|
||||
const newUsers = await User.bulkCreate(
|
||||
users.map((user) => {
|
||||
return {
|
||||
...user,
|
||||
password,
|
||||
salt,
|
||||
};
|
||||
}),
|
||||
);
|
||||
console.info('[create new Users]', newUsers);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user