2025-08-05 21:30:19 +01:00
|
|
|
import { Equals, IsInt, IsPositive, IsString } from 'class-validator';
|
2025-04-09 10:24:38 -04:00
|
|
|
import { Session } from 'src/database';
|
2025-07-11 09:38:02 -04:00
|
|
|
import { Optional, ValidateBoolean } from 'src/validation';
|
2025-05-15 13:34:33 -05:00
|
|
|
|
|
|
|
|
export class SessionCreateDto {
|
|
|
|
|
/**
|
|
|
|
|
* session duration, in seconds
|
|
|
|
|
*/
|
|
|
|
|
@IsInt()
|
|
|
|
|
@IsPositive()
|
|
|
|
|
@Optional()
|
|
|
|
|
duration?: number;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@Optional()
|
|
|
|
|
deviceType?: string;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@Optional()
|
|
|
|
|
deviceOS?: string;
|
|
|
|
|
}
|
2024-04-19 06:47:29 -04:00
|
|
|
|
2025-07-11 09:38:02 -04:00
|
|
|
export class SessionUpdateDto {
|
|
|
|
|
@ValidateBoolean({ optional: true })
|
2025-08-05 21:30:19 +01:00
|
|
|
@Equals(true)
|
|
|
|
|
isPendingSyncReset?: true;
|
2025-07-11 09:38:02 -04:00
|
|
|
}
|
|
|
|
|
|
2024-04-19 06:47:29 -04:00
|
|
|
export class SessionResponseDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
createdAt!: string;
|
|
|
|
|
updatedAt!: string;
|
2025-05-15 18:08:31 -04:00
|
|
|
expiresAt?: string;
|
2024-04-19 06:47:29 -04:00
|
|
|
current!: boolean;
|
|
|
|
|
deviceType!: string;
|
|
|
|
|
deviceOS!: string;
|
2025-10-22 01:36:18 +03:00
|
|
|
appVersion!: string | null;
|
2025-07-11 09:38:02 -04:00
|
|
|
isPendingSyncReset!: boolean;
|
2024-04-19 06:47:29 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-15 13:34:33 -05:00
|
|
|
export class SessionCreateResponseDto extends SessionResponseDto {
|
|
|
|
|
token!: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-09 10:24:38 -04:00
|
|
|
export const mapSession = (entity: Session, currentId?: string): SessionResponseDto => ({
|
2024-04-19 06:47:29 -04:00
|
|
|
id: entity.id,
|
|
|
|
|
createdAt: entity.createdAt.toISOString(),
|
|
|
|
|
updatedAt: entity.updatedAt.toISOString(),
|
2025-05-15 18:08:31 -04:00
|
|
|
expiresAt: entity.expiresAt?.toISOString(),
|
2024-04-19 06:47:29 -04:00
|
|
|
current: currentId === entity.id,
|
2025-10-22 01:36:18 +03:00
|
|
|
appVersion: entity.appVersion,
|
2024-04-19 06:47:29 -04:00
|
|
|
deviceOS: entity.deviceOS,
|
|
|
|
|
deviceType: entity.deviceType,
|
2025-07-11 09:38:02 -04:00
|
|
|
isPendingSyncReset: entity.isPendingSyncReset,
|
2024-04-19 06:47:29 -04:00
|
|
|
});
|