ff-admin-server/src/service/refreshService.ts

27 lines
820 B
TypeScript
Raw Normal View History

2024-08-23 12:42:47 +00:00
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<refresh>}
*/
static async getByToken(token: string): Promise<refresh> {
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) => {
2024-09-06 08:08:19 +00:00
throw new InternalException("refresh not found", err);
2024-08-23 12:42:47 +00:00
});
}
}