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

Migrate support module to Server Preset (Part 5) #4956

Merged
merged 1 commit into from
Jul 2, 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
1 change: 0 additions & 1 deletion codegen.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const config: CodegenConfig = {
'policy',
'project',
'schema',
'support',
'target',
],
scalarsOverrides: {
Expand Down
2 changes: 1 addition & 1 deletion packages/services/api/src/modules/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createModule } from 'graphql-modules';
import { SupportManager } from './providers/support-manager';
import { resolvers } from './resolvers';
import { resolvers } from './resolvers.generated';
import typeDefs from './module.graphql';

export const supportModule = createModule({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SupportTicketPriority, SupportTicketStatus } from '../../shared/entities';

export type SupportTicketPriorityMapper = SupportTicketPriority;
export type SupportTicketStatusMapper = SupportTicketStatus;
109 changes: 0 additions & 109 deletions packages/services/api/src/modules/support/resolvers.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IdTranslator } from '../../../shared/providers/id-translator';
import { SupportManager } from '../../providers/support-manager';
import type { MutationResolvers } from './../../../../__generated__/types.next';

export const supportTicketCreate: NonNullable<MutationResolvers['supportTicketCreate']> = async (
_,
{ input },
{ injector },
) => {
const organizationId = await injector.get(IdTranslator).translateOrganizationId(input);
const response = await injector.get(SupportManager).createTicket({
organizationId,
...input,
});

return response;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IdTranslator } from '../../../shared/providers/id-translator';
import { SupportManager } from '../../providers/support-manager';
import type { MutationResolvers } from './../../../../__generated__/types.next';

export const supportTicketReply: NonNullable<MutationResolvers['supportTicketReply']> = async (
_,
{ input },
{ injector },
) => {
const organizationId = await injector.get(IdTranslator).translateOrganizationId(input);
const response = await injector.get(SupportManager).replyToTicket({
organizationId,
...input,
});

return response;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { SupportManager } from '../providers/support-manager';
import type { OrganizationResolvers } from './../../../__generated__/types.next';

export const Organization: Pick<OrganizationResolvers, 'supportTicket' | 'supportTickets'> = {
supportTickets: async (org, args, { injector }) => {
const response = await injector.get(SupportManager).getTickets(org.id);

return {
edges: response.nodes.map(ticket => ({
node: {
id: String(ticket.id),
status: ticket.status,
priority: ticket.priority,
description: ticket.description,
subject: ticket.subject,
createdAt: ticket.created_at,
updatedAt: ticket.updated_at,
},
cursor: String(ticket.id),
})),
pageInfo: {
endCursor: String(response.nodes[response.nodes.length - 1]?.id ?? ''),
hasNextPage: response.meta.has_more,
hasPreviousPage: false,
startCursor: String(response.nodes[0]?.id ?? ''),
},
};
},
supportTicket: async (org, args, { injector }) => {
const ticket = await injector.get(SupportManager).getTicket(org.id, args.id);

if (!ticket) {
return null;
}

return {
id: String(ticket.id),
status: ticket.status,
priority: ticket.priority,
description: ticket.description,
subject: ticket.subject,
createdAt: ticket.created_at,
updatedAt: ticket.updated_at,
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SupportManager } from '../providers/support-manager';
import type { SupportTicketResolvers } from './../../../__generated__/types.next';

export const SupportTicket: SupportTicketResolvers = {
comments: async (ticket, _args, { injector }) => {
const response = await injector.get(SupportManager).getTicketComments(ticket.id);

return {
edges: response.nodes.map(comment => ({
node: {
id: String(comment.id),
body: comment.body,
createdAt: comment.created_at,
fromSupport: comment.fromSupport,
},
cursor: String(comment.id),
})),
pageInfo: {
endCursor: String(response.nodes[response.nodes.length - 1]?.id ?? ''),
hasNextPage: response.meta.has_more,
hasPreviousPage: false,
startCursor: String(response.nodes[0]?.id ?? ''),
},
};
},
Comment on lines +5 to +25
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema for this type is this:

comments: SupportTicketCommentConnection

This seems a bit different from other *Connection as they are usually non-nullable i.e. *Connection!.
Looking at the implementation, it can never be null. So I think this could be a way to get around having to declare mapper for SupportTicket? 🤔

Either way, this is part of the migration so we should keep the implementation as-is, however, I think we should change the type to SupportTicketCommentConnection! so it correctly reflects the logic.

Unless I misunderstood it, then please let me know!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilkisiela Did you think about anything specific when u implemented this?

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SupportTicketPriority as SupportTicketPriorityEnum } from '../../../shared/entities';
import type { SupportTicketPriorityResolvers } from './../../../__generated__/types.next';

export const SupportTicketPriority: SupportTicketPriorityResolvers = {
NORMAL: SupportTicketPriorityEnum.NORMAL,
HIGH: SupportTicketPriorityEnum.HIGH,
URGENT: SupportTicketPriorityEnum.URGENT,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SupportTicketStatus as SupportTicketStatusEnum } from '../../../shared/entities';
import type { SupportTicketStatusResolvers } from './../../../__generated__/types.next';

export const SupportTicketStatus: SupportTicketStatusResolvers = {
OPEN: SupportTicketStatusEnum.OPEN,
SOLVED: SupportTicketStatusEnum.SOLVED,
};
Loading
Loading