From 66c79948dc7f0cbc9cf83ac75837663fc5fd72e7 Mon Sep 17 00:00:00 2001 From: EstherDev2 Date: Sun, 18 Jun 2023 18:43:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=97=E8=AD=89?= =?UTF-8?q?=EF=BC=9Aoption=20status=20=E9=9C=80=E5=A4=A7=E6=96=BC2=20(API:?= =?UTF-8?q?=20S5&S6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/option.bp.ts | 3 ++- src/controllers/project.bp.ts | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/controllers/option.bp.ts b/src/controllers/option.bp.ts index d41dddc..f232d55 100644 --- a/src/controllers/option.bp.ts +++ b/src/controllers/option.bp.ts @@ -85,7 +85,8 @@ async function doGetProjectOptions(projectId: string) { const options = await Option.find({ option_parent: projectId, - delete: false + delete: false, + option_status: { $gte: 2 } }).exec(); if (!options || options.length === 0) { diff --git a/src/controllers/project.bp.ts b/src/controllers/project.bp.ts index 43005ca..551c109 100644 --- a/src/controllers/project.bp.ts +++ b/src/controllers/project.bp.ts @@ -267,12 +267,16 @@ async function doGetProject(projectId: string) { proposer_project: 1, proposer_tax_id: 1 }) - .populate("option", { - _id: 1, - option_name: 1, - option_price: 1, - option_content: 1, - option_cover: 1 + .populate({ + path: "option", + match: { option_status: { $gte: 2 } }, // 只關聯 option_status >= 2 的 option + select: { + _id: 1, + option_name: 1, + option_price: 1, + option_content: 1, + option_cover: 1 + } }) .populate("qas", { _id: 1, From f8d85497a4e398cb7697f8992418fba8f3afc127 Mon Sep 17 00:00:00 2001 From: EstherDev2 Date: Sun, 18 Jun 2023 18:43:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=97=E8=AD=89?= =?UTF-8?q?=EF=BC=9A=E4=BF=AE=E6=94=B9/=E5=88=AA=E9=99=A4=E5=B0=88?= =?UTF-8?q?=E6=A1=88=E6=99=82=E9=A9=97=E8=AD=89=E6=8F=90=E6=A1=88=E4=BA=BA?= =?UTF-8?q?=E8=BA=AB=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/project.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/project.ts b/src/controllers/project.ts index 6d8f06f..c6c14c5 100644 --- a/src/controllers/project.ts +++ b/src/controllers/project.ts @@ -89,6 +89,8 @@ export const putOwnerProject: RequestHandler = async ( return next(createError(400, "找不到專案")); } + await isUserProposer(userId, projectId); + // TODO: verify data const project = await doPutOwnerProject(userId, projectId, data); @@ -107,6 +109,8 @@ export const deleteOwnerProject: RequestHandler = async ( return next(createError(400, "找不到專案")); } + await isUserProposer(userId, projectId); + const result = await doDeleteOwnerProject(userId, projectId); return handleSuccess(res, result); };