mirror of
https://github.com/immich-app/immich.git
synced 2025-11-26 00:20:47 +09:00
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { ExpressionBuilder } from 'kysely';
|
|
import { DB } from 'src/db';
|
|
import { UserEntity } from 'src/entities/user.entity';
|
|
|
|
export class SessionEntity {
|
|
id!: string;
|
|
token!: string;
|
|
userId!: string;
|
|
user!: UserEntity;
|
|
createdAt!: Date;
|
|
updatedAt!: Date;
|
|
updateId!: string;
|
|
deviceType!: string;
|
|
deviceOS!: string;
|
|
}
|
|
|
|
const userColumns = [
|
|
'id',
|
|
'email',
|
|
'createdAt',
|
|
'profileImagePath',
|
|
'isAdmin',
|
|
'shouldChangePassword',
|
|
'deletedAt',
|
|
'oauthId',
|
|
'updatedAt',
|
|
'storageLabel',
|
|
'name',
|
|
'quotaSizeInBytes',
|
|
'quotaUsageInBytes',
|
|
'status',
|
|
'profileChangedAt',
|
|
] as const;
|
|
|
|
export const withUser = (eb: ExpressionBuilder<DB, 'sessions'>) => {
|
|
return eb
|
|
.selectFrom('users')
|
|
.select(userColumns)
|
|
.select((eb) =>
|
|
eb
|
|
.selectFrom('user_metadata')
|
|
.whereRef('users.id', '=', 'user_metadata.userId')
|
|
.select((eb) => eb.fn('array_agg', [eb.table('user_metadata')]).as('metadata'))
|
|
.as('metadata'),
|
|
)
|
|
.whereRef('users.id', '=', 'sessions.userId')
|
|
.where('users.deletedAt', 'is', null)
|
|
.as('user');
|
|
};
|