Skip to content

Commit 27accfb

Browse files
committed
review comments
1 parent bf1dec0 commit 27accfb

File tree

16 files changed

+47
-37
lines changed

16 files changed

+47
-37
lines changed

backend/__tests__/__integration__/dal/leaderboards.isolated.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe("LeaderboardsDal", () => {
5959
)) as DBLeaderboardEntry[];
6060

6161
//THEN
62-
const lb = result.map((it) => omit(it, "_id"));
62+
const lb = result.map((it) => omit(it, ["_id"]));
6363

6464
expect(lb).toEqual([
6565
expectedLbEntry("15", { rank: 1, user: rank1 }),
@@ -86,7 +86,7 @@ describe("LeaderboardsDal", () => {
8686
)) as LeaderboardsDal.DBLeaderboardEntry[];
8787

8888
//THEN
89-
const lb = result.map((it) => omit(it, "_id"));
89+
const lb = result.map((it) => omit(it, ["_id"]));
9090

9191
expect(lb).toEqual([
9292
expectedLbEntry("60", { rank: 1, user: rank1 }),
@@ -200,7 +200,7 @@ describe("LeaderboardsDal", () => {
200200
)) as DBLeaderboardEntry[];
201201

202202
//THEN
203-
const lb = result.map((it) => omit(it, "_id"));
203+
const lb = result.map((it) => omit(it, ["_id"]));
204204

205205
expect(lb).toEqual([
206206
expectedLbEntry("15", { rank: 1, user: noBadge }),
@@ -239,7 +239,7 @@ describe("LeaderboardsDal", () => {
239239
)) as DBLeaderboardEntry[];
240240

241241
//THEN
242-
const lb = result.map((it) => omit(it, "_id"));
242+
const lb = result.map((it) => omit(it, ["_id"]));
243243

244244
expect(lb).toEqual([
245245
expectedLbEntry("15", { rank: 1, user: noPremium }),

backend/__tests__/api/controllers/result.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,14 @@ describe("result controller test", () => {
489489
it("should apply defaults on missing data", async () => {
490490
//GIVEN
491491
const result = givenDbResult(uid);
492-
const partialResult = omit(
493-
result,
492+
const partialResult = omit(result, [
494493
"difficulty",
495494
"language",
496495
"funbox",
497496
"lazyMode",
498497
"punctuation",
499-
"numbers"
500-
);
498+
"numbers",
499+
]);
501500

502501
const resultIdString = result._id.toHexString();
503502
const tagIds = [

backend/__tests__/utils/misc.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,26 @@ describe("Misc Utils", () => {
408408
describe("omit()", () => {
409409
it("should omit a single key", () => {
410410
const input = { a: 1, b: 2, c: 3 };
411-
const result = Misc.omit(input, "b");
411+
const result = Misc.omit(input, ["b"]);
412412
expect(result).toEqual({ a: 1, c: 3 });
413413
});
414414

415415
it("should omit multiple keys", () => {
416416
const input = { a: 1, b: 2, c: 3, d: 4 };
417-
const result = Misc.omit(input, "a", "d");
417+
const result = Misc.omit(input, ["a", "d"]);
418418
expect(result).toEqual({ b: 2, c: 3 });
419419
});
420420

421421
it("should return the same object if no keys are omitted", () => {
422422
const input = { x: 1, y: 2 };
423-
const result = Misc.omit(input);
423+
const result = Misc.omit(input, []);
424424
expect(result).toEqual({ x: 1, y: 2 });
425425
});
426426

427427
it("should not mutate the original object", () => {
428428
const input = { foo: "bar", baz: "qux" };
429429
const copy = { ...input };
430-
Misc.omit(input, "baz");
430+
Misc.omit(input, ["baz"]);
431431
expect(input).toEqual(copy);
432432
});
433433

@@ -445,7 +445,7 @@ describe("Misc Utils", () => {
445445
obj: { x: 1 },
446446
arr: [1, 2, 3],
447447
};
448-
const result = Misc.omit(input, "bool", "arr");
448+
const result = Misc.omit(input, ["bool", "arr"]);
449449
expect(result).toEqual({
450450
str: "hello",
451451
num: 123,

backend/src/api/controllers/ape-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ApeKey } from "@monkeytype/schemas/ape-keys";
1717
import { MonkeyRequest } from "../types";
1818

1919
function cleanApeKey(apeKey: ApeKeysDAL.DBApeKey): ApeKey {
20-
return omit(apeKey, "hash", "_id", "uid", "useCount") as ApeKey;
20+
return omit(apeKey, ["hash", "_id", "uid", "useCount"]) as ApeKey;
2121
}
2222

2323
export async function getApeKeys(

backend/src/api/controllers/leaderboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function getLeaderboard(
5757
}
5858

5959
const count = await LeaderboardsDAL.getCount(mode, mode2, language);
60-
const normalizedLeaderboard = leaderboard.map((it) => omit(it, "_id"));
60+
const normalizedLeaderboard = leaderboard.map((it) => omit(it, ["_id"]));
6161

6262
return new MonkeyResponse("Leaderboard retrieved", {
6363
count,

backend/src/api/controllers/result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export async function addResult(
224224

225225
const resulthash = completedEvent.hash;
226226
if (req.ctx.configuration.results.objectHashCheckEnabled) {
227-
const objectToHash = omit(completedEvent, "hash");
227+
const objectToHash = omit(completedEvent, ["hash"]);
228228
const serverhash = objectHash(objectToHash);
229229
if (serverhash !== resulthash) {
230230
void addLog(

backend/src/api/controllers/user.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ type RelevantUserInfo = Omit<
512512
>;
513513

514514
function getRelevantUserInfo(user: UserDAL.DBUser): RelevantUserInfo {
515-
return omit(
516-
user,
515+
return omit(user, [
517516
"bananas",
518517
"lbPersonalBests",
519518
"inbox",
@@ -524,8 +523,8 @@ function getRelevantUserInfo(user: UserDAL.DBUser): RelevantUserInfo {
524523
"note",
525524
"ips",
526525
"testActivity",
527-
"suspicious"
528-
) as RelevantUserInfo;
526+
"suspicious",
527+
]) as RelevantUserInfo;
529528
}
530529

531530
export async function getUser(req: MonkeyRequest): Promise<GetUserResponse> {

backend/src/dal/leaderboards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function get(
5151
.toArray();
5252

5353
if (!premiumFeaturesEnabled) {
54-
return result.map((it) => omit(it, "isPremium"));
54+
return result.map((it) => omit(it, ["isPremium"]));
5555
}
5656

5757
return result;

backend/src/dal/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function editPreset(
6161
uid: string,
6262
preset: EditPresetRequest
6363
): Promise<void> {
64-
const update: Partial<Omit<Preset, "_id">> = omit(preset, "_id");
64+
const update: Partial<Omit<Preset, "_id">> = omit(preset, ["_id"]);
6565
if (
6666
preset.config === undefined ||
6767
preset.config === null ||

backend/src/init/configuration.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { join } from "path";
1414
import { existsSync, readFileSync } from "fs";
1515
import { parseWithSchema as parseJsonWithSchema } from "@monkeytype/util/json";
1616
import { z } from "zod";
17+
import { intersect } from "@monkeytype/util/arrays";
1718

1819
const CONFIG_UPDATE_INTERVAL = 10 * 60 * 1000; // 10 Minutes
1920
const SERVER_CONFIG_FILE_PATH = join(
@@ -30,9 +31,7 @@ function mergeConfigurations(
3031
}
3132

3233
function merge(base: object, source: object): void {
33-
const baseKeys = Object.keys(base);
34-
const sourceKeys = Object.keys(source);
35-
const commonKeys = baseKeys.filter((key) => sourceKeys.includes(key));
34+
const commonKeys = intersect(Object.keys(base), Object.keys(source), true);
3635

3736
commonKeys.forEach((key) => {
3837
const baseValue = base[key] as object;
@@ -81,10 +80,9 @@ export async function getLiveConfiguration(): Promise<Configuration> {
8180
if (liveConfiguration) {
8281
const baseConfiguration = structuredClone(BASE_CONFIGURATION);
8382

84-
const liveConfigurationWithoutId = omit(
85-
liveConfiguration,
86-
"_id"
87-
) as Configuration;
83+
const liveConfigurationWithoutId = omit(liveConfiguration, [
84+
"_id",
85+
]) as Configuration;
8886
mergeConfigurations(baseConfiguration, liveConfigurationWithoutId);
8987

9088
await pushConfiguration(baseConfiguration);

0 commit comments

Comments
 (0)