设计接口
This commit is contained in:
parent
b13d584f57
commit
741fde2d1f
@ -10,6 +10,7 @@
|
|||||||
"#config/*": "./config/*.js",
|
"#config/*": "./config/*.js",
|
||||||
"#start": "./src/utils/start.js",
|
"#start": "./src/utils/start.js",
|
||||||
"#plugins/*": "./src/plugins/*.js",
|
"#plugins/*": "./src/plugins/*.js",
|
||||||
|
"#routes/*": "./src/routes/*.js",
|
||||||
"#src/*": "./src/*.js"
|
"#src/*": "./src/*.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -1,17 +1,242 @@
|
|||||||
/**
|
import { mysqlTable, mysqlSchema, AnyMySqlColumn, primaryKey, unique, bigint, int, tinyint, varchar, datetime } from "drizzle-orm/mysql-core"
|
||||||
* @typedef {import('drizzle-orm/mysql-core').MySqlTable} MySqlTable
|
import { sql } from "drizzle-orm"
|
||||||
* @typedef {import('drizzle-orm/mysql-core').varchar} varchar
|
|
||||||
* @typedef {import('drizzle-orm/mysql-core').int} int
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { mysqlTable, varchar, int } from 'drizzle-orm/mysql-core';
|
export const sysDict = mysqlTable("sys_dict", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
pid: bigint({ mode: "number" }).notNull(),
|
||||||
|
module: tinyint(),
|
||||||
|
dictKey: varchar("dict_key", { length: 255 }),
|
||||||
|
value: varchar({ length: 255 }),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
sort: int().default(0).notNull(),
|
||||||
|
status: int().notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_dict_id"}),
|
||||||
|
unique("uniq_dict_key").on(table.dictKey, table.pid),
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
export const sysOrganization = mysqlTable("sys_organization", {
|
||||||
* 用户模型
|
orgId: bigint("org_id", { mode: "number" }).autoincrement().notNull(),
|
||||||
* @type {MySqlTable}
|
pid: bigint({ mode: "number" }).notNull(),
|
||||||
*/
|
orgName: varchar("org_name", { length: 255 }),
|
||||||
export const users = mysqlTable('users', {
|
orgCode: varchar("org_code", { length: 128 }),
|
||||||
id: int('id').primaryKey(),
|
orgType: int("org_type").notNull(),
|
||||||
name: varchar('name', { length: 255 }),
|
description: varchar({ length: 255 }),
|
||||||
email: varchar('email', { length: 255 }).unique(),
|
sort: int().default(0).notNull(),
|
||||||
});
|
status: int().notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.orgId], name: "sys_organization_org_id"}),
|
||||||
|
unique("uniq_org_code").on(table.orgCode, table.pid),
|
||||||
|
unique("uniq_org_name").on(table.orgName, table.pid),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysOrganizationManager = mysqlTable("sys_organization_manager", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
orgId: bigint("org_id", { mode: "number" }).notNull(),
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
rank: int().notNull(),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_organization_manager_id"}),
|
||||||
|
unique("uniq_org_user").on(table.orgId, table.userId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysPermission = mysqlTable("sys_permission", {
|
||||||
|
permId: bigint("perm_id", { mode: "number" }).autoincrement().notNull(),
|
||||||
|
pid: bigint({ mode: "number" }).notNull(),
|
||||||
|
permName: varchar("perm_name", { length: 255 }).notNull(),
|
||||||
|
permKey: varchar("perm_key", { length: 255 }).notNull(),
|
||||||
|
url: varchar({ length: 255 }),
|
||||||
|
avatarUrl: varchar("avatar_url", { length: 255 }),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
permType: int("perm_type").notNull(),
|
||||||
|
isVisible: int("is_visible").default(0).notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
sort: int().default(0).notNull(),
|
||||||
|
status: int().notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.permId], name: "sys_permission_perm_id"}),
|
||||||
|
unique("uniq_pid_name").on(table.permName, table.pid),
|
||||||
|
unique("uniq_perm_key").on(table.permKey),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysReRolePermission = mysqlTable("sys_re_role_permission", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
roleId: bigint("role_id", { mode: "number" }).notNull(),
|
||||||
|
permId: bigint("perm_id", { mode: "number" }).notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_re_role_permission_id"}),
|
||||||
|
unique("uniq_perm_role").on(table.roleId, table.permId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysReUserOrganization = mysqlTable("sys_re_user_organization", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
orgId: bigint("org_id", { mode: "number" }).notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_re_user_organization_id"}),
|
||||||
|
unique("uniq_user_org").on(table.userId, table.orgId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysReUserRole = mysqlTable("sys_re_user_role", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
roleId: bigint("role_id", { mode: "number" }).notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_re_user_role_id"}),
|
||||||
|
unique("uniq_user_role").on(table.userId, table.roleId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysRole = mysqlTable("sys_role", {
|
||||||
|
roleId: bigint("role_id", { mode: "number" }).autoincrement().notNull(),
|
||||||
|
pid: bigint({ mode: "number" }).notNull(),
|
||||||
|
roleName: varchar("role_name", { length: 255 }).notNull(),
|
||||||
|
roleKey: varchar("role_key", { length: 255 }).notNull(),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
status: int().notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.roleId], name: "sys_role_role_id"}),
|
||||||
|
unique("uniq_role_pid").on(table.roleName, table.pid),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUser = mysqlTable("sys_user", {
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
pid: bigint({ mode: "number" }).notNull(),
|
||||||
|
username: varchar({ length: 255 }).notNull(),
|
||||||
|
email: varchar({ length: 255 }).notNull(),
|
||||||
|
phone: varchar({ length: 255 }),
|
||||||
|
avatarUrl: varchar("avatar_url", { length: 255 }),
|
||||||
|
userType: tinyint("user_type"),
|
||||||
|
status: tinyint().default(0).notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.userId], name: "sys_user_user_id"}),
|
||||||
|
unique("uniq_username").on(table.username),
|
||||||
|
unique("uniq_email").on(table.email),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUserAuth = mysqlTable("sys_user_auth", {
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||||
|
passwordModified: datetime("password_modified", { mode: 'string'}).notNull(),
|
||||||
|
passwordExpire: datetime("password_expire", { mode: 'string'}),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.userId], name: "sys_user_auth_user_id"}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUserAuthHistory = mysqlTable("sys_user_auth_history", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||||
|
modifiedAt: varchar("modified_at", { length: 255 }).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_user_auth_history_id"}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUserFieldDefinition = mysqlTable("sys_user_field_definition", {
|
||||||
|
fieldId: bigint("field_id", { mode: "number" }).autoincrement().notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
fieldName: varchar("field_name", { length: 255 }).notNull(),
|
||||||
|
fieldKey: varchar("field_key", { length: 255 }).notNull(),
|
||||||
|
fieldType: tinyint("field_type").notNull(),
|
||||||
|
dictModule: int("dict_module"),
|
||||||
|
isRequired: tinyint("is_required").default(0).notNull(),
|
||||||
|
limit: int(),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
defaultValue: varchar("default_value", { length: 255 }),
|
||||||
|
defaultOptions: varchar("default_options", { length: 255 }),
|
||||||
|
sort: int().default(0).notNull(),
|
||||||
|
status: int().notNull(),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.fieldId], name: "sys_user_field_definition_field_id"}),
|
||||||
|
unique("uniq_field_name").on(table.fieldName),
|
||||||
|
unique("uniq_field_key").on(table.fieldKey),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUserFieldValue = mysqlTable("sys_user_field_value", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
userId: bigint("user_id", { mode: "number" }).notNull(),
|
||||||
|
fieldId: int("field_id").notNull(),
|
||||||
|
value: varchar({ length: 4096 }),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_user_field_value_id"}),
|
||||||
|
unique("uniq_user_field").on(table.userId, table.fieldId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const sysUserProfile = mysqlTable("sys_user_profile", {
|
||||||
|
id: bigint({ mode: "number" }).autoincrement().notNull(),
|
||||||
|
version: int().default(0).notNull(),
|
||||||
|
name: varchar({ length: 32 }).notNull(),
|
||||||
|
profileKey: varchar("profile_key", { length: 255 }).notNull(),
|
||||||
|
description: varchar({ length: 255 }),
|
||||||
|
content: varchar({ length: 255 }),
|
||||||
|
createdBy: bigint("created_by", { mode: "number" }).notNull(),
|
||||||
|
updatedBy: bigint("updated_by", { mode: "number" }).notNull(),
|
||||||
|
createdAt: datetime("created_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`(CURRENT_TIMESTAMP)`).notNull(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
primaryKey({ columns: [table.id], name: "sys_user_profile_id"}),
|
||||||
|
unique("uniq_name").on(table.name),
|
||||||
|
unique("uniq_profile_key").on(table.profileKey),
|
||||||
|
]);
|
||||||
|
@ -20,6 +20,7 @@ async function swagger(fastify, options) {
|
|||||||
routePrefix: '/docs',
|
routePrefix: '/docs',
|
||||||
});
|
});
|
||||||
fastify.log.warn('Register Swagger complete!');
|
fastify.log.warn('Register Swagger complete!');
|
||||||
|
fastify.log.info(`Swagger documentation available at http://127.0.0.1:${fastify.config.server.port}/docs`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default fastifyPlugin(swagger);
|
export default fastifyPlugin(swagger);
|
@ -1,5 +1,6 @@
|
|||||||
import { testSchema } from "#src/schema/test.schema";
|
import { testSchema } from "#src/schema/test.schema";
|
||||||
import { testService } from "#src/services/test.service";
|
import { testService } from "#src/services/test.service";
|
||||||
|
import userRoute from "#routes/user.route";
|
||||||
|
|
||||||
export default async function routes(fastify, options) {
|
export default async function routes(fastify, options) {
|
||||||
// 定义一个GET请求的路由,路径为根路径
|
// 定义一个GET请求的路由,路径为根路径
|
||||||
@ -8,6 +9,21 @@ export default async function routes(fastify, options) {
|
|||||||
return fastify.config;
|
return fastify.config;
|
||||||
});
|
});
|
||||||
fastify.get('/test', testSchema , testService);
|
fastify.get('/test', testSchema , testService);
|
||||||
|
|
||||||
|
|
||||||
|
// 注册子路由
|
||||||
|
fastify.register(userRoute, { prefix: '/user' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fastify.route({
|
fastify.route({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/login',
|
url: '/login',
|
||||||
@ -48,4 +64,10 @@ export default async function routes(fastify, options) {
|
|||||||
// ...业务逻辑...
|
// ...业务逻辑...
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 输出路由树
|
||||||
|
fastify.ready(() => {
|
||||||
|
fastify.log.info('Routes Registered!');
|
||||||
|
fastify.log.info('\n' + fastify.printRoutes());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
54
src/routes/user.route.js
Normal file
54
src/routes/user.route.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { userDefaultSchema } from "#src/schema/user.schema";
|
||||||
|
import { userDefaultService } from "#src/services/user.service";
|
||||||
|
|
||||||
|
export default async function userRoute(fastify, options) {
|
||||||
|
fastify.get('/', userDefaultSchema, userDefaultService);
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 个人接口
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// 注册
|
||||||
|
fastify.post('/register', userDefaultSchema, userDefaultService);
|
||||||
|
// 登录
|
||||||
|
fastify.post('/login', userDefaultSchema, userDefaultService);
|
||||||
|
// 退出登录
|
||||||
|
fastify.post('/logout', userDefaultSchema, userDefaultService);
|
||||||
|
// 修改密码
|
||||||
|
fastify.post('/changePassword', userDefaultSchema, userDefaultService);
|
||||||
|
// 获取当前用户信息
|
||||||
|
fastify.get('/getUserInfo', userDefaultSchema, userDefaultService);
|
||||||
|
// 修改当前用户信息
|
||||||
|
fastify.post('/updateUserInfo', userDefaultSchema, userDefaultService);
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 管理接口
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 获取用户列表
|
||||||
|
|
||||||
|
// 获取用户详细信息
|
||||||
|
|
||||||
|
// 创建用户
|
||||||
|
|
||||||
|
// 更新用户信息
|
||||||
|
|
||||||
|
// 批量删除用户
|
||||||
|
|
||||||
|
// 批量重置用户密码
|
||||||
|
|
||||||
|
// 批量启用用户
|
||||||
|
|
||||||
|
// 批量禁用用户
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 拓展字段
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 获取拓展字段列表
|
||||||
|
|
||||||
|
|
||||||
|
}
|
3
src/schema/user.schema.js
Normal file
3
src/schema/user.schema.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const userDefaultSchema = {
|
||||||
|
|
||||||
|
}
|
@ -1,35 +1,3 @@
|
|||||||
import { eq } from 'drizzle-orm';
|
export async function userDefaultService() {
|
||||||
import { users } from '#db/schema';
|
return 'user service';
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户服务模块
|
|
||||||
* @param {object} fastify - Fastify实例
|
|
||||||
*/
|
|
||||||
export default async function userService(fastify) {
|
|
||||||
const { db } = fastify;
|
|
||||||
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* 根据ID获取用户
|
|
||||||
* @param {number} userId - 用户ID
|
|
||||||
* @returns {Promise<object>} 用户对象
|
|
||||||
*/
|
|
||||||
async getUserById(userId) {
|
|
||||||
return db
|
|
||||||
.select()
|
|
||||||
.from(users)
|
|
||||||
.where(eq(users.id, userId))
|
|
||||||
.limit(1)
|
|
||||||
.then(res => res[0]);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建新用户
|
|
||||||
* @param {object} userData - 用户数据
|
|
||||||
* @returns {Promise<object>} 创建的用户记录
|
|
||||||
*/
|
|
||||||
async createUser(userData) {
|
|
||||||
return db.insert(users).values(userData).returning();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user