-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathorganizerSidePaymentController.js
79 lines (69 loc) · 2.1 KB
/
organizerSidePaymentController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { getOrganizerIdFromToken } = require("../helper");
const {
get_payment_by_organizer_id,
update_payment,
add_payment,
} = require("../services/paymentService");
const messages = {
notFound: "No Data Found",
serverError: "Internal Server Error",
};
const getAllPaymentsByOrganizerId = async (req, res) => {
const id = await getOrganizerIdFromToken(req, res);
console.log(id);
try {
const allPaymentsByOrganizer = await get_payment_by_organizer_id(id);
if (allPaymentsByOrganizer.length <= 0) {
return res.status(404).json({ message: messages.notFound });
}
return res.status(200).json(allPaymentsByOrganizer);
} catch (error) {
return res.status(500).json({ message: messages.serverError });
}
};
const getAllPaymentsByOrganizerIdAdmin = async (req, res) => {
const id = await req.params.organizerId
console.log(id);
try {
const allPaymentsByOrganizer = await get_payment_by_organizer_id(id);
if (allPaymentsByOrganizer.length <= 0) {
return res.status(404).json({ message: messages.notFound });
}
return res.status(200).json(allPaymentsByOrganizer);
} catch (error) {
return res.status(500).json({ message: messages.serverError });
}
};
const addOrganizerPayment = async (req, res) => {
const id = await getOrganizerIdFromToken(req, res);
const paymentData = req.body.payment;
const response = [];
for (const payment of paymentData) {
try {
const addedPayment = await add_payment({ ...payment, organizer: id });
response.push(addedPayment);
} catch (error) {
return res.json(error);
}
}
return res.json(response);
};
const updateOrganizerPayment = async (req, res) => {
const { paymentId } = req.params;
const paymentData = req.body;
try {
const payment = await update_payment(paymentId, paymentData);
if (payment.error) {
return res.status(400).json(payment.error);
}
res.json(payment);
} catch (error) {
res.status(400).send(error);
}
};
module.exports = {
getAllPaymentsByOrganizerId,
updateOrganizerPayment,
addOrganizerPayment,
getAllPaymentsByOrganizerIdAdmin
};