From 9a7edacfc7a2b7030d04157490a3e471027edd4d Mon Sep 17 00:00:00 2001 From: Hyun_Gwang Date: Thu, 3 Oct 2024 13:37:07 +0900 Subject: [PATCH] fix: add watch --- src/controller/meme.controller.ts | 5 +++++ src/model/meme.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/controller/meme.controller.ts b/src/controller/meme.controller.ts index f9309ab..0813d5b 100644 --- a/src/controller/meme.controller.ts +++ b/src/controller/meme.controller.ts @@ -85,12 +85,17 @@ const createMeme = async (req: CustomRequest, res: Response, next: NextFunction) return next(new CustomError(`'keywordIds' field should be provided`, HttpCode.BAD_REQUEST)); } + if (typeof req.body.keywordIds !== 'object') { + return next(new CustomError(`'keywordIds' should be an array`, HttpCode.BAD_REQUEST)); + } + const createPayload: IMemeCreatePayload = { deviceId: user.deviceId, title: req.body.title, image: image.location, source: req.body.source, keywordIds: req.body.keywordIds.map((id: string) => new Types.ObjectId(id)), + watch: 0, }; try { diff --git a/src/model/meme.ts b/src/model/meme.ts index aa453d5..b323478 100644 --- a/src/model/meme.ts +++ b/src/model/meme.ts @@ -7,6 +7,7 @@ export interface IMemeCreatePayload { title: string; keywordIds: Types.ObjectId[]; image: string; + watch: number; source: string; } @@ -23,6 +24,7 @@ export interface IMeme { keywordIds: Types.ObjectId[]; image: string; reaction: number; + watch: number; source: string; isTodayMeme: boolean; } @@ -50,6 +52,7 @@ export interface IMemeDocument extends Document { keywordIds: Types.ObjectId[]; image: string; reaction: number; + watch: number; source: string; isTodayMeme: boolean; createdAt: Date; @@ -64,6 +67,7 @@ const MemeSchema: Schema = new Schema( keywordIds: { type: [Types.ObjectId], ref: 'Keyword', required: true, default: [] }, image: { type: String, required: true }, reaction: { type: Number, required: true, default: 0 }, + watch: { type: Number, required: true, default: 0 }, source: { type: String, required: true, default: '' }, isTodayMeme: { type: Boolean, requried: true, default: false }, isDeleted: { type: Boolean, required: true, default: false },