Skip to content

Commit

Permalink
fix comment count generics updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-funk committed Oct 7, 2024
1 parent de2bf8f commit fb56ddf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
3 changes: 1 addition & 2 deletions server/src/core/server/models/comment/counts/counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
GQLCommentTagCounts,
} from "coral-server/graph/schema/__generated__/types";

import { Story } from "coral-server/models/story";
import {
createEmptyCommentModerationQueueCounts,
createEmptyCommentStatusCounts,
Expand Down Expand Up @@ -224,7 +223,7 @@ interface RelatedCommentCountsDocument extends Document {
}

export async function updateRelatedCommentCounts(
collection: Collection<Readonly<Story>>,
collection: Collection,
tenantID: string,
id: string,
commentCounts: DeepPartial<RelatedCommentCounts>
Expand Down
12 changes: 10 additions & 2 deletions server/src/core/server/models/site/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { identity, isNumber } from "lodash";
import { MongoError } from "mongodb";
import { Collection, MongoError } from "mongodb";
import { v4 as uuid } from "uuid";

import { FirstDeepPartial } from "coral-common/common/lib/types";
Expand Down Expand Up @@ -186,4 +186,12 @@ export const updateSiteCounts = (
tenantID: string,
id: string,
commentCounts: FirstDeepPartial<RelatedCommentCounts>
) => updateRelatedCommentCounts(mongo.sites(), tenantID, id, commentCounts);
) =>
updateRelatedCommentCounts(
// the generics on this won't let us extend to
// all Coral types
mongo.sites() as unknown as Collection,
tenantID,
id,
commentCounts
);
12 changes: 10 additions & 2 deletions server/src/core/server/models/story/story.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MongoError } from "mongodb";
import { Collection, MongoError } from "mongodb";
import { v4 as uuid } from "uuid";

import { DeepPartial, FirstDeepPartial } from "coral-common/common/lib/types";
Expand Down Expand Up @@ -674,7 +674,15 @@ export const updateStoryCounts = (
tenantID: string,
id: string,
commentCounts: FirstDeepPartial<RelatedCommentCounts>
) => updateRelatedCommentCounts(mongo.stories(), tenantID, id, commentCounts);
) =>
updateRelatedCommentCounts(
// the generics on this won't let us extend to
// all Coral types
mongo.stories() as unknown as Collection,
tenantID,
id,
commentCounts
);

export async function addStoryExpert(
mongo: MongoContext,
Expand Down
12 changes: 10 additions & 2 deletions server/src/core/server/models/user/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bcrypt from "bcryptjs";
import { DateTime, DurationObject } from "luxon";
import { MongoError } from "mongodb";
import { Collection, MongoError } from "mongodb";
import { v4 as uuid } from "uuid";

import { DeepPartial, Sub } from "coral-common/common/lib/types";
Expand Down Expand Up @@ -3602,7 +3602,15 @@ export const updateUserCommentCounts = (
tenantID: string,
id: string,
commentCounts: DeepPartial<UserCommentCounts>
) => updateRelatedCommentCounts(mongo.users(), tenantID, id, commentCounts);
) =>
updateRelatedCommentCounts(
// the generics on this won't let us extend to
// all Coral types
mongo.users() as unknown as Collection,
tenantID,
id,
commentCounts
);

export const updateLastFeaturedDate = async (
mongo: MongoContext,
Expand Down

0 comments on commit fb56ddf

Please sign in to comment.