fix update library item

This commit is contained in:
Hongbo Wu
2023-09-05 17:43:35 +08:00
parent d9d71aa443
commit 0016b0a9a7
2 changed files with 14 additions and 13 deletions

View File

@ -1,20 +1,14 @@
import { LibraryItem, LibraryItemState } from '../../entity/library_item'
import { LibraryItemState } from '../../entity/library_item'
import {
MutationUpdatePageArgs,
UpdatePageError,
UpdatePageSuccess,
} from '../../generated/graphql'
import { updateLibraryItem } from '../../services/library_item'
import { Merge } from '../../util'
import { authorized } from '../../utils/helpers'
export type UpdatePageSuccessPartial = Merge<
UpdatePageSuccess,
{ updatedPage: Partial<LibraryItem> }
>
import { authorized, libraryItemToArticle } from '../../utils/helpers'
export const updatePageResolver = authorized<
UpdatePageSuccessPartial,
UpdatePageSuccess,
UpdatePageError,
MutationUpdatePageArgs
>(async (_, { input }, { uid }) => {
@ -34,6 +28,6 @@ export const updatePageResolver = authorized<
uid
)
return {
updatedPage,
updatedPage: libraryItemToArticle(updatedPage),
}
})

View File

@ -317,9 +317,16 @@ export const updateLibraryItem = async (
userId: string,
pubsub = createPubSubClient()
): Promise<LibraryItem> => {
const updatedLibraryItem = await authTrx(async (tx) =>
tx.withRepository(libraryItemRepository).save({ id, ...libraryItem })
)
const updatedLibraryItem = await authTrx(async (tx) => {
const itemRepo = tx.withRepository(libraryItemRepository)
await itemRepo.save({ id, ...libraryItem })
return itemRepo.findById(id)
})
if (!updatedLibraryItem) {
throw new Error(`Library item ${id} not found`)
}
await pubsub.entityUpdated<DeepPartial<LibraryItem>>(
EntityType.PAGE,