Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/prompts/repositories/prompt.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const promptSelect = Prisma.validator<Prisma.PromptSelect>()({
},
});

export const getPromptDetailRepo = async (promptId: number) => {
export const getPromptDetailRepo = async (promptId: number, userId?: number) => {

await prisma.prompt.update({
where: { prompt_id: promptId },
Expand Down Expand Up @@ -334,7 +334,37 @@ export const getPromptDetailRepo = async (promptId: number) => {
// โœ… ํ†ต๊ณ„ ๋ถ™์ด๊ธฐ
const [promptWithStats] = attachReviewStats([prompt], stats);

return promptWithStats;
let is_paid = false;

if (userId) {
if (prompt.user_id === userId) {
// ๋ณธ์ธ์ด ๋“ฑ๋กํ•œ ํ”„๋กฌํ”„ํŠธ (๋ฌด์กฐ๊ฑด ์—ด๋žŒ ๊ฐ€๋Šฅ)
is_paid = true;
} else if (prompt.is_free) {
// ๋กœ๊ทธ์ธํ•œ ์ƒํƒœ && ๋ฌด๋ฃŒ ํ”„๋กฌํ”„ํŠธ (DB ์กฐํšŒ ์—†์ด ์—ด๋žŒ ๊ฐ€๋Šฅ)
is_paid = true;
} else {
// ๋กœ๊ทธ์ธํ•œ ์ƒํƒœ && ์œ ๋ฃŒ ํ”„๋กฌํ”„ํŠธ (๊ฒฐ์ œ ์„ฑ๊ณต ์—ฌ๋ถ€ ๊ฒ€์‚ฌ)
const purchaseRecord = await prisma.purchase.findFirst({
where: {
user_id: userId,
prompt_id: promptId,
payment: {
status: 'Succeed',
},
},
});

if (purchaseRecord) {
is_paid = true;
}
}
}

return {
...promptWithStats,
is_paid,
};
};

export const createPromptWriteRepo = async (
Expand Down
1 change: 1 addition & 0 deletions src/prompts/routes/prompt.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ router.get("/", promptController.getAllPrompts);
* usage_guide: "์‚ฌ์šฉ ๊ฐ€์ด๋“œ 2"
* price: 1000
* is_free: false
* is_paid: true
* tags:
* - tag_id: 2
* name: "ํƒœ๊ทธ 2"
Expand Down
Loading