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({
|
||||
models: this.models,
|
||||
errors: this.errors,
|
||||
sequelize: this.sequelize,
|
||||
}).provide();
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,35 +1,48 @@
|
|||
const uuid = require('uuid');
|
||||
|
||||
class OfferServiceProvider {
|
||||
constructor({ models, errors }) {
|
||||
constructor({ models, errors, sequelize }) {
|
||||
this.models = models;
|
||||
this.errors = errors;
|
||||
this.sequelize = sequelize;
|
||||
}
|
||||
provide() {
|
||||
const createOffer = async (publicKey, offerDetails) => {
|
||||
const offerCreated = await this.models.OfferCreated.create({
|
||||
uuid: uuid.v7(),
|
||||
public_key: publicKey,
|
||||
created_at: new Date().toISOString(),
|
||||
});
|
||||
const createOfferTransaction = await this.sequelize.transaction();
|
||||
try {
|
||||
const offerCreated = await this.models.OfferCreated.create(
|
||||
{
|
||||
uuid: uuid.v7(),
|
||||
public_key: publicKey,
|
||||
created_at: new Date().toISOString(),
|
||||
},
|
||||
{ transaction: createOfferTransaction }
|
||||
);
|
||||
|
||||
await this.models.OfferDetailsSet.create({
|
||||
uuid: uuid.v7(),
|
||||
offer_uuid: offerCreated.uuid,
|
||||
wants: offerDetails.wants,
|
||||
premium: offerDetails.premium,
|
||||
trade_amount_eur: offerDetails.trade_amount_eur,
|
||||
location_details: offerDetails.location_details,
|
||||
time_availability_details: offerDetails.time_availability_details,
|
||||
show_offer_to_trusted: offerDetails.show_offer_to_trusted,
|
||||
show_offer_to_trusted_trusted:
|
||||
offerDetails.show_offer_to_trusted_trusted,
|
||||
show_offer_to_all_members: offerDetails.show_offer_to_all_members,
|
||||
is_onchain_accepted: offerDetails.is_onchain_accepted,
|
||||
is_lightning_accepted: offerDetails.is_lightning_accepted,
|
||||
are_big_notes_accepted: offerDetails.are_big_notes_accepted,
|
||||
created_at: new Date().toISOString(),
|
||||
});
|
||||
await this.models.OfferDetailsSet.create(
|
||||
{
|
||||
uuid: uuid.v7(),
|
||||
offer_uuid: offerCreated.uuid,
|
||||
wants: offerDetails.wants,
|
||||
premium: offerDetails.premium,
|
||||
trade_amount_eur: offerDetails.trade_amount_eur,
|
||||
location_details: offerDetails.location_details,
|
||||
time_availability_details: offerDetails.time_availability_details,
|
||||
show_offer_to_trusted: offerDetails.show_offer_to_trusted,
|
||||
show_offer_to_trusted_trusted:
|
||||
offerDetails.show_offer_to_trusted_trusted,
|
||||
show_offer_to_all_members: offerDetails.show_offer_to_all_members,
|
||||
is_onchain_accepted: offerDetails.is_onchain_accepted,
|
||||
is_lightning_accepted: offerDetails.is_lightning_accepted,
|
||||
are_big_notes_accepted: offerDetails.are_big_notes_accepted,
|
||||
created_at: new Date().toISOString(),
|
||||
},
|
||||
{ transaction: createOfferTransaction }
|
||||
);
|
||||
await createOfferTransaction.commit();
|
||||
} catch (error) {
|
||||
await createOfferTransaction.rollback();
|
||||
}
|
||||
};
|
||||
|
||||
const deleteOffer = async (offerUuid) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue