Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Aug 9, 2024
1 parent a7d1326 commit 6c858fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/studio/src/server/modules/page/page.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
updatePageById,
} from "../resource/resource.service"
import { getSiteConfig } from "../site/site.service"
import { addNewVersion } from "../version/version.service"
import { incrementVersion } from "../version/version.service"
import { createDefaultPage } from "./page.service"

const ajv = new Ajv({ allErrors: true, strict: false, logger: false })
Expand Down Expand Up @@ -250,7 +250,7 @@ export const pageRouter = router({
.mutation(async ({ ctx, input: { siteId, pageId } }) => {
/* Step 1: Update DB table to latest state */
// Create a new version
const addedVersionResult = await addNewVersion({
const addedVersionResult = await incrementVersion({
siteId,
pageId,
userId: ctx.user.id,
Expand Down
10 changes: 8 additions & 2 deletions apps/studio/src/server/modules/version/version.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SelectExpression } from "kysely"
import { TRPCError } from "@trpc/server"
import { type DB } from "~prisma/generated/generatedTypes"

import type { SafeKysely } from "../database"
Expand Down Expand Up @@ -45,7 +46,7 @@ const createVersion = async (
return { versionId: addedVersion.id }
}

export const addNewVersion = async ({
export const incrementVersion = async ({
siteId,
pageId,
userId,
Expand All @@ -56,12 +57,17 @@ export const addNewVersion = async ({
}) => {
return await db
.transaction()
// serialize to prevent discrepancies from
// concurrent publishes from other users
.setIsolationLevel("serializable")
.execute(async (tx) => {
const page = await getPageById(tx, { siteId, resourceId: pageId })

if (!page.draftBlobId) {
return { error: "No drafts to publish for this page" }
throw new TRPCError({
code: "BAD_REQUEST",
message: "No drafts to publish for this page",
})
}

let newVersionNum = 1
Expand Down

0 comments on commit 6c858fc

Please sign in to comment.