0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

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.
This commit is contained in:
Fabien O'Carroll 2021-10-15 11:08:30 +02:00
parent c2f85d3742
commit 47ad10629e

View file

@ -150,7 +150,8 @@ class OfferRepository {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async save(offer, options) { async save(offer, options) {
const model = this.OfferModel.forge({ /** @type any */
const data = {
id: offer.id, id: offer.id,
name: offer.name.value, name: offer.name.value,
code: offer.code.value, code: offer.code.value,
@ -164,7 +165,7 @@ class OfferRepository {
duration_in_months: offer.duration.value.type === 'repeating' ? offer.duration.value.months : null, duration_in_months: offer.duration.value.type === 'repeating' ? offer.duration.value.months : null,
currency: offer.currency ? offer.currency.value : null, currency: offer.currency ? offer.currency.value : null,
active: offer.status.equals(OfferStatus.create('active')) active: offer.status.equals(OfferStatus.create('active'))
}); };
if (offer.codeChanged || offer.isNew) { if (offer.codeChanged || offer.isNew) {
const event = OfferCodeChangeEvent.create({ const event = OfferCodeChangeEvent.create({
@ -194,10 +195,10 @@ class OfferRepository {
} }
const couponData = await this.stripeAPIService.createCoupon(coupon); const couponData = await this.stripeAPIService.createCoupon(coupon);
model.set('stripe_coupon_id', couponData.id); data.stripe_coupon_id = couponData.id;
await model.save(null, {method: 'insert', ...options}); await this.OfferModel.add(data, options);
} else { } else {
await model.save(null, {method: 'update', ...options}); await this.OfferModel.edit(data, {...options, id: data.id});
} }
} }
} }