Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): keep full datetime precision from database #10622

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/src/dtos/activity.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type MaybeDuplicate<T> = { duplicate: boolean; value: T };

export class ActivityResponseDto {
id!: string;
createdAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
type!: ReactionType;
user!: UserResponseDto;
assetId!: string | null;
Expand Down
6 changes: 4 additions & 2 deletions server/src/dtos/album.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export class AlbumResponseDto {
ownerId!: string;
albumName!: string;
description!: string;
createdAt!: Date;
updatedAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
albumThumbnailAssetId!: string | null;
shared!: boolean;
albumUsers!: AlbumUserResponseDto[];
Expand Down
7 changes: 5 additions & 2 deletions server/src/dtos/api-key.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { Optional } from 'src/validation';
export class APIKeyCreateDto {
Expand All @@ -21,6 +22,8 @@ export class APIKeyCreateResponseDto {
export class APIKeyResponseDto {
id!: string;
name!: string;
createdAt!: Date;
updatedAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
}
3 changes: 2 additions & 1 deletion server/src/dtos/asset-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class AssetResponseDto extends SanitizedAssetResponseDto {
originalFileName!: string;
fileCreatedAt!: Date;
fileModifiedAt!: Date;
updatedAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
isFavorite!: boolean;
isArchived!: boolean;
isTrashed!: boolean;
Expand Down
6 changes: 3 additions & 3 deletions server/src/dtos/audit.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Type } from 'class-transformer';
import { IsArray, IsEnum, IsString, IsUUID, ValidateNested } from 'class-validator';
import { EntityType } from 'src/entities/audit.entity';
import { AssetPathType, PathType, PersonPathType, UserPathType } from 'src/entities/move.entity';
import { Optional, ValidateDate, ValidateUUID } from 'src/validation';
import { Optional, ValidateUUID } from 'src/validation';

const PathEnum = Object.values({ ...AssetPathType, ...PersonPathType, ...UserPathType });

export class AuditDeletesDto {
@ValidateDate()
after!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
after!: string;

@ApiProperty({ enum: EntityType, enumName: 'EntityType' })
@IsEnum(EntityType)
Expand Down
6 changes: 4 additions & 2 deletions server/src/dtos/library.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ export class LibraryResponseDto {

exclusionPatterns!: string[];

createdAt!: Date;
updatedAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
refreshedAt!: Date | null;
}

Expand Down
9 changes: 6 additions & 3 deletions server/src/dtos/memory.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ export class MemoryCreateDto extends MemoryBaseDto {

export class MemoryResponseDto {
id!: string;
createdAt!: Date;
updatedAt!: Date;
deletedAt?: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
deletedAt?: string;
memoryAt!: Date;
seenAt?: Date;
ownerId!: string;
Expand Down
4 changes: 2 additions & 2 deletions server/src/dtos/session.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class SessionResponseDto {

export const mapSession = (entity: SessionEntity, currentId?: string): SessionResponseDto => ({
id: entity.id,
createdAt: entity.createdAt.toISOString(),
updatedAt: entity.updatedAt.toISOString(),
createdAt: entity.createdAt,
updatedAt: entity.updatedAt,
current: currentId === entity.id,
deviceOS: entity.deviceOS,
deviceType: entity.deviceType,
Expand Down
3 changes: 2 additions & 1 deletion server/src/dtos/shared-link.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export class SharedLinkResponseDto {

@ApiProperty({ enumName: 'SharedLinkType', enum: SharedLinkType })
type!: SharedLinkType;
createdAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
expiresAt!: Date | null;
assets!: AssetResponseDto[];
album?: AlbumResponseDto;
Expand Down
10 changes: 5 additions & 5 deletions server/src/dtos/sync.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsInt, IsPositive } from 'class-validator';
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
import { ValidateDate, ValidateUUID } from 'src/validation';
import { ValidateUUID } from 'src/validation';

export class AssetFullSyncDto {
@ValidateUUID({ optional: true })
lastId?: string;

@ValidateDate()
updatedUntil!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedUntil!: string;

@IsInt()
@IsPositive()
Expand All @@ -20,8 +20,8 @@ export class AssetFullSyncDto {
}

export class AssetDeltaSyncDto {
@ValidateDate()
updatedAfter!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAfter!: string;

@ValidateUUID({ each: true })
userIds!: string[];
Expand Down
9 changes: 6 additions & 3 deletions server/src/dtos/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ export class UserAdminResponseDto extends UserResponseDto {
storageLabel!: string | null;
shouldChangePassword!: boolean;
isAdmin!: boolean;
createdAt!: Date;
deletedAt!: Date | null;
updatedAt!: Date;
@ApiProperty({ type: 'string', format: 'date-time' })
createdAt!: string;
@ApiProperty({ type: 'string', format: 'date-time' })
deletedAt!: string | null;
@ApiProperty({ type: 'string', format: 'date-time' })
updatedAt!: string;
oauthId!: string;
@ApiProperty({ type: 'integer', format: 'int64' })
quotaSizeInBytes!: number | null;
Expand Down
4 changes: 2 additions & 2 deletions server/src/entities/activity.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export class ActivityEntity {
id!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@Column()
albumId!: string;
Expand Down
6 changes: 3 additions & 3 deletions server/src/entities/album.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class AlbumEntity {
description!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@DeleteDateColumn({ type: 'timestamptz' })
deletedAt!: Date | null;
deletedAt!: string | null;

@ManyToOne(() => AssetEntity, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' })
albumThumbnailAsset!: AssetEntity | null;
Expand Down
4 changes: 2 additions & 2 deletions server/src/entities/api-key.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class APIKeyEntity {
userId!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;
}
6 changes: 3 additions & 3 deletions server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ export class AssetEntity {
encodedVideoPath!: string | null;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@DeleteDateColumn({ type: 'timestamptz', nullable: true })
deletedAt!: Date | null;
deletedAt!: string | null;

@Index('idx_asset_file_created_at')
@Column({ type: 'timestamptz' })
Expand Down
2 changes: 1 addition & 1 deletion server/src/entities/audit.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export class AuditEntity {
ownerId!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;
}
6 changes: 3 additions & 3 deletions server/src/entities/library.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class LibraryEntity {
exclusionPatterns!: string[];

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@DeleteDateColumn({ type: 'timestamptz' })
deletedAt?: Date;
deletedAt?: string;

@Column({ type: 'timestamptz', nullable: true })
refreshedAt!: Date | null;
Expand Down
6 changes: 3 additions & 3 deletions server/src/entities/memory.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export class MemoryEntity<T extends MemoryType = MemoryType> {
id!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@DeleteDateColumn({ type: 'timestamptz' })
deletedAt?: Date;
deletedAt?: string;

@ManyToOne(() => UserEntity, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
owner!: UserEntity;
Expand Down
4 changes: 2 additions & 2 deletions server/src/entities/partner.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class PartnerEntity {
sharedWith!: UserEntity;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@Column({ type: 'boolean', default: false })
inTimeline!: boolean;
Expand Down
4 changes: 2 additions & 2 deletions server/src/entities/person.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class PersonEntity {
id!: string;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@Column()
ownerId!: string;
Expand Down
4 changes: 2 additions & 2 deletions server/src/entities/session.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class SessionEntity {
user!: UserEntity;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@Column({ default: '' })
deviceType!: string;
Expand Down
2 changes: 1 addition & 1 deletion server/src/entities/shared-link.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SharedLinkEntity {
type!: SharedLinkType;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@Column({ type: 'timestamptz', nullable: true })
expiresAt!: Date | null;
Expand Down
6 changes: 3 additions & 3 deletions server/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export class UserEntity {
shouldChangePassword!: boolean;

@CreateDateColumn({ type: 'timestamptz' })
createdAt!: Date;
createdAt!: string;

@DeleteDateColumn({ type: 'timestamptz' })
deletedAt!: Date | null;
deletedAt!: string | null;

@Column({ type: 'varchar', default: UserStatus.ACTIVE })
status!: UserStatus;

@UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: Date;
updatedAt!: string;

@OneToMany(() => TagEntity, (tag) => tag.user)
tags!: TagEntity[];
Expand Down
4 changes: 2 additions & 2 deletions server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ export interface AssetExploreOptions extends AssetExploreFieldOptions {
export interface AssetFullSyncOptions {
ownerId: string;
lastId?: string;
updatedUntil: Date;
updatedUntil: string;
limit: number;
}

export interface AssetDeltaSyncOptions {
userIds: string[];
updatedAfter: Date;
updatedAfter: string;
limit: number;
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/interfaces/audit.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export interface AuditSearch {
}

export interface IAuditRepository {
getAfter(since: Date, options: AuditSearch): Promise<string[]>;
getAfter(since: string, options: AuditSearch): Promise<string[]>;
removeBefore(before: Date): Promise<void>;
}
4 changes: 2 additions & 2 deletions server/src/repositories/audit.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { In, LessThan, MoreThan, Repository } from 'typeorm';
export class AuditRepository implements IAuditRepository {
constructor(@InjectRepository(AuditEntity) private repository: Repository<AuditEntity>) {}

async getAfter(since: Date, options: AuditSearch): Promise<string[]> {
async getAfter(since: string, options: AuditSearch): Promise<string[]> {
const records = await this.repository
.createQueryBuilder('audit')
.where({
Expand All @@ -28,6 +28,6 @@ export class AuditRepository implements IAuditRepository {
}

async removeBefore(before: Date): Promise<void> {
await this.repository.delete({ createdAt: LessThan(before) });
await this.repository.delete({ createdAt: LessThan(before.toISOString()) });
}
}
2 changes: 1 addition & 1 deletion server/src/repositories/session.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SessionRepository implements ISessionRepository {

@GenerateSql({ params: [DummyValue.DATE] })
search(options: SessionSearchOptions): Promise<SessionEntity[]> {
return this.repository.find({ where: { updatedAt: LessThanOrEqual(options.updatedBefore) } });
return this.repository.find({ where: { updatedAt: LessThanOrEqual(options.updatedBefore.toISOString()) } });
}

@GenerateSql({ params: [DummyValue.STRING] })
Expand Down
Loading
Loading