-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
1cf8b5b
commit 40cd926
Showing
8 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Request, Response } from "express"; | ||
import asyncHandler from 'express-async-handler'; | ||
import { getPaymentById } from "../service/payment.service"; | ||
|
||
export const showPaymentPage = asyncHandler(async (req: Request, res: Response): Promise<void> => { | ||
const { payment_id } = req.params | ||
const userId = req.user.id | ||
|
||
const payment = await getPaymentById(parseInt(payment_id)); | ||
|
||
if (!payment || payment.user.id !== userId) { | ||
res.status(404).json({ message: "Payment not found or not authorized" }); | ||
return; | ||
} | ||
|
||
const course = payment.course; | ||
|
||
res.json({ payment, course, user: payment.user }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Router } from 'express'; | ||
import { showPaymentPage } from '../controller/payment.controller'; | ||
|
||
const router = Router(); | ||
|
||
// Define the payment route for a specific course | ||
router.get('/:payment_id', showPaymentPage); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AppDataSource } from "../repos/db"; | ||
import { Payment } from "../entity/Payment"; | ||
import { User } from "../entity/User"; | ||
import { Course } from "../entity/Course"; | ||
|
||
const paymentRepository = AppDataSource.getRepository(Payment); | ||
|
||
export const createPayment = async (user: User, course: Course) => { | ||
const payment = paymentRepository.create({ | ||
user: user, // In a real scenario, you'd fetch the actual user from your auth system | ||
course: course, | ||
amount: course.price, // Assuming the payment amount is the course price | ||
payment_date: new Date(), | ||
status: 'done', // Or set to 'pending' based on your logic | ||
}); | ||
|
||
return await paymentRepository.save(payment); | ||
} | ||
|
||
export const getPaymentById = async (id: number) => { | ||
return await paymentRepository.findOne({ | ||
where: { id: id }, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import 'express-serve-static-core'; | ||
import { User } from '.../entity/User'; | ||
|
||
declare module 'express-serve-static-core' { | ||
interface Response { | ||
setLocale?: (locale: string) => void; | ||
} | ||
} | ||
|
||
declare global { | ||
namespace Express { | ||
interface Request { | ||
user?: User; | ||
} | ||
} | ||
} |