Skip to content

Commit 6076370

Browse files
committed
[backend/frontend] refactor: mutualize code for private document list
1 parent 09b3334 commit 6076370

File tree

31 files changed

+143
-343
lines changed

31 files changed

+143
-343
lines changed

apps/portal-api/src/__generated__/resolvers-types.ts

Lines changed: 0 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/portal-api/src/modules/services/custom-dashboards/custom-dashboards.graphql

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,5 @@ type CustomDashboardConnection {
3838
type Query {
3939
seoCustomDashboardsByServiceSlug(serviceSlug: String): [CustomDashboard]
4040
seoCustomDashboardBySlug(slug: String): CustomDashboard
41-
customDashboards(
42-
first: Int!
43-
after: ID
44-
orderBy: DocumentOrdering!
45-
orderMode: OrderingMode!
46-
searchTerm: String
47-
logicalFilters: LogicalFilterInput
48-
serviceInstanceId: String
49-
): CustomDashboardConnection! @auth
5041
customDashboard(id: ID, serviceInstanceId: ID): CustomDashboard @auth
5142
}

apps/portal-api/src/modules/services/custom-dashboards/custom-dashboards.resolver.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
CustomDashboardConnection,
3-
Resolvers,
4-
} from '../../../__generated__/resolvers-types';
1+
import { Resolvers } from '../../../__generated__/resolvers-types';
52
import { DocumentId } from '../../../model/kanel/public/Document';
63
import { ServiceInstanceId } from '../../../model/kanel/public/ServiceInstance';
74
import { extractId } from '../../../utils/utils';
@@ -49,13 +46,6 @@ const resolvers: Resolvers = {
4946
seoCustomDashboardBySlug: async (_, { slug }) => {
5047
return CustomDashboardsApp.loadSeoCustomDashboard(slug);
5148
},
52-
customDashboards: async (_, input) => {
53-
return DocumentDomain.loadParentDocumentsByServiceInstance<CustomDashboardConnection>(
54-
OPENCTI_CUSTOM_DASHBOARD_DOCUMENT_TYPE,
55-
input,
56-
CUSTOM_DASHBOARD_METADATA_KEYS
57-
);
58-
},
5949
customDashboard: async (_, { id }) =>
6050
CustomDashboardsApp.loadCustomDashboard(extractId<DocumentId>(id)),
6151
},

apps/portal-api/src/modules/services/document/document.app.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
CreateDocumentInput,
3+
DocumentConnection,
34
DocumentMetadata as DocumentMetadataResolverType,
45
IntegrationType,
56
MutationUpdateDocumentArgs as MutationUpdateDocumentArgsResolverType,
7+
QueryDocumentsArgs,
68
} from '../../../__generated__/resolvers-types';
79
import { withTransaction } from '../../../context/database.context';
810
import { requestContext } from '../../../context/request.context';
@@ -25,6 +27,7 @@ import { buildCreateEvent } from '../../telemetry/telemetry.helper';
2527
import { serviceDefinitionDomain } from '../definition/service-definition.domain';
2628
import { OPENCTI_INTEGRATION_DOCUMENT_TYPE } from '../integrations/integrations.model';
2729
import {
30+
ALL_METADATA_KEYS,
2831
DocumentHelper,
2932
ManageableServiceDefinitionIdentifier,
3033
} from './document.helper';
@@ -349,6 +352,27 @@ export const DocumentApp = {
349352

350353
return documentFromDb as T;
351354
},
355+
356+
loadDocuments: async (input: QueryDocumentsArgs) => {
357+
const serviceDefinition =
358+
await serviceDefinitionDomain.loadServiceDefinitionByServiceInstance(
359+
extractId<ServiceInstanceId>(input.serviceInstanceId)
360+
);
361+
if (!serviceDefinition) {
362+
throw new Error(ErrorCode.ServiceDefinitionNotFound);
363+
}
364+
365+
const documentType =
366+
DocumentHelper.retrieveDocumentTypeFromServiceDefinition(
367+
serviceDefinition.identifier as ManageableServiceDefinitionIdentifier
368+
);
369+
370+
return DocumentDomain.loadParentDocumentsByServiceInstance<DocumentConnection>(
371+
documentType,
372+
input,
373+
ALL_METADATA_KEYS
374+
);
375+
},
352376
};
353377

