Skip to content

Commit

Permalink
feat: fixed billing report
Browse files Browse the repository at this point in the history
  • Loading branch information
vklimontovich committed Dec 11, 2023
1 parent 32149f8 commit e19b326
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 1 addition & 2 deletions webapps/ee-api/pages/api/report/overage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ const handler = async function handler(req: NextApiRequest, res: NextApiResponse
const allInvoices = await listAllInvoices();
const allCustomers = new Set(allWorkspaces.map(w => w.obj.stripeCustomerId));
const eligibleInvoices = allInvoices.filter(i => allCustomers.has(i.customer)).filter(i => i.lines.data.length > 0);
getLog().atInfo().log(`Found ${eligibleInvoices.length} invoices for ${allCustomers.size} workspaces`);
const minDate = eligibleInvoices.map(i => getInvoiceStartDate(i)).sort()[0];
const minDate = eligibleInvoices.map(i => getInvoiceStartDate(i)).sort((a, b) => a.getTime() - b.getTime())[0];

const timer = Date.now();
const report = await buildWorkspaceReport(minDate.toISOString(), new Date().toISOString(), "day", workspaceId);
Expand Down
21 changes: 12 additions & 9 deletions webapps/ee-api/pages/api/report/workspace-stat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { namedParameters, SqlQueryParameters, unrollParams } from "juava";
import { getLog, namedParameters, SqlQueryParameters, unrollParams } from "juava";
import { withErrorHandler } from "../../../lib/error-handler";
import { auth } from "../../../lib/auth";
import { clickhouse, pg } from "../../../lib/services";
Expand Down Expand Up @@ -59,20 +59,23 @@ async function getClickhousePart({
workspaceId ? "and workspaceId = {workspaceId:String}" : ""
}
group by period, workspaceId
order by period desc;
order by period desc, workspaceId desc;
`;
//getLog().atInfo().log(`Running Clickhouse query: ${query}`);
const queryParams = removeUndefined({
start: isoDateTOClickhouse(start),
end: isoDateTOClickhouse(end),
granularity,
workspaceId,
});
// getLog()
// .atDebug()
// .log(`Running Clickhouse query with ${JSON.stringify(queryParams)} : ${query}`);
const resultSet = await clickhouse.query({
query,
clickhouse_settings: {
wait_end_of_query: 1,
},
query_params: removeUndefined({
start: isoDateTOClickhouse(start),
end: isoDateTOClickhouse(end),
granularity,
workspaceId,
}),
query_params: queryParams,
});
log.atInfo().log(`Clickhouse query took ${Date.now() - timer}ms`);

Expand Down

1 comment on commit e19b326

@vercel
Copy link

@vercel vercel bot commented on e19b326 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

new-jitsu-ee-api – ./webapps/ee-api

onetag-ee-api.vercel.app
new-jitsu-ee-api-git-newjitsu-jitsu.vercel.app
ee.jitsu.dev
new-jitsu-ee-api-jitsu.vercel.app

Please sign in to comment.