add create date

This commit is contained in:
vigdorov
2021-05-16 20:31:25 +03:00
parent 8225dce0c5
commit 4b37f041df
3 changed files with 17 additions and 1 deletions

View File

@ -26,11 +26,12 @@ export class AppService {
async getImageList(): Promise<Image[]> { async getImageList(): Promise<Image[]> {
const imageList = await this.imageModel.find().exec(); const imageList = await this.imageModel.find().exec();
return imageList.map(({url, author, likes, id}) => ({ return imageList.map(({url, author, likes, id, create_at}) => ({
url, url,
author, author,
likes, likes,
id, id,
create_at,
})); }));
} }
@ -65,6 +66,7 @@ export class AppService {
url: image.url, url: image.url,
likes: [], likes: [],
author: login, author: login,
create_at: new Date().toISOString()
}); });
try { try {
await imageModel.validate(); await imageModel.validate();
@ -78,6 +80,7 @@ export class AppService {
author: newImage.author, author: newImage.author,
likes: [], likes: [],
id: newImage.id, id: newImage.id,
create_at: newImage.create_at,
}; };
} }
@ -89,6 +92,7 @@ export class AppService {
author: searchImage.author, author: searchImage.author,
likes: searchImage.likes, likes: searchImage.likes,
id: searchImage.id, id: searchImage.id,
create_at: searchImage.create_at,
}; };
} }
throw new BadRequestException(`Картинка с id - "${id}" не найдена`); throw new BadRequestException(`Картинка с id - "${id}" не найдена`);
@ -110,6 +114,7 @@ export class AppService {
author: searchImage.author, author: searchImage.author,
likes: searchImage.likes, likes: searchImage.likes,
id: searchImage.id, id: searchImage.id,
create_at: searchImage.create_at,
}; };
} }
@ -130,6 +135,7 @@ export class AppService {
author: searchImage.author, author: searchImage.author,
likes: updatedLikes, likes: updatedLikes,
id: searchImage.id, id: searchImage.id,
create_at: searchImage.create_at,
}; };
} }
} }

View File

@ -33,6 +33,9 @@ export class ImageResponse implements Image {
@ApiProperty() @ApiProperty()
id: string; id: string;
@ApiProperty()
create_at: string;
} }
@Schema() @Schema()
@ -69,6 +72,12 @@ export class ImageDocument extends Document {
required: true, required: true,
}) })
likes: string[]; likes: string[];
@Prop({
type: String,
required: true,
})
create_at: string;
} }
export const ImageScheme = SchemaFactory.createForClass(ImageDocument); export const ImageScheme = SchemaFactory.createForClass(ImageDocument);

View File

@ -6,6 +6,7 @@ export type Image = {
url: string; url: string;
author: string; author: string;
likes: string[]; likes: string[];
create_at: string;
id: string; id: string;
}; };