Skip to content

Commit

Permalink
api: Add story urls to getStoryDetails event
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Jan 25, 2025
1 parent 2deee39 commit 9f0a9ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions packages/api/services/coa/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ import type { StorySearchResults } from "~dm-types/StorySearchResults";
import { prismaClient as prismaCoa } from "~prisma-schemas/schemas/coa/client";

import type Events from "../types";
import { Prisma } from "~prisma-schemas/client_coa";
export default (socket: Socket<Events>) => {
socket.on("getStoryDetails", (storycodes, callback) =>
prismaCoa.inducks_story
.findMany({
Promise.all([
prismaCoa.inducks_story.findMany({
where: {
storycode: { in: storycodes },
},
})
.then((data) => {
callback({ stories: data.groupBy("storycode") });
})
}),
prismaCoa.$queryRaw<{ storycode: string; url: string }[]>`
select s.storycode, CONCAT('webusers/webusers/', url) AS url
from inducks_story s
inner join coa.inducks_storyversion sv on s.originalstoryversioncode = sv.storyversioncode
inner join coa.inducks_entry e using (storyversioncode)
inner join coa.inducks_entryurl eu using (entrycode)
where s.storycode IN (${Prisma.join(storycodes)})
and eu.sitecode = 'webusers'
group by s.storycode`,
])
.then(([stories, storyUrls]) => ({
stories: stories.groupBy("storycode"),
storyUrls: storyUrls.groupBy("storycode", "url"),
}))
.catch((e) => {
callback({ error: "Error", errorDetails: e });
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/services/coa/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default abstract class {
abstract getStoryDetails: (
storycodes: string[],
callback: (
value: Errorable<{ stories: Record<string, inducks_story> }, "Error">,
value: Errorable<{ stories: Record<string, inducks_story>, storyUrls: Record<string, string> }, "Error">,
) => void,
) => void;
abstract getStoryversionsDetails: (
Expand Down

0 comments on commit 9f0a9ca

Please sign in to comment.