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

export const AuthSessionRepository = db.getRepository(AuthSession).extend({
	async pack(
		src: AuthSession['id'] | AuthSession,
		me?: { id: User['id'] } | null | undefined
	) {
		const session = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });

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