Skip to content

Commit cfb206d

Browse files
authored
Merge pull request #444 from PromptPlace/develop
Develop
2 parents ec913a6 + 03b04b6 commit cfb206d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/prompts/repositories/prompt.repository.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ const promptSelect = Prisma.validator<Prisma.PromptSelect>()({
278278
},
279279
});
280280

281-
export const getPromptDetailRepo = async (promptId: number) => {
281+
export const getPromptDetailRepo = async (promptId: number, userId?: number) => {
282282

283283
await prisma.prompt.update({
284284
where: { prompt_id: promptId },
@@ -334,7 +334,37 @@ export const getPromptDetailRepo = async (promptId: number) => {
334334
// ✅ 통계 붙이기
335335
const [promptWithStats] = attachReviewStats([prompt], stats);
336336

337-
return promptWithStats;
337+
let is_paid = false;
338+
339+
if (userId) {
340+
if (prompt.user_id === userId) {
341+
// 본인이 등록한 프롬프트 (무조건 열람 가능)
342+
is_paid = true;
343+
} else if (prompt.is_free) {
344+
// 로그인한 상태 && 무료 프롬프트 (DB 조회 없이 열람 가능)
345+
is_paid = true;
346+
} else {
347+
// 로그인한 상태 && 유료 프롬프트 (결제 성공 여부 검사)
348+
const purchaseRecord = await prisma.purchase.findFirst({
349+
where: {
350+
user_id: userId,
351+
prompt_id: promptId,
352+
payment: {
353+
status: 'Succeed',
354+
},
355+
},
356+
});
357+
358+
if (purchaseRecord) {
359+
is_paid = true;
360+
}
361+
}
362+
}
363+
364+
return {
365+
...promptWithStats,
366+
is_paid,
367+
};
338368
};
339369

340370
export const createPromptWriteRepo = async (

src/prompts/routes/prompt.route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ router.get("/", promptController.getAllPrompts);
200200
* usage_guide: "사용 가이드 2"
201201
* price: 1000
202202
* is_free: false
203+
* is_paid: true
203204
* tags:
204205
* - tag_id: 2
205206
* name: "태그 2"

0 commit comments

Comments
 (0)