354378
const upsertDocument = async <T extends DocumentModel>(

apps/portal-api/src/modules/services/document/document.graphql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ type Query {
138138
orderBy: DocumentOrdering!
139139
orderMode: OrderingMode!
140140
searchTerm: String
141-
filters: [Filter!]
142141
logicalFilters: LogicalFilterInput
143142
serviceInstanceId: String
144143
parentsOnly: Boolean

apps/portal-api/src/modules/services/document/document.helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import { telemetryApp } from '../../telemetry/telemetry.app';
2222
import { TelemetryEventType } from '../../telemetry/telemetry.types';
2323
import {
2424
CUSTOM_DASHBOARD_METADATA,
25+
CUSTOM_DASHBOARD_METADATA_KEYS,
2526
OPENCTI_CUSTOM_DASHBOARD_DOCUMENT_TYPE,
2627
} from '../custom-dashboards/custom-dashboards.domain';
2728
import {
2829
INTEGRATION_CSV_FEED_METADATA,
30+
INTEGRATION_METADATA_KEYS,
2931
INTEGRATION_STREAM_METADATA,
3032
INTEGRATION_TAXII_FEED_METADATA,
3133
INTEGRATION_THIRD_PARTY_INTEGRATION_METADATA,
@@ -35,6 +37,7 @@ import {
3537
import {
3638
OPENAEV_SCENARIO_DOCUMENT_TYPE,
3739
OPENAEV_SCENARIO_METADATA,
40+
OPENAEV_SCENARIO_METADATA_KEYS,
3841
} from '../openaev-scenarios/openaev-scenarios.domain';
3942
import { DocumentApp } from './document.app';
4043
import { Upload } from './document.uploads.helper';
@@ -52,6 +55,14 @@ export type FullDocumentMutator = Partial<DocumentModel> & {
5255
parent_document_id?: DocumentId;
5356
};
5457

58+
export const ALL_METADATA_KEYS: string[] = Array.from(
59+
new Set([
60+
...INTEGRATION_METADATA_KEYS,
61+
...CUSTOM_DASHBOARD_METADATA_KEYS,
62+
...OPENAEV_SCENARIO_METADATA_KEYS,
63+
])
64+
);
65+
5566
export type ManageableServiceDefinitionIdentifier =
5667
| ServiceDefinitionIdentifier.OpenctiIntegrations
5768
| ServiceDefinitionIdentifier.OpenctiCustomDashboards

apps/portal-api/src/modules/services/document/document.resolver.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -188,39 +188,7 @@ const resolvers: Resolvers = {
188188
throw mapToGraphQLError(error);
189189
}
190190
},
191-
documents: async (
192-
_,
193-
{
194-
first,
195-
after,
196-
orderMode,
197-
orderBy,
198-
searchTerm,
199-
filters,
200-
serviceInstanceId,
201-
parentsOnly,
202-
}
203-
) => {
204-
try {
205-
return DocumentDomain.loadDocuments(
206-
{
207-
first,
208-
after,
209-
orderMode,
210-
orderBy,
211-
parentsOnly,
212-
filters,
213-
searchTerm: searchTerm ?? '',
214-
},
215-
{
216-
'Document.service_instance_id': fromGlobalId(serviceInstanceId).id,
217-
}
218-
);
219-
} catch (error) {
220-
logApp.error('Error while fetching documents:', error);
221-
throw mapToGraphQLError(error);
222-
}
223-
},
191+
documents: async (_, input) => DocumentApp.loadDocuments(input),
224192
document: async (_, { documentId }) =>
225193
DocumentDomain.loadDocumentWithMetadataById(
226194
extractId<DocumentId>(documentId)

apps/portal-api/src/modules/services/document/domain/document.domain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const DocumentDomain = {
125125
return DocumentDomain.loadDocuments<T>(
126126
{
127127
...input,
128-
parentsOnly: true,
128+
parentsOnly: input.parentsOnly ?? true,
129129
searchTerm: input.searchTerm,
130130
},
131131
{

apps/portal-api/src/modules/services/integrations/integrations.app.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
IntegrationConnection,
3-
QueryIntegrationsArgs,
43
QueryPublicIntegrationsArgs,
54
} from '../../../__generated__/resolvers-types';
65
import { DocumentId } from '../../../model/kanel/public/Document';
@@ -17,13 +16,6 @@ import {
1716
} from './integrations.model';
1817

1918
export const integrationsApp = {
20-
loadIntegrations: async (input: QueryIntegrationsArgs) => {
21-
return DocumentDomain.loadParentDocumentsByServiceInstance<IntegrationConnection>(
22-
OPENCTI_INTEGRATION_DOCUMENT_TYPE,
23-
input,
24-
INTEGRATION_METADATA_KEYS
25-
);
26-
},
2719
loadIntegration: async (
2820
documentId: DocumentId
2921
): Promise<WithUseCases<Integration>> => {

apps/portal-api/src/modules/services/integrations/integrations.graphql

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,6 @@ type IntegrationConnection {
267267
}
268268

269269
type Query {
270-
integrations(
271-
first: Int!
272-
after: ID
273-
orderBy: DocumentOrdering!
274-
orderMode: OrderingMode!
275-
searchTerm: String
276-
logicalFilters: LogicalFilterInput
277-
serviceInstanceId: String
278-
): IntegrationConnection! @auth
279270
integration(id: ID, serviceInstanceId: ID): Integration @auth
280271
publicIntegrations(
281272
slug: String!

0 commit comments

Comments
 (0)