offer service makes transaction for offer creation
This commit is contained in:
parent
3b995dfc70
commit
d19c057937
2 changed files with 37 additions and 23 deletions
|
|
@ -44,6 +44,7 @@ class ServicesProvider {
|
||||||
const offerService = new OfferServiceProvider({
|
const offerService = new OfferServiceProvider({
|
||||||
models: this.models,
|
models: this.models,
|
||||||
errors: this.errors,
|
errors: this.errors,
|
||||||
|
sequelize: this.sequelize,
|
||||||
}).provide();
|
}).provide();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,26 @@
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
|
|
||||||
class OfferServiceProvider {
|
class OfferServiceProvider {
|
||||||
constructor({ models, errors }) {
|
constructor({ models, errors, sequelize }) {
|
||||||
this.models = models;
|
this.models = models;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
|
this.sequelize = sequelize;
|
||||||
}
|
}
|
||||||
provide() {
|
provide() {
|
||||||
const createOffer = async (publicKey, offerDetails) => {
|
const createOffer = async (publicKey, offerDetails) => {
|
||||||
const offerCreated = await this.models.OfferCreated.create({
|
const createOfferTransaction = await this.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
const offerCreated = await this.models.OfferCreated.create(
|
||||||
|
{
|
||||||
uuid: uuid.v7(),
|
uuid: uuid.v7(),
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
},
|
||||||
|
{ transaction: createOfferTransaction }
|
||||||
|
);
|
||||||
|
|
||||||
await this.models.OfferDetailsSet.create({
|
await this.models.OfferDetailsSet.create(
|
||||||
|
{
|
||||||
uuid: uuid.v7(),
|
uuid: uuid.v7(),
|
||||||
offer_uuid: offerCreated.uuid,
|
offer_uuid: offerCreated.uuid,
|
||||||
wants: offerDetails.wants,
|
wants: offerDetails.wants,
|
||||||
|
|
@ -29,7 +36,13 @@ class OfferServiceProvider {
|
||||||
is_lightning_accepted: offerDetails.is_lightning_accepted,
|
is_lightning_accepted: offerDetails.is_lightning_accepted,
|
||||||
are_big_notes_accepted: offerDetails.are_big_notes_accepted,
|
are_big_notes_accepted: offerDetails.are_big_notes_accepted,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
},
|
||||||
|
{ transaction: createOfferTransaction }
|
||||||
|
);
|
||||||
|
await createOfferTransaction.commit();
|
||||||
|
} catch (error) {
|
||||||
|
await createOfferTransaction.rollback();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteOffer = async (offerUuid) => {
|
const deleteOffer = async (offerUuid) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue