import { dataSource } from "../data-source"; import { refresh } from "../entity/refresh"; import InternalException from "../exceptions/internalException"; export default abstract class RefreshService { /** * @description get refresh by token * @param token string * @returns {Promise} */ static async getByToken(token: string): Promise { return await dataSource .getRepository(refresh) .createQueryBuilder("refresh") .leftJoinAndSelect("refresh.user", "user") .where("refresh.token = :token", { token: token }) .andWhere("refresh.expiry >= :expiry", { expiry: new Date() }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("refresh not found"); }); } }