Files
immich/server/src/dtos/session.dto.ts

46 lines
1008 B
TypeScript
Raw Normal View History

import { IsInt, IsPositive, IsString } from 'class-validator';
2025-04-09 10:24:38 -04:00
import { Session } from 'src/database';
import { Optional } from 'src/validation';
export class SessionCreateDto {
/**
* session duration, in seconds
*/
@IsInt()
@IsPositive()
@Optional()
duration?: number;
@IsString()
@Optional()
deviceType?: string;
@IsString()
@Optional()
deviceOS?: string;
}
export class SessionResponseDto {
id!: string;
createdAt!: string;
updatedAt!: string;
2025-05-15 18:08:31 -04:00
expiresAt?: string;
current!: boolean;
deviceType!: string;
deviceOS!: string;
}
export class SessionCreateResponseDto extends SessionResponseDto {
token!: string;
}
2025-04-09 10:24:38 -04:00
export const mapSession = (entity: Session, currentId?: string): SessionResponseDto => ({
id: entity.id,
createdAt: entity.createdAt.toISOString(),
updatedAt: entity.updatedAt.toISOString(),
2025-05-15 18:08:31 -04:00
expiresAt: entity.expiresAt?.toISOString(),
current: currentId === entity.id,
deviceOS: entity.deviceOS,
deviceType: entity.deviceType,
});