Skip to content

Commit 3ebd946

Browse files
committed
Bug:Add UpgradeOrganzierPayment
1 parent 6a74bd6 commit 3ebd946

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

controllers/organizerInvoiceController.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ const messages = {
1212
const addOrganizerInvoice = async (req, res) => {
1313
try {
1414
const data = await add_organizer_payment_invoice(req.body);
15-
if (data.length > 0) {
15+
console.log(data);
16+
if (!data.error) {
17+
return res.status(200).json(data);
18+
} else {
19+
return res.status(404).json({ message: messages.notFound });
20+
}
21+
} catch (error) {
22+
return res.status(500).json({ message: messages.serverError });
23+
}
24+
};
25+
26+
const upgradeOrganizerPayment = async (req, res) => {
27+
try {
28+
const id = await getOrganizerInvoiceById();
29+
const accountLevelId = req.body.subscription.accountLevelId;
30+
const data = await add_organizer_payment_invoice(req.body.payment);
31+
32+
if (!data.error) {
1633
return res.status(200).json(data);
1734
} else {
1835
return res.status(404).json({ message: messages.notFound });
@@ -53,4 +70,5 @@ module.exports = {
5370
addOrganizerInvoice,
5471
getAllOrganizerInvoice,
5572
getOrganizerInvoiceById,
73+
upgradeOrganizerPayment,
5674
};

helper/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ const verifyRefresh = (email, token) => {
1212
}
1313
};
1414

15-
module.exports = { verifyRefresh };
15+
const getOrganizerIdFromToken = () => {
16+
const token = req.cookies.accessToken;
17+
18+
if (!token) return res.status(403).send("Access denied.");
19+
const decoded = jwt.verify(token, process.env.JWT_SECRET);
20+
21+
const id = decoded.UserInfo.id;
22+
return id;
23+
};
24+
25+
module.exports = { verifyRefresh, getOrganizerIdFromToken };

routers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ router.use("/customer", customerRoutes);
1818
router.use("/admin", admin);
1919
router.use("/organizer", organizerRouter);
2020
router.use("/organizer-payment", organizerSidePaymentRoutes);
21-
router.use("/organizer-invoice/", organizerInvoiceRoutes);
21+
router.use("/organizer-invoice", organizerInvoiceRoutes);
2222
router.use("/event", eventRoute);
2323
router.use("/ticket", ticketRoutes);
2424
router.use("/upgrade-payment", upgradePaymentRoutes);

services/organizerPaymentInvoiceService.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ const get_all_organizer_payment_invoice = async () => {
99
}
1010
};
1111

12-
const get_organizer_payment_invoice_by_id = async (
13-
organizerPaymentInvoiceId
14-
) => {
12+
const get_organizer_payment_invoice_by_id = async (organizerPaymentInvoiceId) => {
1513
try {
16-
const result = await OrganizerPaymentInvoice.findById(
17-
organizerPaymentInvoiceId
18-
);
14+
const result = await OrganizerPaymentInvoice.findById(organizerPaymentInvoiceId);
1915

2016
return { data: result };
2117
} catch (error) {
@@ -24,14 +20,12 @@ const get_organizer_payment_invoice_by_id = async (
2420
};
2521

2622
const add_organizer_payment_invoice = async (organizerPaymentInvoiceData) => {
27-
const organizerPaymentInvoice = new OrganizerPaymentInvoice(
28-
organizerPaymentInvoiceData
29-
);
23+
const organizerPaymentInvoice = new OrganizerPaymentInvoice(organizerPaymentInvoiceData);
3024
try {
3125
const result = await organizerPaymentInvoice.save();
3226
return result;
3327
} catch (error) {
34-
return error;
28+
return { error: error };
3529
}
3630
};
3731

0 commit comments

Comments
 (0)