Skip to content

Commit

Permalink
refactored tasks and small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Alisson Fabiano <afabiano@eshopworld.com>
  • Loading branch information
esw-afabiano committed Oct 16, 2024
1 parent 7e92b0b commit 8df0d1c
Show file tree
Hide file tree
Showing 23 changed files with 488 additions and 699 deletions.
4 changes: 2 additions & 2 deletions workspaces/copilot/plugins/copilot-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"@types/express": "*",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"joi": "^17.13.3",
"knex": "^3.0.0",
"luxon": "^3.5.0",
"node-fetch": "^2.6.7",
"winston": "^3.2.1",
"yn": "^4.0.0"
"yn": "^4.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@backstage/backend-test-utils": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ResponseError } from '@backstage/errors';
import { Config } from '@backstage/config';
import { Metric, TeamInfo } from '@backstage-community/plugin-copilot-common';
import fetch from 'node-fetch';
import { getGithubInfo, GithubInfo } from '../utils/GithubUtils';
import { getGithubInfo, GithubInfo } from '../utils/githubUtils';

interface GithubApi {
fetchEnterpriseCopilotUsage: () => Promise<Metric[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,6 @@ export class DatabaseHandler {

private constructor(private readonly db: Knex) {}

async getByPeriod(
startDate: string,
endDate: string,
type: MetricsType,
teamName?: string,
): Promise<MetricDbRow[]> {
let query = this.db<MetricDbRow>('metrics').where('type', type);

if (teamName) {
query = query.where('team_name', teamName);
} else {
query = query.whereNull('team_name');
}

const records = await query.whereBetween('day', [startDate, endDate]);

return records ?? [];
}

async getPeriodRange(type: MetricsType): Promise<PeriodRange | undefined> {
const query = this.db<MetricDbRow>('metrics').where('type', type);

Expand Down Expand Up @@ -125,4 +106,22 @@ export class DatabaseHandler {
return undefined;
}
}

async getMetrics(
startDate: string,
endDate: string,
type: MetricsType,
teamName?: string,
): Promise<MetricDbRow[]> {
if (teamName) {
return await this.db<MetricDbRow>('metrics')
.where('type', type)
.where('team_name', teamName)
.whereBetween('day', [startDate, endDate]);
}
return this.db<MetricDbRow>('metrics')
.where('type', type)
.whereNull('team_name')
.whereBetween('day', [startDate, endDate]);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8df0d1c

Please sign in to comment.