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[]> {
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,
};
}
}

View File

@ -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);

View File

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