diff --git a/src/app.service.ts b/src/app.service.ts index 20801f5..11ec469 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -26,11 +26,12 @@ export class AppService { async getImageList(): Promise { const imageList = await this.imageModel.find().exec(); - return imageList.map(({url, author, likes, id}) => ({ + return imageList.map(({url, author, likes, id, create_at}) => ({ url, author, likes, id, + create_at, })); } @@ -65,6 +66,7 @@ export class AppService { url: image.url, likes: [], author: login, + create_at: new Date().toISOString() }); try { await imageModel.validate(); @@ -78,6 +80,7 @@ export class AppService { author: newImage.author, likes: [], id: newImage.id, + create_at: newImage.create_at, }; } @@ -89,6 +92,7 @@ export class AppService { author: searchImage.author, likes: searchImage.likes, id: searchImage.id, + create_at: searchImage.create_at, }; } throw new BadRequestException(`Картинка с id - "${id}" не найдена`); @@ -110,6 +114,7 @@ export class AppService { author: searchImage.author, likes: searchImage.likes, id: searchImage.id, + create_at: searchImage.create_at, }; } @@ -130,6 +135,7 @@ export class AppService { author: searchImage.author, likes: updatedLikes, id: searchImage.id, + create_at: searchImage.create_at, }; } } diff --git a/src/schemas.ts b/src/schemas.ts index def3a29..6e99a5b 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -33,6 +33,9 @@ export class ImageResponse implements Image { @ApiProperty() id: string; + + @ApiProperty() + create_at: string; } @Schema() @@ -69,6 +72,12 @@ export class ImageDocument extends Document { required: true, }) likes: string[]; + + @Prop({ + type: String, + required: true, + }) + create_at: string; } export const ImageScheme = SchemaFactory.createForClass(ImageDocument); diff --git a/src/types.ts b/src/types.ts index 6c28195..bb33f5f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,6 +6,7 @@ export type Image = { url: string; author: string; likes: string[]; + create_at: string; id: string; };