Files
zhiyin/backend/src/modules/positions/positions.controller.ts
T
yuzhiran 37cfdfe93c feat: 登录页密码+验证码双模式 / 首页岗位优化 / 法律页面 / 后端接口完善
- 前端:登录页重构,支持密码登录、验证码登录、注册三种模式
- 前端:首页热门岗位添加「参考示例」标签,去虚构数据
- 前端:面试页顶部优化,岗位名+状态标签展示
- 前端:新增用户协议、隐私政策页面及免责声明
- 后端:新增 POST /api/user/register 注册接口
- 后端:新增 POST /api/user/set-password 设置密码接口
- 后端:修复 user.schema.ts unique 索引导致 null 冲突问题
- 后端:新增 payment-order.schema、positions.schema、site-config.schema
- 后端:package.json 新增 postbuild 脚本自动复制证书
- 管理后台:新增订单管理 Tab
2026-06-09 15:39:17 +08:00

55 lines
2.2 KiB
TypeScript

import { Controller, Get, Body, Post, Delete, Param, UseGuards, HttpException, HttpStatus } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model } from 'mongoose'
import { HotPosition, HotPositionDocument } from './positions.schema'
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
import { Public } from '../../common/decorators/public.decorator'
import { CurrentUser } from '../../common/decorators/current-user.decorator'
import { User, UserDocument } from '../user/user.schema'
@Controller('positions')
export class PositionsController {
constructor(
@InjectModel(HotPosition.name) private positionModel: Model<HotPositionDocument>,
@InjectModel(User.name) private userModel: Model<UserDocument>,
) {}
@Public()
@Get('hot')
async hot() {
return this.positionModel.find({ active: true }).sort({ sort: 1 }).lean().exec()
}
// ─── 管理后台 CRUD ──────────────────────
@UseGuards(JwtAuthGuard)
@Post('admin/list')
async adminList(@CurrentUser('userId') adminUserId: string) {
const admin = await this.userModel.findById(adminUserId).exec()
if (admin?.role !== 'admin') throw new HttpException('无权限', HttpStatus.FORBIDDEN)
return this.positionModel.find().sort({ sort: 1 }).lean().exec()
}
@UseGuards(JwtAuthGuard)
@Post('admin/save')
async save(@Body() body: HotPosition & { _id?: string }, @CurrentUser('userId') adminUserId: string) {
const admin = await this.userModel.findById(adminUserId).exec()
if (admin?.role !== 'admin') throw new HttpException('无权限', HttpStatus.FORBIDDEN)
if (body._id) {
await this.positionModel.findByIdAndUpdate(body._id, body).exec()
return { success: true }
}
const created = await this.positionModel.create(body)
return { success: true, id: created._id }
}
@UseGuards(JwtAuthGuard)
@Delete('admin/:id')
async remove(@Param('id') id: string, @CurrentUser('userId') adminUserId: string) {
const admin = await this.userModel.findById(adminUserId).exec()
if (admin?.role !== 'admin') throw new HttpException('无权限', HttpStatus.FORBIDDEN)
await this.positionModel.findByIdAndDelete(id).exec()
return { success: true }
}
}