Skip to content

Commit

Permalink
feat: page router
Browse files Browse the repository at this point in the history
update docs, shift to pageProcedure
  • Loading branch information
seaerchin committed Jun 25, 2024
1 parent 3043040 commit 521cd32
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions apps/studio/src/server/modules/page/page.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,49 @@ import {
} from '../resource/resource.service'
import { getSiteConfig } from '../site/site.service'

// NOTE: Need to do validation like checking for existence of the page
// and whether the user has write-access to said page
const pageProcedure = protectedProcedure

export const pageRouter = router({
readPageAndBlob: protectedProcedure
readPageAndBlob: pageProcedure
.input(getEditPageSchema)
.query(async ({ input, ctx }) => {
const { pageId, siteId } = input
const page = await getFullPageById(pageId)
// TODO: Fill these in later
const pageName: string = page.name
// NOTE: Sitemap in siteMeta is immediate parent, immediate children and siblings
const siteMeta = getSiteConfig(siteId)
const navbar = getNavBar(siteId)
const footer = getFooter(siteId)
const { content } = page

return {
pageName,
// NOTE: might shift theme, isGovt, navbar, footer out into separate function?
// because this is shared across the whole site (site level props)
...siteMeta,
navbar,
footer,
// NOTE: This is immediate parent, immediate children and siblings
content,
...siteMeta,
}
}),

updatePage: protectedProcedure
updatePage: pageProcedure
.input(updatePageSchema)
.query(async ({ input, ctx }) => {
// NOTE: Need to do validation like checking for existence of the page
// and whether the user has write-access to said page
await updatePageById({ ...input, id: input.pageId })

return {
// NOTE: This should adhere to our db schema
...input,
// NOTE: Don't need `variant` here
// because the router itself discriminates for us
}
return input
}),

updatePageBlob: protectedProcedure
updatePageBlob: pageProcedure
.input(updatePageBlobSchema)
.query(async ({ input, ctx }) => {
// NOTE: Need to do validation like checking for existence of the page
// and whether the user has write-access to said page
await updateBlobById({ ...input, id: input.pageId })

// NOTE: Not returning the `content` first because
// 1. it might potentially be huge
// 2. frontend already knows
// ahead of time what is the content (it sent the content over)
return input
}),

createPage: protectedProcedure
createPage: pageProcedure
.input(createPageSchema)
.query(async ({ input, ctx }) => {
return { pageId: '' }
Expand Down

0 comments on commit 521cd32

Please sign in to comment.