-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoll-problem.ts
More file actions
124 lines (98 loc) · 2.87 KB
/
Copy pathpoll-problem.ts
File metadata and controls
124 lines (98 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { PrismaClient } from "../../gp-api/node_modules/@prisma/client";
import { S3 } from "@aws-sdk/client-s3";
import { input as getInput } from "@inquirer/prompts";
import { searchGrafanaLogs } from "../utils/grafana";
const prisma = new PrismaClient();
const s3 = new S3({ region: "us-west-2" });
const getUserFromPoll = async (pollId: string) => {
const poll = await prisma.poll.findUniqueOrThrow({
where: { id: pollId },
});
const electedOffice = await prisma.electedOffice.findUniqueOrThrow({
where: { id: poll.electedOfficeId! },
});
const user = await prisma.user.findUniqueOrThrow({
where: { id: electedOffice.userId! },
});
return user;
};
const getUser = async (input: string) => {
if (input.length === 36) {
console.log("Detected poll id, finding user");
return getUserFromPoll(input);
}
if (input.includes("@")) {
return prisma.user.findUniqueOrThrow({
where: { email: input },
});
}
const campaign = await prisma.campaign.findFirstOrThrow({
where: { slug: input },
});
return prisma.user.findFirstOrThrow({
where: {
id: campaign.userId,
},
});
};
export default async () => {
const input =
process.argv.at(3) ??
(await getInput({
message: "Enter any of the following: email, campaign slug, or poll id",
default: process.argv.at(3),
}));
console.log("Input:", input);
const user = await getUser(input);
console.log("Found user id:", user.id);
console.log("Found user email:", user.email);
const org = await prisma.organization.findFirstOrThrow({
where: {
ownerId: user.id,
},
});
console.log("Found org:", org);
const campaign = await prisma.campaign.findFirstOrThrow({
where: {
userId: user.id,
},
});
console.log("Found campaign id:", campaign.id);
const electedOffice = await prisma.electedOffice.findFirst({
where: {
userId: user.id,
},
});
if (!electedOffice) {
console.log("No elected office found");
return;
}
console.log("Found elected office id:", electedOffice.id);
const polls = await prisma.poll.findMany({
where: {
electedOfficeId: electedOffice.id,
},
});
console.log("Found polls:", polls.length);
for (const poll of polls) {
console.log(poll);
const res = await s3.listObjectsV2({
Bucket: "tevyn-poll-csvs-master",
Prefix: poll.id,
});
console.log();
console.log(`Has CSV: ${!!res.Contents?.length}`);
console.log("");
const grafanaLogs = await searchGrafanaLogs(
`{service_name="gp-api"} |= "Message processing failed" |= "${poll.id}"`
);
console.log("Background job failures :");
console.log("--------------------------------");
for (const log of grafanaLogs) {
console.log(JSON.parse(log.line));
console.log();
}
console.log("--------------------------------");
console.log();
}
};