refactor: 调整userSession服务及实体至Auth模块下

This commit is contained in:
2025-12-18 12:16:09 +08:00
parent d6bf4d3cb3
commit 77b7bf8ab2
8 changed files with 17 additions and 16 deletions

View File

@@ -0,0 +1,39 @@
import { InjectRepository } from '@nestjs/typeorm';
import { Injectable } from '@nestjs/common';
import { UserSession } from '../entity/user-session.entity';
import { Repository } from 'typeorm';
@Injectable()
export class UserSessionService {
constructor(
@InjectRepository(UserSession)
private readonly userSessionRepository: Repository<UserSession>,
) { }
async createSession(userId: string): Promise<UserSession> {
const session = this.userSessionRepository.create({
userId,
});
return this.userSessionRepository.save(session);
}
async getSession(sessionId: string) {
const session = await this.userSessionRepository.findOne({
where: {
sessionId,
},
});
return session;
}
async invalidateSession(sessionId: string, reason?: string): Promise<void> {
await this.userSessionRepository.update(
{ sessionId, deletedAt: null },
{
deletedAt: new Date(),
disabledReason: reason || null,
}
)
}
}