Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/handler/analysis/analysisHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
calculateAnalysis: (
params: AnalysisHandlerParams<T, U, V>,
ctx: AnalysisContext,
) => Promise<any>;

Check warning on line 42 in src/handler/analysis/analysisHandler.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected any. Specify a different type
usesDataSource: boolean;
shouldCache: boolean;
};
Expand Down Expand Up @@ -120,7 +120,7 @@
context,
);

res.set('X-Lovat-Cache','miss');
res.set("X-Lovat-Cache", "miss");
res.status(200).send(calculatedAnalysis.error ?? calculatedAnalysis);

try {
Expand All @@ -143,7 +143,7 @@
return;
}
} else {
res.set('X-Lovat-Cache','hit');
res.set("X-Lovat-Cache", "hit");
res.status(200).send(JSON.parse(cacheRow.toString()));
}
} catch (error) {
Expand Down
23 changes: 22 additions & 1 deletion src/handler/analysis/teamLookUp/breakdownMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import z from "zod";
import prismaClient from "../../../prismaClient.js";
import { nonEventMetric } from "../coreAnalysis/nonEventMetric.js";
import {
lowercaseToBreakdown,
Expand All @@ -22,7 +23,27 @@ export const breakdownMetrics = createAnalysisHandler({
};
},
calculateAnalysis: async ({ params }, ctx) => {
const result = {};
const teamRow = await prismaClient.team.findUnique({
where: { number: params.team },
select: { number: true },
});

if (!teamRow) {
return { error: "TEAM_DOES_NOT_EXIST" };
}

const reportCount = await prismaClient.scoutReport.count({
where: {
teamMatchData: {
teamNumber: params.team,
},
},
});
if (reportCount === 0) {
return { error: "NO_DATA_FOR_TEAM" };
}

const result: Record<string, any> = {};
for (const [key, metric] of Object.entries(lowercaseToBreakdown)) {
const data = await nonEventMetric(ctx.user, {
team: params.team,
Expand Down
26 changes: 24 additions & 2 deletions src/handler/analysis/teamLookUp/categoryMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import z from "zod";
import prismaClient from "../../../prismaClient.js";
import { metricsCategory, metricToName } from "../analysisConstants.js";
import { averageManyFast } from "../coreAnalysis/averageManyFast.js";
import { createAnalysisHandler } from "../analysisHandler.js";
Expand All @@ -9,6 +10,7 @@ export const categoryMetrics = createAnalysisHandler({
team: z.preprocess((x) => Number(x), z.number()),
}),
},

usesDataSource: true,
shouldCache: true,
createKey: ({ params }) => {
Expand All @@ -19,9 +21,29 @@ export const categoryMetrics = createAnalysisHandler({
};
},
calculateAnalysis: async ({ params }, ctx) => {
const result = {};
const teamRow = await prismaClient.team.findUnique({
where: { number: params.team },
select: { number: true },
});

if (!teamRow) {
return { error: "TEAM_DOES_NOT_EXIST" };
}

const reportCount = await prismaClient.scoutReport.count({
where: {
teamMatchData: {
teamNumber: params.team,
},
},
});

if (reportCount === 0) {
return { error: "NO_DATA_FOR_TEAM" };
}

const result: Record<string, any> = {};

//update if statments in arrayAndAverage if the metric needs to look at scoutReport instead of events table
const data = await averageManyFast(ctx.user, {
teams: [params.team],
metrics: metricsCategory,
Expand Down
22 changes: 20 additions & 2 deletions src/handler/analysis/teamLookUp/getNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ export const getNotes = createAnalysisHandler({
};
},
calculateAnalysis: async ({ params }, ctx) => {
const teamRow = await prismaClient.team.findUnique({
where: { number: params.team },
select: { number: true },
});

if (!teamRow) {
return { error: "TEAM_DOES_NOT_EXIST" };
}

const reportCount = await prismaClient.scoutReport.count({
where: {
teamMatchData: {
teamNumber: params.team,
},
},
});
if (reportCount === 0) {
return { error: "NO_DATA_FOR_TEAM" };
}

let notesAndMatches: {
notes: string;
match: string;
Expand All @@ -30,7 +50,6 @@ export const getNotes = createAnalysisHandler({
scouterName?: string;
}[];

// Set up filters to decrease server load
const sourceTnmtFilter = dataSourceRuleToPrismaFilter(
dataSourceRuleSchema(z.string()).parse(ctx.user.tournamentSourceRule),
);
Expand Down Expand Up @@ -71,7 +90,6 @@ export const getNotes = createAnalysisHandler({
},
},
orderBy: [
// Ordered by most recent first
{ teamMatchData: { tournament: { date: "desc" } } },
{ teamMatchData: { matchType: "desc" } },
{ teamMatchData: { matchNumber: "desc" } },
Expand Down
2 changes: 1 addition & 1 deletion src/handler/manager/getScouters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import z from "zod";

export const getScouters = async (
req: AuthenticatedRequest,
res: Response
res: Response,
): Promise<void> => {
try {
const params = z
Expand Down
2 changes: 1 addition & 1 deletion src/handler/manager/getScoutersOnTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import z from "zod";

export const getScoutersOnTeam = async (
req: Request,
res: Response
res: Response,
): Promise<void> => {
try {
console.log(req.headers);
Expand Down
4 changes: 2 additions & 2 deletions src/handler/manager/scoutingLeadProgressPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AuthenticatedRequest } from "../../lib/middleware/requireAuth.js";

export const scoutingLeadProgressPage = async (
req: AuthenticatedRequest,
res: Response
res: Response,
): Promise<void> => {
try {
const params = z
Expand Down Expand Up @@ -147,7 +147,7 @@ export const scoutingLeadProgressPage = async (
matchesScouted: matchesScoutedAtTournament.length,
missedMatches: Math.max(
0,
totalAssignedScouterMatches - matchesScoutedAtTournament.length
totalAssignedScouterMatches - matchesScoutedAtTournament.length,
),
};
result.push(currData);
Expand Down
2 changes: 1 addition & 1 deletion src/handler/slack/addSlackWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const addSlackWorkspace = async (

if (!teamRow) {
res.status(404).send("Team not found");
return
return;
}

await prismaClient.slackWorkspace.upsert({
Expand Down
44 changes: 22 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ app.post(
"/v1/slack/command",
express.urlencoded({ extended: true }),
requireSlackToken,
processCommand
processCommand,
);

app.post("/v1/slack/event", requireSlackToken, processEvent);

app.post(
"/v1/manager/onboarding/verifyemail",
requireLovatSignature,
approveTeamEmail
approveTeamEmail,
); //tested

// Log requests
Expand All @@ -158,12 +158,12 @@ app.use(posthogReporter);
app.get(
"/v1/manager/tournament/:tournament/teams",
requireAuth,
getTeamsInTournament
getTeamsInTournament,
);
app.get(
"/v1/manager/tournament/:tournament/rankedTeams",
requireAuth,
getTeamRankings
getTeamRankings,
);
app.get("/v1/manager/teams", requireAuth, getTeams); //tested
app.get("/v1/manager/tournaments", requireAuth, getTournaments); //tested
Expand All @@ -181,7 +181,7 @@ app.get("/v1/manager/scoutreports/:uuid", getScoutReport); //tested
app.post(
"/v1/manager/tournament/:tournament/scoutershifts",
requireAuth,
addScouterShift
addScouterShift,
); //tested , expecting only 1 at a time
// app.get('/manager/tournament/:tournament/scoutershifts',requireAuth, getScouterSchedule) //tested
app.post("/v1/manager/scoutershifts/:uuid", requireAuth, updateScouterShift); //tested
Expand All @@ -200,18 +200,18 @@ app.post("/v1/manager/mutablepicklists", requireAuth, addMutablePicklist); // te
app.delete(
"/v1/manager/mutablepicklists/:uuid",
requireAuth,
deleteMutablePicklist
deleteMutablePicklist,
); //tested
app.get("/v1/manager/mutablepicklists", requireAuth, getMutablePicklists); //tested
app.get(
"/v1/manager/mutablepicklists/:uuid",
requireAuth,
getSingleMutablePicklist
getSingleMutablePicklist,
); //tested
app.put(
"/v1/manager/mutablepicklists/:uuid",
requireAuth,
updateMutablePicklist
updateMutablePicklist,
); //tested

// Also it would be nice to have an endpoint to subscribe to a mutable picklist, so that the client can get updates when it changes
Expand All @@ -221,34 +221,34 @@ app.put(
app.get(
"/v1/manager/registeredteams/:team/registrationstatus",
requireAuth,
checkRegisteredTeam
checkRegisteredTeam,
); //tested
app.post("/v1/manager/onboarding/username", requireAuth, addUsername); //tested
app.post("/v1/manager/onboarding/teamcode", requireAuth, checkCode); //tested
app.post("/v1/manager/settings/teamsource", requireAuth, addTeamSource); //tested
app.post(
"/v1/manager/settings/tournamentsource",
requireAuth,
addTournamentSource
addTournamentSource,
);
app.post("/v1/manager/onboarding/team", requireAuth, addRegisteredTeam); //tested, is the link correct?
app.post(
"/v1/manager/registeredteams/:team/approve",
requireLovatSignature,
approveRegisteredTeam
approveRegisteredTeam,
); //tested waiting for new middle ware
app.post(
"/v1/manager/registeredteams/:team/reject",
requireLovatSignature,
rejectRegisteredTeam
rejectRegisteredTeam,
); // tested, waiting for new middle ware
app.post("/v1/manager/onboarding/teamwebsite", requireAuth, addWebsite); //tested

app.post(
"/v1/manager/onboarding/resendverificationemail",
resendEmailLimiter,
requireAuth,
resendEmail
resendEmail,
); //tested
app.get("/v1/manager/profile", requireAuth, getProfile); //tested
app.get("/v1/manager/users", requireAuth, getUsers); //tested
Expand All @@ -263,27 +263,27 @@ app.get("/v1/manager/settings/teamsource", requireAuth, getTeamSource);
app.get(
"/v1/manager/settings/tournamentsource",
requireAuth,
getTournamentSource
getTournamentSource,
);
app.put(
"/v1/manager/settings/teamemail",
updateTeamEmails,
requireAuth,
updateTeamEmail
updateTeamEmail,
);

//scouting lead information/QR codes
app.get("/v1/manager/code", requireAuth, getTeamCode);
app.get(
"/v1/manager/tournament/:tournament/scoutershifts",
requireAuth,
getScouterSchedule
getScouterSchedule,
); //tested

app.post(
"/v1/manager/dashboard/scoutreport",
requireAuth,
addScoutReportDashboard
addScoutReportDashboard,
);

//scouter onboarding
Expand All @@ -310,7 +310,7 @@ app.get("/v1/analysis/breakdown/team/:team", requireAuth, breakdownMetrics); //t
app.get(
"/v1/analysis/breakdown/team/:team/:breakdown",
requireAuth,
breakdownDetails
breakdownDetails,
);
app.get("/v1/analysis/notes/team/:team", requireAuth, getNotes); //tested
app.get("/v1/analysis/flag/team/:team", requireAuth, multipleFlags); //tested
Expand All @@ -334,17 +334,17 @@ app.get("/v1/manager/scouterreports", requireAuth, scouterScoutReports);
app.get(
"/v1/analysis/metrics/scoutreport/:uuid",
requireAuth,
matchPageSpecificScouter
matchPageSpecificScouter,
);
app.get(
"/v1/analysis/scoutreports/match/:match",
requireAuth,
scoutReportForMatch
scoutReportForMatch,
);
app.get(
"/v1/analysis/timeline/scoutreport/:uuid",
requireAuth,
timelineForScoutReport
timelineForScoutReport,
);

//pit scouting
Expand All @@ -361,7 +361,7 @@ app.get("/v1/analysis/reportcsv", requireAuth, getReportCSV);
app.get(
"/v1/manager/team-tournament-status",
requireAuth,
getTeamTournamentStatus
getTeamTournamentStatus,
);

// match results from scouting reports
Expand Down
2 changes: 1 addition & 1 deletion src/lib/middleware/posthogMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const posthogReporter = async (
$set: userProps,
$pathname: req.route?.path,
method: req.method,
cache: res.getHeader('X-Lovat-Cache'),
cache: res.getHeader("X-Lovat-Cache"),
path: req.path,
query: req.query,
reqBody: req.body,
Expand Down
Loading