Skip to content

Commit

Permalink
feat: offer tweaks and RESTful compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Jul 18, 2024
1 parent 8b8da07 commit 0756fc9
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/controllers/offer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ export const commitImportedOfferFile = async (req, res) => {

const response = await datalayer.takeOffer(JSON.parse(offerFile.metaValue));

res.json({
message: 'Offer Accepted.',
tradeId: response.trade_id,
success: true,
});

await Meta.destroy({
where: {
metaKey: 'activeOffer',
},
});

res.json({
message: 'Offer Accepted.',
tradeId: response.trade_id,
success: true,
});
} catch (error) {
res.status(400).json({
message: 'Can not commit offer.',
Expand All @@ -160,6 +160,11 @@ export const cancelImportedOfferFile = async (req, res) => {
metaKey: 'activeOffer',
},
});

res.json({
message: 'Offer Cancelled',
success: true,
});
} catch (error) {
res.status(400).json({
message: 'Can not cancel offer.',
Expand All @@ -171,7 +176,15 @@ export const cancelImportedOfferFile = async (req, res) => {

export const getCurrentOfferInfo = async (req, res) => {
try {
await assertActiveOfferFile();
try {
await assertActiveOfferFile();
} catch (error) {
res.status(200).json({
message: 'No offer to accept',
success: true,
});
return;
}

const offerFileJson = await Meta.findOne({
where: { metaKey: 'activeOffer' },
Expand Down Expand Up @@ -231,9 +244,9 @@ export const getCurrentOfferInfo = async (req, res) => {
maker,
taker,
},
success: true,
});
} catch (error) {
console.trace(error);
res.status(400).json({
message: 'Can not get offer.',
error: error.message,
Expand Down

0 comments on commit 0756fc9

Please sign in to comment.