use service to create offer

This commit is contained in:
Pablo Martin 2025-03-31 16:12:33 +02:00
parent e046c8c118
commit 873493f697
3 changed files with 20 additions and 9 deletions

View file

@ -10,13 +10,16 @@ const TrustCheckboxes = require('../components/TrustCheckboxes');
const BigNotesCheckbox = require('../components/BigNotesCheckbox'); const BigNotesCheckbox = require('../components/BigNotesCheckbox');
const PopupNotification = require('../components/PopupNotification'); const PopupNotification = require('../components/PopupNotification');
const offerService = require('../services/offerService');
class CreateOfferModal { class CreateOfferModal {
// Actual creation logic to be provided by a service // Actual creation logic to be provided by a service
// Stop relying on IDs // Stop relying on IDs
constructor({ parentElement, onCreationCallback }) { constructor({ parentElement, onCreationCallback, offerService }) {
this.element = null; this.element = null;
this.parentElement = parentElement; this.parentElement = parentElement;
this.onCreationCallback = onCreationCallback; this.onCreationCallback = onCreationCallback;
this.offerService = offerService;
this.publishOfferButton = null; this.publishOfferButton = null;
this.buyOrSellButtonGroup = null; this.buyOrSellButtonGroup = null;
@ -230,13 +233,7 @@ class CreateOfferModal {
are_big_notes_accepted, are_big_notes_accepted,
}; };
await fetch('/api/offer', { await this.offerService.createOffer(offerDetails);
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ offerDetails }),
});
this.toggle(); this.toggle();
} }
@ -262,6 +259,7 @@ function offersPage() {
await myOffers.render(); await myOffers.render();
offerCreatedPopup.displayTemporarily(3000); offerCreatedPopup.displayTemporarily(3000);
}, },
offerService: offerService,
}); });
createOfferModal.render(); createOfferModal.render();
// ----------- // -----------

View file

@ -0,0 +1,13 @@
const createOffer = async (offerDetails) => {
await fetch('/api/offer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ offerDetails }),
});
};
module.exports = {
createOffer,
};