more data in deal endpoint

This commit is contained in:
@wwwjim 2020-10-19 11:02:10 -07:00
parent 1ce944033f
commit 386d31e360

View File

@ -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)
);
};