Skip to content

Commit f94abfa

Browse files
authored
Merge branch 'master' into convert-quotes-correctly-in-british-english
2 parents 1a33271 + 1dd0ca7 commit f94abfa

File tree

103 files changed

+1698
-882
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1698
-882
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Checks
66

7+
- [ ] Adding/modifying Typescript code?
8+
- [ ] I have used `qs`,`qsa` or `qsr` instead of JQuery selectors.
79
- [ ] Adding quotes?
810
- [ ] Make sure to include translations for the quotes in the description (or another comment) so we can verify their content.
911
- [ ] Adding a language?

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export NVM_DIR="$HOME/.nvm"
99
if [ $(git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') = "master" ] && [ $(git remote get-url origin) = "https://github.com/monkeytypegame/monkeytype" ]; then
1010
nvm install
1111
echo "Running a full check before pushing to master..."
12-
npm run full-check
12+
pnpm run full-check
1313
if [ $? -ne 0 ]; then
1414
echo "Full check failed, aborting push."
1515
exit 1

backend/__tests__/__testData__/auth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export async function mockAuthenticateWithApeKey(
1212
uid: string,
1313
config: Configuration,
1414
): Promise<string> {
15-
if (!config.apeKeys.acceptKeys)
15+
if (!config.apeKeys.acceptKeys) {
1616
throw Error("config.apeKeys.acceptedKeys needs to be set to true");
17+
}
1718
const { apeKeyBytes, apeKeySaltRounds } = config.apeKeys;
1819

1920
const apiKey = randomBytes(apeKeyBytes).toString("base64url");

backend/src/api/controllers/dev.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ async function createTestResults(
9696
const results = createArray(day.amount, () =>
9797
createResult(user, day.timestamp),
9898
);
99-
if (results.length > 0)
99+
if (results.length > 0) {
100100
await ResultDal.getResultCollection().insertMany(results);
101+
}
101102
}
102103
}
103104

@@ -221,9 +222,10 @@ async function updateUser(uid: string): Promise<void> {
221222
{ sort: { wpm: -1, timestamp: 1 } },
222223
)) as DBResult;
223224

224-
if (personalBests[mode.mode] === undefined) personalBests[mode.mode] = {};
225-
if (personalBests[mode.mode][mode.mode2] === undefined)
225+
personalBests[mode.mode] ??= {};
226+
if (personalBests[mode.mode][mode.mode2] === undefined) {
226227
personalBests[mode.mode][mode.mode2] = [];
228+
}
227229

228230
const entry = {
229231
acc: best.acc,
@@ -241,8 +243,9 @@ async function updateUser(uid: string): Promise<void> {
241243
(personalBests[mode.mode][mode.mode2] as PersonalBest[]).push(entry);
242244

243245
if (mode.mode === "time") {
244-
if (lbPersonalBests[mode.mode][mode.mode2] === undefined)
246+
if (lbPersonalBests[mode.mode][mode.mode2] === undefined) {
245247
lbPersonalBests[mode.mode][mode.mode2] = {};
248+
}
246249

247250
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
248251
lbPersonalBests[mode.mode][mode.mode2][mode.language] = entry;

backend/src/api/controllers/quote.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ export async function submitRating(
125125
shouldUpdateRating,
126126
);
127127

128-
if (!userQuoteRatings[language]) {
129-
userQuoteRatings[language] = {};
130-
}
128+
userQuoteRatings[language] ??= {};
131129
userQuoteRatings[language][quoteId] = rating;
132130

133131
await updateQuoteRatings(uid, userQuoteRatings);

backend/src/api/controllers/result.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,12 @@ export async function updateTags(
170170
await ResultDAL.updateTags(uid, resultId, tagIds);
171171
const result = await ResultDAL.getResult(uid, resultId);
172172

173-
if (!result.difficulty) {
174-
result.difficulty = "normal";
175-
}
176-
if (!(result.language ?? "")) {
177-
result.language = "english";
178-
}
179-
if (result.funbox === undefined) {
180-
result.funbox = [];
181-
}
182-
if (!result.lazyMode) {
183-
result.lazyMode = false;
184-
}
185-
if (!result.punctuation) {
186-
result.punctuation = false;
187-
}
188-
if (!result.numbers) {
189-
result.numbers = false;
190-
}
173+
result.difficulty ??= "normal";
174+
result.language ??= "english";
175+
result.funbox ??= [];
176+
result.lazyMode ??= false;
177+
result.punctuation ??= false;
178+
result.numbers ??= false;
191179

192180
const user = await UserDAL.getPartialUser(uid, "update tags", ["tags"]);
193181
const tagPbs = await UserDAL.checkIfTagPb(uid, user, result);

backend/src/api/controllers/user.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,9 @@ export function generateCurrentTestActivity(
12071207
let thisYearData = testActivity?.[thisYear.getFullYear().toString()];
12081208
let lastYearData = testActivity?.[lastYear.getFullYear().toString()];
12091209

1210-
if (lastYearData === undefined && thisYearData === undefined)
1210+
if (lastYearData === undefined && thisYearData === undefined) {
12111211
return undefined;
1212+
}
12121213

12131214
lastYearData = lastYearData ?? [];
12141215
thisYearData = thisYearData ?? [];

backend/src/api/controllers/webhooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export async function githubRelease(
1111

1212
if (action === "published") {
1313
const releaseId = req.body.release?.id;
14-
if (releaseId === undefined)
14+
if (releaseId === undefined) {
1515
throw new MonkeyError(422, 'Missing property "release.id".');
16+
}
1617

1718
await GeorgeQueue.sendReleaseAnnouncement(releaseId);
1819
return new MonkeyResponse("Added release announcement task to queue", null);

backend/src/dal/connections.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export async function getConnections(options: {
2020
}): Promise<DBConnection[]> {
2121
const { initiatorUid, receiverUid, status } = options;
2222

23-
if (initiatorUid === undefined && receiverUid === undefined)
23+
if (initiatorUid === undefined && receiverUid === undefined) {
2424
throw new Error("Missing filter");
25+
}
2526

2627
let filter: Filter<DBConnection> = { $or: [] };
2728

backend/src/dal/result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function addResult(
2121
const { data: user } = await tryCatch(getUser(uid, "add result"));
2222

2323
if (!user) throw new MonkeyError(404, "User not found", "add result");
24-
if (result.uid === undefined) result.uid = uid;
24+
result.uid ??= uid;
2525
// result.ir = true;
2626
const res = await getResultCollection().insertOne(result);
2727
return {

0 commit comments

Comments
 (0)