From 47ad10629ec82e8ce7422ef43fc72a832f677668 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Fri, 15 Oct 2021 11:08:30 +0200 Subject: [PATCH] Used correct methods for reading/writing to db no-issue Using `save` was a placeholder and isn't the correct way to interact with our model layer. --- ghost/offers/lib/application/OfferRepository.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ghost/offers/lib/application/OfferRepository.js b/ghost/offers/lib/application/OfferRepository.js index d23174a628..316126c87f 100644 --- a/ghost/offers/lib/application/OfferRepository.js +++ b/ghost/offers/lib/application/OfferRepository.js @@ -150,7 +150,8 @@ class OfferRepository { * @returns {Promise} */ async save(offer, options) { - const model = this.OfferModel.forge({ + /** @type any */ + const data = { id: offer.id, name: offer.name.value, code: offer.code.value, @@ -164,7 +165,7 @@ class OfferRepository { duration_in_months: offer.duration.value.type === 'repeating' ? offer.duration.value.months : null, currency: offer.currency ? offer.currency.value : null, active: offer.status.equals(OfferStatus.create('active')) - }); + }; if (offer.codeChanged || offer.isNew) { const event = OfferCodeChangeEvent.create({ @@ -194,10 +195,10 @@ class OfferRepository { } const couponData = await this.stripeAPIService.createCoupon(coupon); - model.set('stripe_coupon_id', couponData.id); - await model.save(null, {method: 'insert', ...options}); + data.stripe_coupon_id = couponData.id; + await this.OfferModel.add(data, options); } else { - await model.save(null, {method: 'update', ...options}); + await this.OfferModel.edit(data, {...options, id: data.id}); } } }