fix: created_by 注入 + 登出审计记录真实 username

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
liuyun 2026-10-11 16:43:31 +08:00
parent 6553b4c5c7
commit 5c1f2992b5
2 changed files with 6 additions and 2 deletions

View File

@ -223,10 +223,11 @@ export class AuthService {
data: { revokedAt: new Date() }, data: { revokedAt: new Date() },
}); });
await this.redis.del(this.permKey(record.tenantCode, record.userId)); await this.redis.del(this.permKey(record.tenantCode, record.userId));
const user = await this.prisma.client.user.findUnique({ where: { id: record.userId } });
await this.recordAudit({ await this.recordAudit({
tenantCode: record.tenantCode, tenantCode: record.tenantCode,
userId: record.userId, userId: record.userId,
username: null, username: user?.username ?? null,
module: 'auth', module: 'auth',
action: 'logout', action: 'logout',
status: 'success', status: 'success',

View File

@ -53,7 +53,10 @@ export class BaseCrudService {
async create(data: Record<string, unknown>) { async create(data: Record<string, unknown>) {
const ctx = getRequestContext(); const ctx = getRequestContext();
if (ctx && this.modelName !== 'tenant') data.tenantCode = ctx.tenantCode; if (ctx && this.modelName !== 'tenant') {
data.tenantCode = ctx.tenantCode;
data.createdBy = ctx.userId;
}
return this.db().create({ data }); return this.db().create({ data });
} }