mirror of
https://github.com/immich-app/immich.git
synced 2026-03-22 23:58:58 +03:00
fix(server): accept showAt and hideAt for creating memories (#26429)
* fix(server): accept showAt and hideAt for creating memories * fix history
This commit is contained in:
@@ -51,6 +51,20 @@ describe(MemoryController.name, () => {
|
||||
errorDto.badRequest(['data.year must be a positive number', 'data.year must be an integer number']),
|
||||
);
|
||||
});
|
||||
|
||||
it('should accept showAt and hideAt', async () => {
|
||||
const { status } = await request(ctx.getHttpServer())
|
||||
.post('/memories')
|
||||
.send({
|
||||
type: 'on_this_day',
|
||||
data: { year: 2020 },
|
||||
memoryAt: new Date(2021).toISOString(),
|
||||
showAt: new Date(2022).toISOString(),
|
||||
hideAt: new Date(2023).toISOString(),
|
||||
});
|
||||
|
||||
expect(status).toBe(201);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /memories/statistics', () => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInt, IsObject, IsPositive, ValidateNested } from 'class-validator';
|
||||
import { Memory } from 'src/database';
|
||||
import { HistoryBuilder } from 'src/decorators';
|
||||
import { AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { AssetOrderWithRandom, MemoryType } from 'src/enum';
|
||||
@@ -77,6 +78,20 @@ export class MemoryCreateDto extends MemoryBaseDto {
|
||||
@ValidateDate({ description: 'Memory date' })
|
||||
memoryAt!: Date;
|
||||
|
||||
@ValidateDate({
|
||||
optional: true,
|
||||
description: 'Date when memory should be shown',
|
||||
history: new HistoryBuilder().added('v2.6.0').stable('v2.6.0'),
|
||||
})
|
||||
showAt?: Date;
|
||||
|
||||
@ValidateDate({
|
||||
optional: true,
|
||||
description: 'Date when memory should be hidden',
|
||||
history: new HistoryBuilder().added('v2.6.0').stable('v2.6.0'),
|
||||
})
|
||||
hideAt?: Date;
|
||||
|
||||
@ValidateUUID({ optional: true, each: true, description: 'Asset IDs to associate with memory' })
|
||||
assetIds?: string[];
|
||||
}
|
||||
|
||||
@@ -100,6 +100,8 @@ export class MemoryService extends BaseService {
|
||||
data: dto.data,
|
||||
isSaved: dto.isSaved,
|
||||
memoryAt: dto.memoryAt,
|
||||
showAt: dto.showAt,
|
||||
hideAt: dto.hideAt,
|
||||
seenAt: dto.seenAt,
|
||||
},
|
||||
allowedAssetIds,
|
||||
|
||||
@@ -233,7 +233,7 @@ export const ValidateHexColor = () => {
|
||||
};
|
||||
|
||||
type DateOptions = OptionalOptions & { optional?: boolean; format?: 'date' | 'date-time' };
|
||||
export const ValidateDate = (options?: DateOptions & ApiPropertyOptions) => {
|
||||
export const ValidateDate = (options?: DateOptions & PropertyOptions) => {
|
||||
const {
|
||||
optional,
|
||||
nullable = false,
|
||||
@@ -243,7 +243,7 @@ export const ValidateDate = (options?: DateOptions & ApiPropertyOptions) => {
|
||||
} = options || {};
|
||||
|
||||
return applyDecorators(
|
||||
ApiProperty({ format, ...apiPropertyOptions }),
|
||||
Property({ format, ...apiPropertyOptions }),
|
||||
IsDate(),
|
||||
optional ? Optional({ nullable, emptyToNull }) : IsNotEmpty(),
|
||||
Transform(({ key, value }) => {
|
||||
|
||||
Reference in New Issue
Block a user