mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Wrapped product repo methods in transactions
refs https://github.com/TryGhost/Team/issues/982 This ensures that we will not commit any rows to the database if something is to go wrong with a Stripe API request.
This commit is contained in:
parent
dc79f04989
commit
dd4d6aeae5
1 changed files with 34 additions and 0 deletions
|
@ -49,6 +49,14 @@ class ProductRepository {
|
|||
* @returns {Promise<ProductModel>}
|
||||
*/
|
||||
async get(data, options) {
|
||||
if (!options.transacting) {
|
||||
return this._Product.transaction((transacting) => {
|
||||
return this.get(data, {
|
||||
...options,
|
||||
transacting
|
||||
});
|
||||
});
|
||||
}
|
||||
if ('stripe_product_id' in data) {
|
||||
const stripeProduct = await this._StripeProduct.findOne({
|
||||
stripe_product_id: data.stripe_product_id
|
||||
|
@ -115,6 +123,15 @@ class ProductRepository {
|
|||
});
|
||||
}
|
||||
|
||||
if (!options.transacting) {
|
||||
return this._Product.transaction((transacting) => {
|
||||
return this.create(data, {
|
||||
...options,
|
||||
transacting
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const productData = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
|
@ -241,6 +258,15 @@ class ProductRepository {
|
|||
});
|
||||
}
|
||||
|
||||
if (!options.transacting) {
|
||||
return this._Product.transaction((transacting) => {
|
||||
return this.update(data, {
|
||||
...options,
|
||||
transacting
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const productData = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
|
@ -464,6 +490,14 @@ class ProductRepository {
|
|||
* @returns {Promise<{data: ProductModel[], meta: object}>}
|
||||
**/
|
||||
async list(options) {
|
||||
if (!options.transacting) {
|
||||
return this._Product.transaction((transacting) => {
|
||||
return this.list({
|
||||
...options,
|
||||
transacting
|
||||
});
|
||||
});
|
||||
}
|
||||
return this._Product.findPage(options);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue