Skip to content

Commit

Permalink
Migrate support module to server preset
Browse files Browse the repository at this point in the history
- Migrate Mutation.supportTicketCreate
- Migrate Mutation.supportTicketReply
- Migrate Organization.supportTickets and Organization.supportTickets
- Migrate SupportTicket
- Migrate SupportTicketPriority and SupportTicketStatus
  • Loading branch information
eddeee888 committed Jul 2, 2024
1 parent df8b90b commit 73056eb
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 261 deletions.
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 ?? ''),
},
};
},
};
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

0 comments on commit 73056eb

Please sign in to comment.