bump
This commit is contained in:
@@ -21,27 +21,52 @@ export class SessionsRepository {
|
||||
return this.repo.find({ where: { userId }, order: { createdAt: 'DESC' } });
|
||||
}
|
||||
|
||||
listActiveForUser(userId: string): Promise<SessionEntity[]> {
|
||||
return this.repo.find({
|
||||
where: { userId, revokedAt: IsNull() },
|
||||
order: { lastActivityAt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
countActiveForUser(userId: string): Promise<number> {
|
||||
return this.repo.count({ where: { userId, revokedAt: IsNull() } });
|
||||
}
|
||||
|
||||
save(session: SessionEntity): Promise<SessionEntity> {
|
||||
return this.repo.save(session);
|
||||
}
|
||||
|
||||
async revoke(sessionId: string): Promise<void> {
|
||||
await this.repo.update({ id: sessionId }, { revokedAt: new Date() });
|
||||
async revoke(sessionId: string): Promise<number> {
|
||||
const result = await this.repo.update(
|
||||
{ id: sessionId, revokedAt: IsNull() },
|
||||
{ revokedAt: new Date() },
|
||||
);
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
async revokeForUser(userId: string, sessionId: string): Promise<number> {
|
||||
const result = await this.repo.update(
|
||||
{ id: sessionId, userId, revokedAt: IsNull() },
|
||||
{ revokedAt: new Date() },
|
||||
);
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
async revokeAllForUser(
|
||||
userId: string,
|
||||
exceptSessionId?: string,
|
||||
): Promise<void> {
|
||||
): Promise<number> {
|
||||
const sessions = await this.repo.find({
|
||||
where: { userId, revokedAt: IsNull() },
|
||||
});
|
||||
const now = new Date();
|
||||
await this.repo.save(
|
||||
sessions
|
||||
.filter((session) => session.id !== exceptSessionId)
|
||||
.map((session) => ({ ...session, revokedAt: now })),
|
||||
const targets = sessions.filter(
|
||||
(session) => session.id !== exceptSessionId,
|
||||
);
|
||||
await this.repo.save(
|
||||
targets.map((session) => ({ ...session, revokedAt: now })),
|
||||
);
|
||||
return targets.length;
|
||||
}
|
||||
|
||||
async cleanupExpired(now = new Date()): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user