fix update library item
This commit is contained in:
@ -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),
|
||||
}
|
||||
})
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user