refactor(server): use date type for entities (#2602)

This commit is contained in:
Michel Heusschen 2023-05-30 15:15:56 +02:00 committed by GitHub
parent 3d505e425d
commit 789e3e3924
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 243 additions and 217 deletions

View file

@ -61,7 +61,7 @@ export class AlbumRepository implements IAlbumRepository {
async addSharedUsers(album: AlbumEntity, addUsersDto: AddUsersDto): Promise<AlbumEntity> {
album.sharedUsers.push(...addUsersDto.sharedUserIds.map((id) => ({ id } as UserEntity)));
album.updatedAt = new Date().toISOString();
album.updatedAt = new Date();
await this.albumRepository.save(album);
@ -71,7 +71,7 @@ export class AlbumRepository implements IAlbumRepository {
async removeUser(album: AlbumEntity, userId: string): Promise<void> {
album.sharedUsers = album.sharedUsers.filter((user) => user.id !== userId);
album.updatedAt = new Date().toISOString();
album.updatedAt = new Date();
await this.albumRepository.save(album);
}
@ -84,7 +84,7 @@ export class AlbumRepository implements IAlbumRepository {
const numRemovedAssets = assetCount - album.assets.length;
if (numRemovedAssets > 0) {
album.updatedAt = new Date().toISOString();
album.updatedAt = new Date();
}
await this.albumRepository.save(album, {});
@ -111,7 +111,7 @@ export class AlbumRepository implements IAlbumRepository {
const successfullyAdded = addAssetsDto.assetIds.length - alreadyExisting.length;
if (successfullyAdded > 0) {
album.updatedAt = new Date().toISOString();
album.updatedAt = new Date();
}
await this.albumRepository.save(album);

View file

@ -32,8 +32,9 @@ describe('Album service', () => {
...authUser,
firstName: 'auth',
lastName: 'user',
createdAt: 'date',
updatedAt: 'date',
createdAt: new Date('2022-06-19T23:41:36.910Z'),
deletedAt: null,
updatedAt: new Date('2022-06-19T23:41:36.910Z'),
profileImagePath: '',
shouldChangePassword: false,
oauthId: '',
@ -52,8 +53,8 @@ describe('Album service', () => {
albumEntity.owner = albumOwner;
albumEntity.id = albumId;
albumEntity.albumName = 'name';
albumEntity.createdAt = 'date';
albumEntity.updatedAt = 'date';
albumEntity.createdAt = new Date('2022-06-19T23:41:36.910Z');
albumEntity.updatedAt = new Date('2022-06-19T23:41:36.910Z');
albumEntity.sharedUsers = [];
albumEntity.assets = [];
albumEntity.albumThumbnailAssetId = null;
@ -67,7 +68,7 @@ describe('Album service', () => {
albumEntity.owner = albumOwner;
albumEntity.id = albumId;
albumEntity.albumName = 'name';
albumEntity.createdAt = 'date';
albumEntity.createdAt = new Date('2022-06-19T23:41:36.910Z');
albumEntity.assets = [];
albumEntity.albumThumbnailAssetId = null;
albumEntity.sharedUsers = [
@ -86,7 +87,7 @@ describe('Album service', () => {
albumEntity.owner = albumOwner;
albumEntity.id = albumId;
albumEntity.albumName = 'name';
albumEntity.createdAt = 'date';
albumEntity.createdAt = new Date('2022-06-19T23:41:36.910Z');
albumEntity.assets = [];
albumEntity.albumThumbnailAssetId = null;
albumEntity.sharedUsers = [
@ -109,7 +110,7 @@ describe('Album service', () => {
albumEntity.ownerId = '5555';
albumEntity.id = albumId;
albumEntity.albumName = 'name';
albumEntity.createdAt = 'date';
albumEntity.createdAt = new Date('2022-06-19T23:41:36.910Z');
albumEntity.sharedUsers = [];
albumEntity.assets = [];
albumEntity.albumThumbnailAssetId = null;
@ -158,8 +159,8 @@ describe('Album service', () => {
owner: mapUser(albumOwner),
id: albumId,
albumName: 'name',
createdAt: 'date',
updatedAt: 'date',
createdAt: new Date('2022-06-19T23:41:36.910Z'),
updatedAt: new Date('2022-06-19T23:41:36.910Z'),
sharedUsers: [],
assets: [],
albumThumbnailAssetId: null,

View file

@ -1,15 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { ValidateUUID } from 'apps/immich/src/decorators/validate-uuid.decorator';
import { IsBoolean, IsISO8601, IsOptional, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { IsBoolean, IsDate, IsOptional, IsString } from 'class-validator';
export class CreateAlbumShareLinkDto {
@ValidateUUID()
albumId!: string;
@IsISO8601()
@IsOptional()
@ApiProperty({ format: 'date-time' })
expiresAt?: string;
@IsDate()
@Type(() => Date)
@ApiProperty()
expiresAt?: Date;
@IsBoolean()
@IsOptional()

View file

@ -1,5 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { IsArray, IsBoolean, IsDate, IsNotEmpty, IsOptional, IsString } from 'class-validator';
export class CreateAssetsShareLinkDto {
@IsArray()
@ -17,9 +18,10 @@ export class CreateAssetsShareLinkDto {
})
assetIds!: string[];
@IsString()
@IsDate()
@Type(() => Date)
@IsOptional()
expiresAt?: string;
expiresAt?: Date;
@IsBoolean()
@IsOptional()

View file

@ -21,9 +21,9 @@ describe('TagService', () => {
email: 'testuser@email.com',
profileImagePath: '',
shouldChangePassword: true,
createdAt: '2022-12-02T19:29:23.603Z',
deletedAt: undefined,
updatedAt: '2022-12-02T19:29:23.603Z',
createdAt: new Date('2022-12-02T19:29:23.603Z'),
deletedAt: null,
updatedAt: new Date('2022-12-02T19:29:23.603Z'),
tags: [],
assets: [],
oauthId: 'oauth-id-1',