Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taxonomy): use right event when unlinking entity from taxonomy #1607

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions __fixtures__/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ export const createEntityLinkNotificationEvent: Model<'CreateEntityLinkNotificat
childId: coursePage.id,
}

export const removeEntityLinkNotificationEvent: Model<'RemoveEntityLinkNotificationEvent'> =
{
__typename: NotificationEventType.RemoveEntityLink,
id: 55273,
instance: Instance.De,
date: '2014-03-01T20:45:56Z',
actorId: user.id,
objectId: coursePage.id,
parentId: course.id,
childId: coursePage.id,
}

export const createEntityRevisionNotificationEvent: Model<'CreateEntityRevisionNotificationEvent'> =
{
__typename: NotificationEventType.CreateEntityRevision,
Expand Down
11 changes: 0 additions & 11 deletions __tests__/schema/event-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
createTaxonomyTermNotificationEvent,
createThreadNotificationEvent,
rejectRevisionNotificationEvent,
removeEntityLinkNotificationEvent,
removeTaxonomyLinkNotificationEvent,
setLicenseNotificationEvent,
setTaxonomyParentNotificationEvent,
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('creates event successfully with right payload', () => {
createTaxonomyTermNotificationEvent,
createThreadNotificationEvent,
rejectRevisionNotificationEvent,
removeEntityLinkNotificationEvent,
removeTaxonomyLinkNotificationEvent,
setLicenseNotificationEvent,
setTaxonomyParentNotificationEvent,
Expand Down Expand Up @@ -196,15 +194,6 @@ async function getLastEvent() {
reason
}

... on RemoveEntityLinkNotificationEvent {
parent {
id
}
child {
id
}
}

... on RemoveTaxonomyLinkNotificationEvent {
parent {
id
Expand Down
13 changes: 0 additions & 13 deletions packages/server/src/model/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ export enum NotificationEventType {
CreateTaxonomyLink = 'CreateTaxonomyLinkNotificationEvent',
CreateThread = 'CreateThreadNotificationEvent',
RejectRevision = 'RejectRevisionNotificationEvent',
RemoveEntityLink = 'RemoveEntityLinkNotificationEvent',
RemoveTaxonomyLink = 'RemoveTaxonomyLinkNotificationEvent',
SetLicense = 'SetLicenseNotificationEvent',
SetTaxonomyTerm = 'SetTaxonomyTermNotificationEvent',
Expand Down Expand Up @@ -544,17 +543,6 @@ export const CreateEntityLinkNotificationEventDecoder = t.exact(
]),
)

export const RemoveEntityLinkNotificationEventDecoder = t.exact(
t.intersection([
AbstractNotificationEventDecoder,
t.type({
__typename: t.literal(NotificationEventType.RemoveEntityLink),
parentId: t.number,
childId: t.number,
}),
]),
)

export const CreateEntityRevisionNotificationEventDecoder = t.exact(
t.intersection([
AbstractNotificationEventDecoder,
Expand Down Expand Up @@ -649,7 +637,6 @@ export const NotificationEventDecoder = t.union([
CreateTaxonomyLinkNotificationEventDecoder,
CreateThreadNotificationEventDecoder,
RejectRevisionNotificationEventDecoder,
RemoveEntityLinkNotificationEventDecoder,
RemoveTaxonomyLinkNotificationEventDecoder,
SetLicenseNotificationEventDecoder,
SetTaxonomyTermNotificationEventDecoder,
Expand Down
4 changes: 0 additions & 4 deletions packages/server/src/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
PageDecoder,
PageRevisionDecoder,
RejectRevisionNotificationEventDecoder,
RemoveEntityLinkNotificationEventDecoder,
RemoveTaxonomyLinkNotificationEventDecoder,
SetLicenseNotificationEventDecoder,
SetTaxonomyParentNotificationEventDecoder,
Expand Down Expand Up @@ -108,9 +107,6 @@ export interface Models {
RejectRevisionNotificationEvent: t.TypeOf<
typeof RejectRevisionNotificationEventDecoder
>
RemoveEntityLinkNotificationEvent: t.TypeOf<
typeof RemoveEntityLinkNotificationEventDecoder
>
SetLicenseNotificationEvent: t.TypeOf<
typeof SetLicenseNotificationEventDecoder
>
Expand Down
12 changes: 0 additions & 12 deletions packages/server/src/schema/event-types/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ export const resolvers: Resolvers = {
},
},

RemoveEntityLinkNotificationEvent: {
...createNotificationEventResolvers(),
async parent(event, _args, context) {
const id = event.parentId
return UuidResolver.resolveWithDecoder(EntityDecoder, { id }, context)
},
async child(event, _args, context) {
const id = event.childId
return UuidResolver.resolveWithDecoder(EntityDecoder, { id }, context)
},
},

CreateEntityLinkNotificationEvent: {
...createNotificationEventResolvers(),
async parent(event, _args, context) {
Expand Down
10 changes: 0 additions & 10 deletions packages/server/src/schema/event-types/types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ type CreateTaxonomyTermNotificationEvent implements AbstractNotificationEvent &
taxonomyTerm: TaxonomyTerm!
}

type RemoveEntityLinkNotificationEvent implements AbstractNotificationEvent & InstanceAware {
id: Int!
instance: Instance!
date: DateTime!
actor: User!
objectId: Int!
parent: AbstractEntity!
child: AbstractEntity!
}

type CreateEntityLinkNotificationEvent implements AbstractNotificationEvent & InstanceAware {
id: Int!
instance: Instance!
Expand Down
28 changes: 4 additions & 24 deletions packages/server/src/schema/events/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ enum EventType {
CreateEntity = 'entity/create',
SetLicense = 'license/object/set',
CreateEntityLink = 'entity/link/create',
RemoveEntityLink = 'entity/link/remove',
CreateEntityRevision = 'entity/revision/add',
CheckoutRevision = 'entity/revision/checkout',
RejectRevision = 'entity/revision/reject',
Expand Down Expand Up @@ -170,16 +169,10 @@ export function toGraphQLModel(
__typename: NotificationEventType.SetLicense,
repositoryId: event.objectId,
}
} else if (
event.type === EventType.CreateEntityLink ||
event.type === EventType.RemoveEntityLink
) {
} else if (event.type === EventType.CreateEntityLink) {
return {
...base,
__typename:
event.type === EventType.CreateEntityLink
? NotificationEventType.CreateEntityLink
: NotificationEventType.RemoveEntityLink,
__typename: NotificationEventType.CreateEntityLink,
childId: event.objectId,
parentId: event.uuidParameter,
}
Expand Down Expand Up @@ -279,16 +272,10 @@ function toDatabaseRepresentation(
type: EventType.SetLicense,
objectId: event.repositoryId,
}
} else if (
event.__typename === NotificationEventType.CreateEntityLink ||
event.__typename === NotificationEventType.RemoveEntityLink
) {
} else if (event.__typename === NotificationEventType.CreateEntityLink) {
return {
...base,
type:
event.__typename === NotificationEventType.CreateEntityLink
? EventType.CreateEntityLink
: EventType.RemoveEntityLink,
type: EventType.CreateEntityLink,
objectId: event.childId,
uuidParameter: event.parentId,
}
Expand Down Expand Up @@ -375,7 +362,6 @@ type GraphQLEventModels =
| Model<'CreateEntityNotificationEvent'>
| Model<'SetLicenseNotificationEvent'>
| Model<'CreateEntityLinkNotificationEvent'>
| Model<'RemoveEntityLinkNotificationEvent'>
| Model<'CreateEntityRevisionNotificationEvent'>
| Model<'CheckoutRevisionNotificationEvent'>
| Model<'RejectRevisionNotificationEvent'>
Expand All @@ -393,7 +379,6 @@ type PayloadForNewEvent =
| Omit<Model<'CreateEntityNotificationEvent'>, 'id' | 'date' | 'objectId'>
| Omit<Model<'SetLicenseNotificationEvent'>, 'id' | 'date' | 'objectId'>
| Omit<Model<'CreateEntityLinkNotificationEvent'>, 'id' | 'date' | 'objectId'>
| Omit<Model<'RemoveEntityLinkNotificationEvent'>, 'id' | 'date' | 'objectId'>
| Omit<
Model<'CreateEntityRevisionNotificationEvent'>,
'id' | 'date' | 'objectId'
Expand Down Expand Up @@ -448,10 +433,6 @@ const DatabaseEventRepresentations = {
type: EventType.CreateEntityLink,
parameters: t.type({ uuidParameter: t.number }),
}),
RemoveEntityLink: getDatabaseRepresentationDecoder({
type: EventType.RemoveEntityLink,
parameters: t.type({ uuidParameter: t.number }),
}),
CreateEntityRevision: getDatabaseRepresentationDecoder({
type: EventType.CreateEntityRevision,
parameters: t.type({ uuidParameter: t.number }),
Expand Down Expand Up @@ -509,7 +490,6 @@ export const DatabaseEventRepresentation: t.Type<DatabaseEventRepresentation> =
DatabaseEventRepresentations.CreateTaxonomyLink,
DatabaseEventRepresentations.CreateThread,
DatabaseEventRepresentations.RejectRevision,
DatabaseEventRepresentations.RemoveEntityLink,
DatabaseEventRepresentations.RemoveTaxonomyLink,
DatabaseEventRepresentations.RestoreThread,
DatabaseEventRepresentations.RestoreUuid,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/uuid/taxonomy-term/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export const resolvers: Resolvers = {

await createEvent(
{
__typename: NotificationEventType.RemoveEntityLink,
__typename: NotificationEventType.RemoveTaxonomyLink,
actorId: userId,
instance: taxonomyTerm.instance,
parentId: taxonomyTermId,
Expand Down
Loading