Skip to content

Commit

Permalink
remove a bunch of TS anys
Browse files Browse the repository at this point in the history
  • Loading branch information
Essential Randomness authored and essential-randomness committed Nov 21, 2023
1 parent 09010e2 commit cc79600
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
26 changes: 12 additions & 14 deletions server/realms/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import { getRealmDataBySlug, getSettingsBySlug } from "./queries";
import {
processBoardsNotifications,
processBoardsSummary,
reduceById,
} from "utils/response-utils";

import { DbRealmBoardType } from "server/boards/sql/types";
import { RealmPermissions } from "types/permissions";
import { createInvite } from "server/realms/queries";
import debug from "debug";
Expand Down Expand Up @@ -243,24 +245,20 @@ router.get("/:realm_id/notifications", ensureLoggedIn, async (req, res) => {
boards,
});
const pinned = notifications
.filter((notification: any) =>
.filter((notification) =>
boards.find(
(board: any) =>
(board) =>
board.string_id == notification.id && board.pinned_order !== null
)
)
.reduce((result: any, current: any) => {
result[current.id] = {
...current,
};
return result;
}, {});
const realmBoards = notifications.reduce((result: any, current: any) => {
result[current.id] = {
...current,
};
return result;
}, {});
.reduce(
reduceById,
{} as Record<string, ReturnType<typeof processBoardsNotifications>[0]>
);
const realmBoards = notifications.reduce(
reduceById,
{} as Record<string, ReturnType<typeof processBoardsNotifications>[0]>
);

const hasNotifications = notifications.some(
(notification) => notification.has_updates
Expand Down
18 changes: 16 additions & 2 deletions utils/response-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BoardByExternalId, DbRealmBoardType } from "server/boards/sql/types";
import {
BoardMetadata,
Comment,
Expand All @@ -17,7 +18,6 @@ import {
ZodDbThreadType,
} from "types/db/schemas";

import { BoardByExternalId } from "server/boards/sql/types";
import { BoardRestrictions } from "types/permissions";
import debug from "debug";
import { getUserPermissionsForBoard } from "./permissions-utils";
Expand Down Expand Up @@ -384,7 +384,11 @@ export const processBoardsSummary = ({
}));
};

export const processBoardsNotifications = ({ boards }: { boards: any[] }) => {
export const processBoardsNotifications = ({
boards,
}: {
boards: DbRealmBoardType[];
}) => {
return boards.map((board) => ({
id: board.string_id,
has_updates: board.has_updates,
Expand All @@ -399,3 +403,13 @@ export const processBoardsNotifications = ({ boards }: { boards: any[] }) => {
last_visited_at: board.last_visit_at,
}));
};

export const reduceById = <T extends { id: string }>(
result: Record<string, T>,
current: T
): Record<string, T> => {
result[current.id] = {
...current,
};
return result;
};

0 comments on commit cc79600

Please sign in to comment.