Skip to content

Commit

Permalink
Add total count on provider deployments endpoint (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x authored Dec 12, 2023
1 parent 707050d commit 50181c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 13 additions & 0 deletions api/src/db/deploymentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ export async function getDeploymentRelatedMessages(owner: string, dseq: string)
}));
}

export async function getProviderDeploymentsCount(provider: string, status?: "active" | "closed") {
let leaseFilter = { providerAddress: provider };
if (status) {
leaseFilter["closedHeight"] = status === "active" ? null : { [Op.ne]: null };
}

const result = await Deployment.count({
include: [{ model: Lease, attributes: [], required: true, where: leaseFilter }]
});

return result;
}

export async function getProviderDeployments(provider: string, skip: number, limit: number, status?: "active" | "closed") {
let leaseFilter = { providerAddress: provider };

Expand Down
12 changes: 9 additions & 3 deletions api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import axios from "axios";
import { getMarketData } from "@src/providers/marketDataProvider";
import { getAuditors, getProviderAttributesSchema } from "@src/providers/githubProvider";
import { getProviderRegions } from "@src/db/providerDataProvider";
import { getProviderDeployments } from "@src/db/deploymentProvider";
import { getProviderDeployments, getProviderDeploymentsCount } from "@src/db/deploymentProvider";

export const apiRouter = express.Router();

Expand Down Expand Up @@ -205,9 +205,15 @@ apiRouter.get(
return;
}

const deployments = await getProviderDeployments(req.params.provider, skip, limit, statusParam);
const deploymentCountQuery = getProviderDeploymentsCount(req.params.provider, statusParam);
const deploymentsQuery = getProviderDeployments(req.params.provider, skip, limit, statusParam);

res.send(deployments);
const [deploymentCount, deployments] = await Promise.all([deploymentCountQuery, deploymentsQuery]);

res.send({
total: deploymentCount,
deployments: deployments
});
})
);

Expand Down

0 comments on commit 50181c0

Please sign in to comment.