Skip to content

Commit 22dd123

Browse files
committed
Add ack POST/GET calls
1 parent 9b9d6c7 commit 22dd123

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/controllers/api.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface Consignment {
99
_id?: string;
1010
filename: string;
1111
blindedutxo: string;
12+
ack?: boolean;
1213
}
1314

1415
let ds = Datastore.create();
@@ -47,4 +48,44 @@ export const loadApiEndpoints = (app: Application): void => {
4748
res.status(500).send({ success: false });
4849
}
4950
});
51+
52+
app.post("/ack", async (req: Request, res: Response) => {
53+
try {
54+
if (!req.body.blindedutxo) {
55+
return res.status(500).send({ success: false });
56+
}
57+
let c: Consignment | null = await ds.findOne({ blindedutxo: req.body.blindedutxo });
58+
if (!c) {
59+
return res.status(500).send({ success: false });
60+
}
61+
await ds.update({ blindedutxo: req.body.blindedutxo }, { $set: { ack: true } }, { multi: false });
62+
c = await ds.findOne({ blindedutxo: req.body.blindedutxo });
63+
64+
return res.status(200).send({ success: true });
65+
} catch (error) {
66+
res.status(500).send({ success: false });
67+
}
68+
});
69+
70+
app.get("/ack", async (req: Request, res: Response) => {
71+
try {
72+
if (!!req.query.blindedutxo) {
73+
const c: Consignment | null = await ds.findOne({ blindedutxo: req.query.blindedutxo });
74+
75+
if (!c) {
76+
return res.status(500).send({ success: false });
77+
}
78+
const ack = !!c.ack;
79+
80+
return res.status(200).send({
81+
success: true,
82+
ack,
83+
});
84+
}
85+
86+
res.status(500).send({ success: false });
87+
} catch (error) {
88+
res.status(500).send({ success: false });
89+
}
90+
});
5091
};

test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)