2021-05-25 18:12:42 +02:00
|
|
|
/* eslint-disable max-classes-per-file */
|
2022-06-25 13:48:25 +00:00
|
|
|
import { Repository, SelectQueryBuilder } from "typeorm";
|
|
|
|
|
import { EntityRepository } from "../database/entity-repository";
|
2020-09-05 23:35:53 +02:00
|
|
|
import { User } from "../users/user.entity";
|
|
|
|
|
import { AuthSession } from "./auth-session.entity";
|
|
|
|
|
|
|
|
|
|
export class AuthSessionScopes extends SelectQueryBuilder<AuthSession> {
|
|
|
|
|
/**
|
|
|
|
|
* `byUser` scopes the query to AuthSessions created by the user.
|
|
|
|
|
* @param currentUser
|
|
|
|
|
*/
|
|
|
|
|
byUser(currentUser: User): this {
|
|
|
|
|
return this.andWhere(`session."userId" = :userID`, {
|
|
|
|
|
userID: currentUser.id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EntityRepository(AuthSession)
|
|
|
|
|
export class AuthSessionRepository extends Repository<AuthSession> {
|
|
|
|
|
get scoped(): AuthSessionScopes {
|
|
|
|
|
return new AuthSessionScopes(this.createQueryBuilder("session"));
|
|
|
|
|
}
|
|
|
|
|
}
|