mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): use date type for entities (#2602)
This commit is contained in:
@@ -128,7 +128,6 @@ describe(AlbumService.name, () => {
|
||||
createdAt: expect.anything(),
|
||||
id: 'album-1',
|
||||
owner: {
|
||||
createdAt: '2021-01-01',
|
||||
email: 'admin@test.com',
|
||||
firstName: 'admin_first_name',
|
||||
id: 'admin_id',
|
||||
@@ -138,7 +137,9 @@ describe(AlbumService.name, () => {
|
||||
profileImagePath: '',
|
||||
shouldChangePassword: false,
|
||||
storageLabel: 'admin',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
},
|
||||
ownerId: 'admin_id',
|
||||
shared: false,
|
||||
|
||||
@@ -7,8 +7,8 @@ export class AlbumResponseDto {
|
||||
id!: string;
|
||||
ownerId!: string;
|
||||
albumName!: string;
|
||||
createdAt!: string;
|
||||
updatedAt!: string;
|
||||
createdAt!: Date;
|
||||
updatedAt!: Date;
|
||||
albumThumbnailAssetId!: string | null;
|
||||
shared!: boolean;
|
||||
sharedUsers!: UserResponseDto[];
|
||||
|
||||
@@ -8,8 +8,8 @@ export class APIKeyCreateResponseDto {
|
||||
export class APIKeyResponseDto {
|
||||
id!: string;
|
||||
name!: string;
|
||||
createdAt!: string;
|
||||
updatedAt!: string;
|
||||
createdAt!: Date;
|
||||
updatedAt!: Date;
|
||||
}
|
||||
|
||||
export function mapKey(entity: APIKeyEntity): APIKeyResponseDto {
|
||||
|
||||
@@ -231,10 +231,10 @@ describe('AuthService', () => {
|
||||
|
||||
it('should sign up the admin', async () => {
|
||||
userMock.getAdmin.mockResolvedValue(null);
|
||||
userMock.create.mockResolvedValue({ ...dto, id: 'admin', createdAt: 'today' } as UserEntity);
|
||||
userMock.create.mockResolvedValue({ ...dto, id: 'admin', createdAt: new Date('2021-01-01') } as UserEntity);
|
||||
await expect(sut.adminSignUp(dto)).resolves.toEqual({
|
||||
id: 'admin',
|
||||
createdAt: 'today',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
email: 'test@immich.com',
|
||||
firstName: 'immich',
|
||||
lastName: 'admin',
|
||||
|
||||
@@ -5,7 +5,7 @@ export class AdminSignupResponseDto {
|
||||
email!: string;
|
||||
firstName!: string;
|
||||
lastName!: string;
|
||||
createdAt!: string;
|
||||
createdAt!: Date;
|
||||
}
|
||||
|
||||
export function mapAdminSignupResponse(entity: UserEntity): AdminSignupResponseDto {
|
||||
|
||||
@@ -6,8 +6,6 @@ import { PartnerService } from './partner.service';
|
||||
|
||||
const responseDto = {
|
||||
admin: {
|
||||
createdAt: '2021-01-01',
|
||||
deletedAt: undefined,
|
||||
email: 'admin@test.com',
|
||||
firstName: 'admin_first_name',
|
||||
id: 'admin_id',
|
||||
@@ -16,12 +14,12 @@ const responseDto = {
|
||||
oauthId: '',
|
||||
profileImagePath: '',
|
||||
shouldChangePassword: false,
|
||||
updatedAt: '2021-01-01',
|
||||
storageLabel: 'admin',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
},
|
||||
user1: {
|
||||
createdAt: '2021-01-01',
|
||||
deletedAt: undefined,
|
||||
email: 'immich@test.com',
|
||||
firstName: 'immich_first_name',
|
||||
id: 'user-id',
|
||||
@@ -30,8 +28,10 @@ const responseDto = {
|
||||
oauthId: '',
|
||||
profileImagePath: '',
|
||||
shouldChangePassword: false,
|
||||
updatedAt: '2021-01-01',
|
||||
storageLabel: null,
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { AlbumEntity, AssetEntity, SharedLinkType } from '@app/infra/entities';
|
||||
|
||||
export class CreateSharedLinkDto {
|
||||
description?: string;
|
||||
expiresAt?: string;
|
||||
expiresAt?: Date;
|
||||
type!: SharedLinkType;
|
||||
assets!: AssetEntity[];
|
||||
album?: AlbumEntity;
|
||||
|
||||
@@ -5,7 +5,7 @@ export class EditSharedLinkDto {
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
expiresAt?: string | null;
|
||||
expiresAt?: Date | null;
|
||||
|
||||
@IsOptional()
|
||||
allowUpload?: boolean;
|
||||
|
||||
@@ -12,8 +12,8 @@ export class SharedLinkResponseDto {
|
||||
|
||||
@ApiProperty({ enumName: 'SharedLinkType', enum: SharedLinkType })
|
||||
type!: SharedLinkType;
|
||||
createdAt!: string;
|
||||
expiresAt!: string | null;
|
||||
createdAt!: Date;
|
||||
expiresAt!: Date | null;
|
||||
assets!: AssetResponseDto[];
|
||||
album?: AlbumResponseDto;
|
||||
allowUpload!: boolean;
|
||||
|
||||
@@ -23,7 +23,7 @@ export class ShareCore {
|
||||
key: Buffer.from(this.cryptoRepository.randomBytes(50)),
|
||||
description: dto.description,
|
||||
userId,
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
expiresAt: dto.expiresAt ?? null,
|
||||
type: dto.type,
|
||||
assets: dto.assets,
|
||||
|
||||
@@ -6,12 +6,12 @@ export class UserResponseDto {
|
||||
firstName!: string;
|
||||
lastName!: string;
|
||||
storageLabel!: string | null;
|
||||
createdAt!: string;
|
||||
profileImagePath!: string;
|
||||
shouldChangePassword!: boolean;
|
||||
isAdmin!: boolean;
|
||||
deletedAt?: Date;
|
||||
updatedAt?: string;
|
||||
createdAt!: Date;
|
||||
deletedAt!: Date | null;
|
||||
updatedAt!: Date;
|
||||
oauthId!: string;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ export function mapUser(entity: UserEntity): UserResponseDto {
|
||||
firstName: entity.firstName,
|
||||
lastName: entity.lastName,
|
||||
storageLabel: entity.storageLabel,
|
||||
createdAt: entity.createdAt,
|
||||
profileImagePath: entity.profileImagePath,
|
||||
shouldChangePassword: entity.shouldChangePassword,
|
||||
isAdmin: entity.isAdmin,
|
||||
createdAt: entity.createdAt,
|
||||
deletedAt: entity.deletedAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
oauthId: entity.oauthId,
|
||||
|
||||
@@ -47,8 +47,9 @@ const adminUser: UserEntity = Object.freeze({
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
storageLabel: 'admin',
|
||||
@@ -64,8 +65,9 @@ const immichUser: UserEntity = Object.freeze({
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
storageLabel: null,
|
||||
@@ -81,8 +83,9 @@ const updatedImmichUser: UserEntity = Object.freeze({
|
||||
oauthId: '',
|
||||
shouldChangePassword: true,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
storageLabel: null,
|
||||
@@ -91,15 +94,15 @@ const updatedImmichUser: UserEntity = Object.freeze({
|
||||
const adminUserResponse = Object.freeze({
|
||||
id: adminUserAuth.id,
|
||||
email: 'admin@test.com',
|
||||
deletedAt: undefined,
|
||||
firstName: 'admin_first_name',
|
||||
lastName: 'admin_last_name',
|
||||
isAdmin: true,
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
storageLabel: 'admin',
|
||||
});
|
||||
|
||||
@@ -140,15 +143,15 @@ describe(UserService.name, () => {
|
||||
{
|
||||
id: adminUserAuth.id,
|
||||
email: 'admin@test.com',
|
||||
deletedAt: undefined,
|
||||
firstName: 'admin_first_name',
|
||||
lastName: 'admin_last_name',
|
||||
isAdmin: true,
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
storageLabel: 'admin',
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -85,8 +85,9 @@ export const userEntityStub = {
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
}),
|
||||
@@ -99,8 +100,9 @@ export const userEntityStub = {
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
}),
|
||||
@@ -113,8 +115,9 @@ export const userEntityStub = {
|
||||
oauthId: '',
|
||||
shouldChangePassword: false,
|
||||
profileImagePath: '',
|
||||
createdAt: '2021-01-01',
|
||||
updatedAt: '2021-01-01',
|
||||
createdAt: new Date('2021-01-01'),
|
||||
deletedAt: null,
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
tags: [],
|
||||
assets: [],
|
||||
}),
|
||||
@@ -317,8 +320,8 @@ export const albumStub = {
|
||||
assets: [],
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -330,8 +333,8 @@ export const albumStub = {
|
||||
assets: [],
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [userEntityStub.user1],
|
||||
}),
|
||||
@@ -343,8 +346,8 @@ export const albumStub = {
|
||||
assets: [],
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [userEntityStub.admin],
|
||||
}),
|
||||
@@ -356,8 +359,8 @@ export const albumStub = {
|
||||
assets: [assetEntityStub.image],
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -369,8 +372,8 @@ export const albumStub = {
|
||||
assets: [],
|
||||
albumThumbnailAsset: assetEntityStub.image,
|
||||
albumThumbnailAssetId: assetEntityStub.image.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -382,8 +385,8 @@ export const albumStub = {
|
||||
assets: [],
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -395,8 +398,8 @@ export const albumStub = {
|
||||
assets: [assetEntityStub.image],
|
||||
albumThumbnailAsset: assetEntityStub.livePhotoMotionAsset,
|
||||
albumThumbnailAssetId: assetEntityStub.livePhotoMotionAsset.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -408,8 +411,8 @@ export const albumStub = {
|
||||
assets: [assetEntityStub.image],
|
||||
albumThumbnailAsset: assetEntityStub.image,
|
||||
albumThumbnailAssetId: assetEntityStub.image.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
sharedLinks: [],
|
||||
sharedUsers: [],
|
||||
}),
|
||||
@@ -468,8 +471,8 @@ const assetResponse: AssetResponseDto = {
|
||||
const albumResponse: AlbumResponseDto = {
|
||||
albumName: 'Test Album',
|
||||
albumThumbnailAssetId: null,
|
||||
createdAt: today.toISOString(),
|
||||
updatedAt: today.toISOString(),
|
||||
createdAt: today,
|
||||
updatedAt: today,
|
||||
id: 'album-123',
|
||||
ownerId: 'admin_id',
|
||||
owner: mapUser(userEntityStub.admin),
|
||||
@@ -645,8 +648,8 @@ export const sharedLinkStub = {
|
||||
user: userEntityStub.admin,
|
||||
key: Buffer.from('secret-key', 'utf8'),
|
||||
type: SharedLinkType.ALBUM,
|
||||
createdAt: today.toISOString(),
|
||||
expiresAt: tomorrow.toISOString(),
|
||||
createdAt: today,
|
||||
expiresAt: tomorrow,
|
||||
allowUpload: true,
|
||||
allowDownload: true,
|
||||
showExif: true,
|
||||
@@ -659,8 +662,8 @@ export const sharedLinkStub = {
|
||||
user: userEntityStub.admin,
|
||||
key: Buffer.from('secret-key', 'utf8'),
|
||||
type: SharedLinkType.ALBUM,
|
||||
createdAt: today.toISOString(),
|
||||
expiresAt: yesterday.toISOString(),
|
||||
createdAt: today,
|
||||
expiresAt: yesterday,
|
||||
allowUpload: true,
|
||||
allowDownload: true,
|
||||
showExif: true,
|
||||
@@ -672,8 +675,8 @@ export const sharedLinkStub = {
|
||||
user: userEntityStub.admin,
|
||||
key: Buffer.from('secret-key', 'utf8'),
|
||||
type: SharedLinkType.ALBUM,
|
||||
createdAt: today.toISOString(),
|
||||
expiresAt: tomorrow.toISOString(),
|
||||
createdAt: today,
|
||||
expiresAt: tomorrow,
|
||||
allowUpload: false,
|
||||
allowDownload: false,
|
||||
showExif: true,
|
||||
@@ -683,8 +686,8 @@ export const sharedLinkStub = {
|
||||
ownerId: authStub.admin.id,
|
||||
owner: userEntityStub.admin,
|
||||
albumName: 'Test Album',
|
||||
createdAt: today.toISOString(),
|
||||
updatedAt: today.toISOString(),
|
||||
createdAt: today,
|
||||
updatedAt: today,
|
||||
albumThumbnailAsset: null,
|
||||
albumThumbnailAssetId: null,
|
||||
sharedUsers: [],
|
||||
@@ -763,9 +766,9 @@ export const sharedLinkResponseStub = {
|
||||
allowDownload: true,
|
||||
allowUpload: true,
|
||||
assets: [],
|
||||
createdAt: today.toISOString(),
|
||||
createdAt: today,
|
||||
description: undefined,
|
||||
expiresAt: tomorrow.toISOString(),
|
||||
expiresAt: tomorrow,
|
||||
id: '123',
|
||||
key: '7365637265742d6b6579',
|
||||
showExif: true,
|
||||
@@ -777,9 +780,9 @@ export const sharedLinkResponseStub = {
|
||||
allowDownload: true,
|
||||
allowUpload: true,
|
||||
assets: [],
|
||||
createdAt: today.toISOString(),
|
||||
createdAt: today,
|
||||
description: undefined,
|
||||
expiresAt: yesterday.toISOString(),
|
||||
expiresAt: yesterday,
|
||||
id: '123',
|
||||
key: '7365637265742d6b6579',
|
||||
showExif: true,
|
||||
@@ -791,8 +794,8 @@ export const sharedLinkResponseStub = {
|
||||
userId: 'admin_id',
|
||||
key: '7365637265742d6b6579',
|
||||
type: SharedLinkType.ALBUM,
|
||||
createdAt: today.toISOString(),
|
||||
expiresAt: tomorrow.toISOString(),
|
||||
createdAt: today,
|
||||
expiresAt: tomorrow,
|
||||
description: undefined,
|
||||
allowUpload: false,
|
||||
allowDownload: false,
|
||||
@@ -805,8 +808,8 @@ export const sharedLinkResponseStub = {
|
||||
userId: 'admin_id',
|
||||
key: '7365637265742d6b6579',
|
||||
type: SharedLinkType.ALBUM,
|
||||
createdAt: today.toISOString(),
|
||||
expiresAt: tomorrow.toISOString(),
|
||||
createdAt: today,
|
||||
expiresAt: tomorrow,
|
||||
description: undefined,
|
||||
allowUpload: false,
|
||||
allowDownload: false,
|
||||
|
||||
@@ -28,10 +28,10 @@ export class AlbumEntity {
|
||||
albumName!: string;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt!: string;
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamptz' })
|
||||
updatedAt!: string;
|
||||
updatedAt!: Date;
|
||||
|
||||
@ManyToOne(() => AssetEntity, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' })
|
||||
albumThumbnailAsset!: AssetEntity | null;
|
||||
|
||||
@@ -19,8 +19,8 @@ export class APIKeyEntity {
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt!: string;
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamptz' })
|
||||
updatedAt!: string;
|
||||
updatedAt!: Date;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ export class SharedLinkEntity {
|
||||
type!: SharedLinkType;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt!: string;
|
||||
createdAt!: Date;
|
||||
|
||||
@Column({ type: 'timestamptz', nullable: true })
|
||||
expiresAt!: string | null;
|
||||
expiresAt!: Date | null;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
allowUpload!: boolean;
|
||||
|
||||
@@ -42,14 +42,14 @@ export class UserEntity {
|
||||
@Column({ default: true })
|
||||
shouldChangePassword!: boolean;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: string;
|
||||
@CreateDateColumn({ type: 'timestamptz' })
|
||||
createdAt!: Date;
|
||||
|
||||
@DeleteDateColumn()
|
||||
deletedAt?: Date;
|
||||
@DeleteDateColumn({ type: 'timestamptz' })
|
||||
deletedAt!: Date | null;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamptz' })
|
||||
updatedAt!: string;
|
||||
updatedAt!: Date;
|
||||
|
||||
@OneToMany(() => TagEntity, (tag) => tag.user)
|
||||
tags!: TagEntity[];
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UserDatesTimestamptz1685370430343 implements MigrationInterface {
|
||||
name = 'UserDatesTimestamptz1685370430343'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "createdAt" TYPE TIMESTAMP WITH TIME ZONE`);
|
||||
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`);
|
||||
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "createdAt" TYPE TIMESTAMP`);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user