From 92bf38c60fc47a4e975eaeebfc7e96efeab28928 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Mon, 20 Jun 2022 17:11:26 -0400 Subject: [PATCH] Update PNID through direct query --- src/routers/account.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/routers/account.js b/src/routers/account.js index e1f13a8..0828b5e 100644 --- a/src/routers/account.js +++ b/src/routers/account.js @@ -620,24 +620,25 @@ router.post('/stripe-wh', express.raw({ type: 'application/json' }), async (requ const product = await stripe.products.retrieve(subscription.plan.product); const customer = await stripe.customers.retrieve(subscription.customer); const pid = Number(customer.metadata.pnid_pid); - const pnid = await database.PNID.findOne({ pid }); + + const updateData = {}; if (product.metadata.beta === 'true') { switch (subscription.status) { case 'active': - pnid.access_level = 1; + updateData.access_level = 1; break; case 'canceled': // Subscription was cancled case 'unpaid': // User missed too many payments - pnid.access_level = 0; + updateData.access_level = 0; break; default: break; } - await pnid.save(); + await database.PNID.updateOne({ pid }, { $set: updateData }, { upsert: true }).exec(); } }