Files
pos-system/services/iam-service/src/modules/session/session.repository.ts
Ho Ngoc Hai 8cc2f66df6 Update IAM Service with various enhancements and fixes
- Added `xmlchars` dependency to `pnpm-lock.yaml` for improved XML character handling.
- Updated IAM Service audit plan to streamline post-deployment monitoring tasks.
- Enhanced Dockerfile to prune development dependencies after build for a leaner production image.
- Introduced a new encryption key configuration in the environment example for better security practices.
- Refactored multiple service files to improve import organization and maintainability.
- Improved error handling in seed scripts to provide more detailed logging on failures.
- Updated various controllers and services to ensure consistent import statements and enhance readability.

These changes aim to improve the overall functionality, security, and maintainability of the IAM Service.
2026-01-02 16:13:36 +07:00

41 lines
981 B
TypeScript

import { getPrismaClient } from '../../config/database.config';
import { BaseRepository } from '../common/repository';
/**
* EN: Session repository
* VI: Repository session
*/
export class SessionRepository extends BaseRepository<any, any, any> {
constructor() {
super(getPrismaClient(), 'session');
}
/**
* EN: Find active sessions for user
* VI: Tìm sessions đang hoạt động của người dùng
*/
async findActiveSessions(userId: string): Promise<any[]> {
return this.prisma.session.findMany({
where: {
userId,
isActive: true,
expiresAt: { gt: new Date() },
},
orderBy: { lastActivityAt: 'desc' },
});
}
/**
* EN: Clean expired sessions
* VI: Dọn dẹp sessions hết hạn
*/
async cleanExpired(): Promise<number> {
const result = await this.prisma.session.deleteMany({
where: {
expiresAt: { lt: new Date() },
},
});
return result.count;
}
}