mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-19 19:01:19 +00:00
Fix to purchase models after unique purchases update
This commit is contained in:
parent
823fff5c96
commit
173632deb8
@ -83,21 +83,9 @@ export const addResourcePurchaseToUser = async (userId, purchaseData) => {
|
||||
where: { id: userId },
|
||||
data: {
|
||||
purchased: {
|
||||
upsert: {
|
||||
where: {
|
||||
userId_courseId_resourceId: {
|
||||
userId: userId,
|
||||
courseId: null,
|
||||
resourceId: purchaseData.resourceId,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
resourceId: purchaseData.resourceId,
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
update: {
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
create: {
|
||||
resourceId: purchaseData.resourceId,
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -116,21 +104,9 @@ export const addCoursePurchaseToUser = async (userId, purchaseData) => {
|
||||
where: { id: userId },
|
||||
data: {
|
||||
purchased: {
|
||||
upsert: {
|
||||
where: {
|
||||
userId_courseId_resourceId: {
|
||||
userId: userId,
|
||||
courseId: purchaseData.courseId,
|
||||
resourceId: null,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
courseId: purchaseData.courseId,
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
update: {
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
create: {
|
||||
courseId: purchaseData.courseId,
|
||||
amountPaid: purchaseData.amountPaid,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -13,17 +13,22 @@ export default async function handler(req, res) {
|
||||
try {
|
||||
const { userId, resourceId, amountPaid } = req.body;
|
||||
|
||||
if (!userId || !resourceId || !amountPaid) {
|
||||
return res.status(400).json({ error: 'Missing required fields' });
|
||||
}
|
||||
|
||||
const updatedUser = await addResourcePurchaseToUser(userId, {
|
||||
resourceId,
|
||||
amountPaid: parseInt(amountPaid, 10) // Ensure amountPaid is an integer
|
||||
amountPaid: parseInt(amountPaid, 10)
|
||||
});
|
||||
|
||||
res.status(200).json(updatedUser);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
console.error('Error in resource purchase:', error);
|
||||
res.status(500).json({ error: 'An error occurred while processing the purchase' });
|
||||
}
|
||||
} else {
|
||||
res.setHeader('Allow', ['POST']);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user