Fix(acc): subscriptions for update and delete
This commit is contained in:
@@ -2444,7 +2444,7 @@ export type ProjectWebhooksArgs = {
|
||||
export type ProjectAccSyncItemsUpdatedMessage = {
|
||||
__typename?: 'ProjectAccSyncItemsUpdatedMessage';
|
||||
accSyncItem?: Maybe<AccSyncItem>;
|
||||
lineageUrn: Scalars['String']['output'];
|
||||
id: Scalars['String']['output'];
|
||||
type: ProjectAccSyncItemsUpdatedMessageType;
|
||||
};
|
||||
|
||||
@@ -9121,7 +9121,7 @@ export type ProjectFieldArgs = {
|
||||
}
|
||||
export type ProjectAccSyncItemsUpdatedMessageFieldArgs = {
|
||||
accSyncItem: {},
|
||||
lineageUrn: {},
|
||||
id: {},
|
||||
type: {},
|
||||
}
|
||||
export type ProjectAccessRequestFieldArgs = {
|
||||
|
||||
@@ -84,7 +84,7 @@ enum ProjectAccSyncItemsUpdatedMessageType {
|
||||
|
||||
type ProjectAccSyncItemsUpdatedMessage {
|
||||
type: ProjectAccSyncItemsUpdatedMessageType!
|
||||
lineageUrn: String!
|
||||
id: String!
|
||||
accSyncItem: AccSyncItem
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import type { AccSyncItem } from '@/modules/acc/domain/types'
|
||||
import type {
|
||||
DeleteAccSyncItemInput,
|
||||
UpdateAccSyncItemInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
|
||||
export const accSyncItemEventsNamespace = 'accSyncItems' as const
|
||||
|
||||
@@ -22,12 +18,10 @@ export type AccSyncItemEventsPayloads = {
|
||||
newSyncItem: AccSyncItem
|
||||
projectId: string
|
||||
userId?: string
|
||||
input: UpdateAccSyncItemInput
|
||||
}
|
||||
[AccSyncItemEvents.Deleted]: {
|
||||
syncItem: AccSyncItem
|
||||
id: string
|
||||
projectId: string
|
||||
userId?: string
|
||||
input: DeleteAccSyncItemInput
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export const reportAccSyncItemCreatedFactory =
|
||||
projectId,
|
||||
projectAccSyncItemsUpdated: {
|
||||
type: 'CREATED',
|
||||
lineageUrn: syncItem.accFileLineageUrn,
|
||||
id: syncItem.id,
|
||||
accSyncItem: syncItem
|
||||
}
|
||||
})
|
||||
@@ -27,7 +27,7 @@ export const reportAccSyncItemUpdatedFactory =
|
||||
projectId,
|
||||
projectAccSyncItemsUpdated: {
|
||||
type: 'UPDATED',
|
||||
lineageUrn: newSyncItem.accFileLineageUrn,
|
||||
id: newSyncItem.id,
|
||||
accSyncItem: newSyncItem
|
||||
}
|
||||
})
|
||||
@@ -36,13 +36,13 @@ export const reportAccSyncItemUpdatedFactory =
|
||||
export const reportAccSyncItemDeletedFactory =
|
||||
(deps: { publish: PublishSubscription }) =>
|
||||
async (payload: EventPayload<typeof AccSyncItemEvents.Deleted>) => {
|
||||
const { projectId, syncItem } = payload.payload
|
||||
const { projectId, id } = payload.payload
|
||||
|
||||
await deps.publish(ProjectSubscriptions.ProjectAccSyncItemUpdated, {
|
||||
projectId,
|
||||
projectAccSyncItemsUpdated: {
|
||||
type: 'DELETED',
|
||||
lineageUrn: syncItem.accFileLineageUrn,
|
||||
id,
|
||||
accSyncItem: null
|
||||
}
|
||||
})
|
||||
|
||||
@@ -137,7 +137,8 @@ const resolvers: Resolvers = {
|
||||
|
||||
return await updateAccSyncItemFactory({
|
||||
getAccSyncItemById: getAccSyncItemByIdFactory({ db }),
|
||||
upsertAccSyncItem: upsertAccSyncItemFactory({ db })
|
||||
upsertAccSyncItem: upsertAccSyncItemFactory({ db }),
|
||||
eventEmit: getEventBus().emit
|
||||
})({
|
||||
syncItem: input
|
||||
})
|
||||
@@ -152,9 +153,11 @@ const resolvers: Resolvers = {
|
||||
})
|
||||
|
||||
await deleteAccSyncItemFactory({
|
||||
deleteAccSyncItemById: deleteAccSyncItemByIdFactory({ db })
|
||||
deleteAccSyncItemById: deleteAccSyncItemByIdFactory({ db }),
|
||||
eventEmit: getEventBus().emit
|
||||
})({
|
||||
id: input.id
|
||||
id: input.id,
|
||||
projectId: input.projectId
|
||||
})
|
||||
|
||||
return true
|
||||
|
||||
@@ -198,6 +198,7 @@ export const updateAccSyncItemFactory =
|
||||
(deps: {
|
||||
getAccSyncItemById: GetAccSyncItemById
|
||||
upsertAccSyncItem: UpsertAccSyncItem
|
||||
eventEmit: EventBusEmit
|
||||
}): UpdateAccSyncItem =>
|
||||
async ({ syncItem }) => {
|
||||
const existingSyncItem = await deps.getAccSyncItemById({
|
||||
@@ -216,17 +217,40 @@ export const updateAccSyncItemFactory =
|
||||
|
||||
await deps.upsertAccSyncItem(newSyncItem)
|
||||
|
||||
await deps.eventEmit({
|
||||
eventName: AccSyncItemEvents.Updated,
|
||||
payload: {
|
||||
oldSyncItem: existingSyncItem,
|
||||
newSyncItem,
|
||||
projectId: newSyncItem.projectId
|
||||
}
|
||||
})
|
||||
|
||||
return newSyncItem
|
||||
}
|
||||
|
||||
export type DeleteAccSyncItem = (params: { id: string }) => Promise<void>
|
||||
export type DeleteAccSyncItem = (params: {
|
||||
id: string
|
||||
projectId: string
|
||||
}) => Promise<void>
|
||||
|
||||
export const deleteAccSyncItemFactory =
|
||||
(deps: { deleteAccSyncItemById: DeleteAccSyncItemById }): DeleteAccSyncItem =>
|
||||
async ({ id }) => {
|
||||
(deps: {
|
||||
deleteAccSyncItemById: DeleteAccSyncItemById
|
||||
eventEmit: EventBusEmit
|
||||
}): DeleteAccSyncItem =>
|
||||
async ({ id, projectId }) => {
|
||||
const itemCount = await deps.deleteAccSyncItemById({ id })
|
||||
|
||||
if (itemCount === 0) {
|
||||
throw new SyncItemNotFoundError()
|
||||
}
|
||||
|
||||
await deps.eventEmit({
|
||||
eventName: AccSyncItemEvents.Deleted,
|
||||
payload: {
|
||||
id,
|
||||
projectId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2469,7 +2469,7 @@ export type ProjectWebhooksArgs = {
|
||||
export type ProjectAccSyncItemsUpdatedMessage = {
|
||||
__typename?: 'ProjectAccSyncItemsUpdatedMessage';
|
||||
accSyncItem?: Maybe<AccSyncItem>;
|
||||
lineageUrn: Scalars['String']['output'];
|
||||
id: Scalars['String']['output'];
|
||||
type: ProjectAccSyncItemsUpdatedMessageType;
|
||||
};
|
||||
|
||||
@@ -7192,7 +7192,7 @@ export type ProjectResolvers<ContextType = GraphQLContext, ParentType extends Re
|
||||
|
||||
export type ProjectAccSyncItemsUpdatedMessageResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['ProjectAccSyncItemsUpdatedMessage'] = ResolversParentTypes['ProjectAccSyncItemsUpdatedMessage']> = {
|
||||
accSyncItem?: Resolver<Maybe<ResolversTypes['AccSyncItem']>, ParentType, ContextType>;
|
||||
lineageUrn?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
type?: Resolver<ResolversTypes['ProjectAccSyncItemsUpdatedMessageType'], ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user