Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create/update payments tables #62

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
26 changes: 26 additions & 0 deletions backend/typescript/rest/paymentRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Router } from "express";
import PaymentService from "../services/implementations/paymentService";
import IPaymentService from "../services/interfaces/paymentService";

const paymentRouter: Router = Router();
const paymentService: IPaymentService = new PaymentService();

paymentRouter.post("/", (req, res) => {
try {
paymentService.createPayment(req.body)
} catch (err) {
console.error(err)
}
res.send("Payment successful!");
});

paymentRouter.put("/", (req, res) => {
const { id, payload } = req.body
try {
paymentService.updatePayment(id, payload)
} catch (err) {
console.error(err)
}

res.send("Payment updated!");
});
35 changes: 35 additions & 0 deletions backend/typescript/services/implementations/paymentService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import IPaymentService from "../interfaces/paymentService";
import prisma from "../../prisma";

class PaymentService implements IPaymentService {
async createPayment(payload: any): Promise<any> {
try {
const newPayment = prisma.payment.create({
data: payload
})

return newPayment;
} catch (error) {
console.error(error)
}

}

async updatePayment(paymentId: number, payload: any): Promise<any> {

try {
const updatedPayment = prisma.payment.update({
where: {
id: paymentId,
},
data: payload
})

return updatedPayment;
} catch (error) {
console.error(error)
}
}
}

export default PaymentService;
32 changes: 32 additions & 0 deletions backend/typescript/services/interfaces/paymentService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


/**
* Interface for the PaymentDTO class
*/
// export interface PaymentDTO {
// id: number;
// stripePaymentId: string;
// creationDate: string;
// updateDate: string;
// // donation?: number;
// amount: number;
// currency: string;
// status: string;
// }

/**
* Interface for the PaymentService class
*/
interface IPaymentService {
/**
* retrieve the SimpleEntity with the given id
* @param id SimpleEntity id
* @returns requested SimpleEntity
* @throws Error if retrieval fails
*/
createPayment(payload: any): Promise<any>;

updatePayment(paymentId: number, payload: any): Promise<any>;
}

export default IPaymentService;