From 0e0a094dc87c0ca409f5afe29ebea2f06827460b Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 1 Mar 2025 23:18:18 +0100 Subject: [PATCH] fe can read from back --- src/app.js | 2 ++ src/public/javascript/offers.js | 44 +++++++++++++++++++++++++++++++++ src/services/offerService.js | 4 +-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index 47430d0..adf0dbe 100644 --- a/src/app.js +++ b/src/app.js @@ -24,6 +24,8 @@ app.use('/api', apiRoutes); app.use(express.static(path.join(__dirname, 'public'))); +app.disable('etag'); //avoids 304 responses + app.listen(port, () => { console.log(`Server started on port ${port}`); }); diff --git a/src/public/javascript/offers.js b/src/public/javascript/offers.js index 74b23a6..e3222c6 100644 --- a/src/public/javascript/offers.js +++ b/src/public/javascript/offers.js @@ -172,6 +172,50 @@ async function publishOffer() { toggleCreateOfferControls(); } +class Offer { + constructor(offerData) { + this.uuid = offerData.uuid; + this.public_key = offerData.public_key; + this.wants = offerData.wants; + this.premium = offerData.premium; + this.trade_amount_eur = offerData.trade_amount_eur; + this.location_details = offerData.location_details; + this.time_availability_details = offerData.time_availability_details; + this.show_offer_to_trusted = offerData.show_offer_to_trusted; + this.show_offer_to_trusted_trusted = + offerData.show_offer_to_trusted_trusted; + this.show_offer_to_all_members = offerData.show_offer_to_all_members; + this.is_onchain_accepted = offerData.is_onchain_accepted; + this.is_lightning_accepted = offerData.is_lightning_accepted; + this.are_big_notes_accepted = offerData.are_big_notes_accepted; + this.created_at = offerData.created_at; + this.last_updated_at = offerData.last_updated_at; + } +} + +class MyOffers { + constructor() { + this.offers = []; + } + + async getOffersFromApi() { + const offersResponse = await fetch('/api/publickey-offers'); + + if (!offersResponse.ok) { + this.offers = []; + } + + const offersData = (await offersResponse.json()).data; + if (offersResponse.ok) { + for (const record of offersData) { + this.offers.push(new Offer(record)); + } + } + } + + async render() {} +} + buttonStartCreateOffer.addEventListener('click', () => { toggleCreateOfferControls(); }); diff --git a/src/services/offerService.js b/src/services/offerService.js index 4defc25..b2d557c 100644 --- a/src/services/offerService.js +++ b/src/services/offerService.js @@ -51,8 +51,6 @@ async function getOffersByPublicKey(publicKey) { order: [['created_at', 'DESC']], }); - console.log(offerDetails); - offersToReturn.push({ uuid: someOffer.uuid, public_key: someOffer.public_key, @@ -68,6 +66,8 @@ async function getOffersByPublicKey(publicKey) { 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: someOffer.created_at, + last_updated_at: offerDetails.created_at, }); } }