refactor(backend): 将ApiUser模型重命名为Admin并更新相关引用
This commit is contained in:
@@ -5,7 +5,7 @@ const Joi = require('joi')
|
||||
const router = express.Router()
|
||||
|
||||
// 引入数据库模型
|
||||
const { ApiUser } = require('../models')
|
||||
const { Admin } = require('../models')
|
||||
|
||||
// 引入认证中间件
|
||||
const { authenticateJWT } = require('../middleware/auth')
|
||||
@@ -118,9 +118,9 @@ router.post('/login', async (req, res) => {
|
||||
const { username, password } = value
|
||||
|
||||
// 查找用户
|
||||
const user = await ApiUser.findOne({
|
||||
const user = await Admin.findOne({
|
||||
where: {
|
||||
[ApiUser.sequelize.Op.or]: [
|
||||
[Admin.sequelize.Op.or]: [
|
||||
{ username },
|
||||
{ email: username }
|
||||
]
|
||||
@@ -218,7 +218,7 @@ router.get('/me', authenticateJWT, async (req, res) => {
|
||||
const userId = req.user.id
|
||||
|
||||
// 根据ID查找用户
|
||||
const user = await ApiUser.findByPk(userId, {
|
||||
const user = await Admin.findByPk(userId, {
|
||||
attributes: {
|
||||
exclude: ['password_hash'] // 排除密码哈希等敏感信息
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const Joi = require('joi')
|
||||
const router = express.Router()
|
||||
|
||||
// 引入数据库模型
|
||||
const { ApiUser } = require('../models')
|
||||
const { Admin } = require('../models')
|
||||
const sequelize = require('sequelize')
|
||||
|
||||
/**
|
||||
@@ -195,7 +195,7 @@ router.get('/', async (req, res) => {
|
||||
if (status) where.status = status
|
||||
|
||||
// 分页查询
|
||||
const result = await ApiUser.findAndCountAll({
|
||||
const result = await Admin.findAndCountAll({
|
||||
where,
|
||||
limit: parseInt(pageSize),
|
||||
offset: (parseInt(page) - 1) * parseInt(pageSize),
|
||||
@@ -260,7 +260,7 @@ router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params
|
||||
|
||||
const user = await ApiUser.findByPk(id)
|
||||
const user = await Admin.findByPk(id)
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
@@ -332,7 +332,7 @@ router.post('/', async (req, res) => {
|
||||
const { username, email, phone, password, user_type, status } = value
|
||||
|
||||
// 检查用户名、邮箱是否已存在
|
||||
const existingUser = await ApiUser.findOne({
|
||||
const existingUser = await Admin.findOne({
|
||||
where: {
|
||||
[sequelize.Op.or]: [
|
||||
{ username },
|
||||
@@ -352,7 +352,7 @@ router.post('/', async (req, res) => {
|
||||
const hashedPassword = await bcrypt.hash(password, 10)
|
||||
|
||||
// 创建用户
|
||||
const user = await ApiUser.create({
|
||||
const user = await Admin.create({
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
@@ -438,7 +438,7 @@ router.put('/:id', async (req, res) => {
|
||||
}
|
||||
|
||||
// 查找用户
|
||||
const user = await ApiUser.findByPk(id)
|
||||
const user = await Admin.findByPk(id)
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
@@ -503,7 +503,7 @@ router.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params
|
||||
|
||||
const user = await ApiUser.findByPk(id)
|
||||
const user = await Admin.findByPk(id)
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
|
||||
Reference in New Issue
Block a user