feat: 鏍囬鏍忕増鏈彿 + 搴旂敤甯傚満涓婃灦鏃ュ巻搴旂敤涓庡垎缁勬姌鍙?+ 鏃ョ▼鍐滃巻/琛ㄥ崟妯増浼樺寲 + 涓汉璧勬枡寮圭獥
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Patch, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||
import { CurrentUser } from './current-user.decorator';
|
||||
@@ -24,6 +24,15 @@ export class AuthController {
|
||||
return user;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch('me')
|
||||
updateMe(
|
||||
@CurrentUser() user: PublicUser,
|
||||
@Body() dto: { signature?: string; status?: string },
|
||||
) {
|
||||
return this.auth.updateProfile(user.id, dto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('logout')
|
||||
logout(@Req() _req: any) {
|
||||
|
||||
@@ -17,6 +17,10 @@ export interface User {
|
||||
email?: string;
|
||||
department?: string;
|
||||
title?: string;
|
||||
/** 个人签名 */
|
||||
signature?: string;
|
||||
/** 自定义状态:上班/外出/出差/请假/学习/休假 等 */
|
||||
status?: string;
|
||||
createdAt: number;
|
||||
}
|
||||
|
||||
@@ -86,6 +90,16 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 更新个人资料(签名、自定义状态等) */
|
||||
async updateProfile(
|
||||
userId: string,
|
||||
patch: { signature?: string; status?: string },
|
||||
) {
|
||||
const user = await this.users().updateById(userId, patch);
|
||||
if (!user) throw new BadRequestException('用户不存在');
|
||||
return this.toPublic(user);
|
||||
}
|
||||
|
||||
toPublic(user: User): PublicUser {
|
||||
const { passwordHash, ...rest } = user;
|
||||
return rest;
|
||||
|
||||
Reference in New Issue
Block a user