summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/repositories/auth-session.ts
blob: c8f4c10f2a8681c6d5ea80b22b61f23e923ff8d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { EntityRepository, Repository } from 'typeorm';
import { Apps } from '../index';
import { AuthSession } from '@/models/entities/auth-session';
import { awaitAll } from '@/prelude/await-all';
import { User } from '@/models/entities/user';

@EntityRepository(AuthSession)
export class AuthSessionRepository extends Repository<AuthSession> {
	public async pack(
		src: AuthSession['id'] | AuthSession,
		me?: { id: User['id'] } | null | undefined
	) {
		const session = typeof src === 'object' ? src : await this.findOneOrFail(src);

		return await awaitAll({
			id: session.id,
			app: Apps.pack(session.appId, me),
			token: session.token
		});
	}
}