endpoint workzzz
This commit is contained in:
parent
197e90a0f3
commit
9e2af37158
2 changed files with 75 additions and 1 deletions
|
|
@ -234,4 +234,31 @@ router.post(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/publickey-offers',
|
||||||
|
rejectIfNotAuthorizedMiddleware,
|
||||||
|
attachPublicKeyMiddleware,
|
||||||
|
async (req, res) => {
|
||||||
|
console.log('elo');
|
||||||
|
const publicKey = req.cookies.publicKey;
|
||||||
|
|
||||||
|
const offers = await offerService.getOffersByPublicKey(publicKey);
|
||||||
|
|
||||||
|
if (!offers) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: true,
|
||||||
|
message: 'No offers posted by this public key.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offers) {
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: 'Offers found',
|
||||||
|
data: offers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,51 @@ async function createOffer(publicKey, offerDetails) {
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
module.exports = { createOffer };
|
|
||||||
|
async function getOffersByPublicKey(publicKey) {
|
||||||
|
const offers = await OfferCreated.findAll({
|
||||||
|
where: {
|
||||||
|
public_key: publicKey,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(offers);
|
||||||
|
|
||||||
|
if (!offers) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const offersToReturn = [];
|
||||||
|
if (offers) {
|
||||||
|
for (const someOffer of offers) {
|
||||||
|
const offerDetails = await OfferDetailsSet.findOne({
|
||||||
|
where: {
|
||||||
|
offer_uuid: someOffer.uuid,
|
||||||
|
},
|
||||||
|
order: [['created_at', 'DESC']],
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(offerDetails);
|
||||||
|
|
||||||
|
offersToReturn.push({
|
||||||
|
uuid: someOffer.uuid,
|
||||||
|
public_key: someOffer.public_key,
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return offersToReturn;
|
||||||
|
}
|
||||||
|
module.exports = { createOffer, getOffersByPublicKey };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue