mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add recommendPage helper function
This commit is contained in:
parent
b19b04bbe6
commit
a7d0525d2e
1 changed files with 37 additions and 0 deletions
37
packages/api/src/elastic/groups.ts
Normal file
37
packages/api/src/elastic/groups.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { Group, Page, PageContext } from './types'
|
||||
import { createPage, updatePage } from './pages'
|
||||
|
||||
export const recommendPage = async (
|
||||
ctx: PageContext,
|
||||
page: Page,
|
||||
userId: string,
|
||||
group: Group,
|
||||
existingPage?: Page
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
if (existingPage) {
|
||||
// update recommendedBy in the existing page
|
||||
const recommendedBy = (existingPage.recommendedBy || []).concat(group)
|
||||
|
||||
await updatePage(
|
||||
existingPage.id,
|
||||
{
|
||||
recommendedBy,
|
||||
},
|
||||
ctx
|
||||
)
|
||||
return existingPage.id
|
||||
}
|
||||
|
||||
// create a new page
|
||||
const newPage = {
|
||||
...page,
|
||||
recommendedBy: [group],
|
||||
userId,
|
||||
}
|
||||
|
||||
return createPage(newPage, ctx)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue