mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-17 17:27:52 +03:00
more data in deal endpoint
This commit is contained in:
parent
1ce944033f
commit
386d31e360
@ -6,6 +6,32 @@ import * as Powergate from "~/node_common/powergate";
|
||||
export default async (req, res) => {
|
||||
const response = await Data.getAllDeals();
|
||||
|
||||
let totals = {
|
||||
size: 0,
|
||||
deals: 0,
|
||||
cost: 0,
|
||||
};
|
||||
|
||||
let slingshot = {
|
||||
root: "",
|
||||
total: 0,
|
||||
addresses: [],
|
||||
};
|
||||
|
||||
response.forEach((each) => {
|
||||
total.deals += 1;
|
||||
total.size += each.data.size;
|
||||
total.cost += each.data.totalCostAttoFIL;
|
||||
|
||||
if (!slingshot.addresses.includes(each.data.addr)) {
|
||||
slingshot.total += 1;
|
||||
slingshot.addresses.push(each.data.addr);
|
||||
}
|
||||
});
|
||||
|
||||
totals.costFormatted = Strings.formatAsFilecoinConversion(total.cost);
|
||||
totals.sizeFormatted = Strings.bytesToSize(each.data.size);
|
||||
|
||||
if (!response) {
|
||||
return res.status(500).send({
|
||||
decorator: "V1_GET_ALL_DEALS_ERROR",
|
||||
@ -22,5 +48,7 @@ export default async (req, res) => {
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.send(JSON.stringify({ decorator: "V1_GET_ALL_DEALS", deals: response }, null, 4));
|
||||
.send(
|
||||
JSON.stringify({ decorator: "V1_GET_ALL_DEALS", totals, slingshot, deals: response }, null, 4)
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user