mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03: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:
parent
c2f85d3742
commit
47ad10629e
@ -150,7 +150,8 @@ class OfferRepository {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user