mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { Equals, IsInt, IsPositive, IsString } from 'class-validator';
|
|
import { Session } from 'src/database';
|
|
import { Optional, ValidateBoolean } 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 SessionUpdateDto {
|
|
@ValidateBoolean({ optional: true })
|
|
@Equals(true)
|
|
isPendingSyncReset?: true;
|
|
}
|
|
|
|
export class SessionResponseDto {
|
|
id!: string;
|
|
createdAt!: string;
|
|
updatedAt!: string;
|
|
expiresAt?: string;
|
|
current!: boolean;
|
|
deviceType!: string;
|
|
deviceOS!: string;
|
|
appVersion!: string | null;
|
|
isPendingSyncReset!: boolean;
|
|
}
|
|
|
|
export class SessionCreateResponseDto extends SessionResponseDto {
|
|
token!: string;
|
|
}
|
|
|
|
export const mapSession = (entity: Session, currentId?: string): SessionResponseDto => ({
|
|
id: entity.id,
|
|
createdAt: entity.createdAt.toISOString(),
|
|
updatedAt: entity.updatedAt.toISOString(),
|
|
expiresAt: entity.expiresAt?.toISOString(),
|
|
current: currentId === entity.id,
|
|
appVersion: entity.appVersion,
|
|
deviceOS: entity.deviceOS,
|
|
deviceType: entity.deviceType,
|
|
isPendingSyncReset: entity.isPendingSyncReset,
|
|
});
|