Skip to content

Commit

Permalink
🐛 Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Mar 23, 2024
1 parent eca0fbf commit da3bd0c
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 182 deletions.
2 changes: 2 additions & 0 deletions packages/api/src/ticketing/collection/collection.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'
import { PrismaService } from '@@core/prisma/prisma.service';
import { WebhookService } from '@@core/webhook/webhook.service';
import { BullModule } from '@nestjs/bull';
import { JiraService } from './services/jira';

@Module({
imports: [
Expand All @@ -27,6 +28,7 @@ import { BullModule } from '@nestjs/bull';
FieldMappingService,
ServiceRegistry,
/* PROVIDERS SERVICES */
JiraService,
],
exports: [SyncService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@ import { Injectable } from '@nestjs/common';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
import { v4 as uuidv4 } from 'uuid';
import { ApiResponse } from '@@core/utils/types';
import { handleServiceError } from '@@core/utils/errors';
import { WebhookService } from '@@core/webhook/webhook.service';
import {
UnifiedCollectionInput,
UnifiedCollectionOutput,
} from '../types/model.unified';
import { desunify } from '@@core/utils/unification/desunify';
import { TicketingObject } from '@ticketing/@utils/@types';
import { UnifiedCollectionOutput } from '../types/model.unified';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ServiceRegistry } from './registry.service';
import { OriginalCollectionOutput } from '@@core/utils/types/original/original.ticketing';
import { unify } from '@@core/utils/unification/unify';
import { ICollectionService } from '../types';

@Injectable()
export class CollectionService {
Expand All @@ -39,42 +30,12 @@ export class CollectionService {
},
});

// WE SHOULDNT HAVE FIELD MAPPINGS TO COMMENT

// Fetch field mappings for the collection
/*const values = await this.prisma.value.findMany({
where: {
entity: {
ressource_owner_id: collection.id_tcg_collection,
},
},
include: {
attribute: true,
},
});
Create a map to store unique field mappings
const fieldMappingsMap = new Map();
values.forEach((value) => {
fieldMappingsMap.set(value.attribute.slug, value.data);
});
// Convert the map to an array of objects
const field_mappings = Array.from(fieldMappingsMap, ([key, value]) => ({
[key]: value,
}));*/

// Transform to UnifiedCollectionOutput format
const unifiedCollection: UnifiedCollectionOutput = {
id: collection.id_tcg_collection,
body: collection.body,
html_body: collection.html_body,
is_private: collection.is_private,
creator_type: collection.creator_type,
ticket_id: collection.id_tcg_ticket,
contact_id: collection.id_tcg_contact, // uuid of Contact object
user_id: collection.id_tcg_user, // uuid of User object
name: collection.name,
description: collection.description,
collection_type: collection.collection_type,
};

let res: UnifiedCollectionOutput = {
Expand Down Expand Up @@ -116,41 +77,11 @@ export class CollectionService {

const unifiedCollections: UnifiedCollectionOutput[] = await Promise.all(
collections.map(async (collection) => {
//WE SHOULDNT HAVE FIELD MAPPINGS FOR COMMENT
// Fetch field mappings for the ticket
/*const values = await this.prisma.value.findMany({
where: {
entity: {
ressource_owner_id: collection.id_tcg_ticket,
},
},
include: {
attribute: true,
},
});
// Create a map to store unique field mappings
const fieldMappingsMap = new Map();
values.forEach((value) => {
fieldMappingsMap.set(value.attribute.slug, value.data);
});
// Convert the map to an array of objects
const field_mappings = Array.from(
fieldMappingsMap,
([key, value]) => ({ [key]: value }),
);*/

// Transform to UnifiedCollectionOutput format
return {
id: collection.id_tcg_collection,
body: collection.body,
html_body: collection.html_body,
is_private: collection.is_private,
creator_type: collection.creator_type,
ticket_id: collection.id_tcg_ticket,
contact_id: collection.id_tcg_contact, // uuid of Contact object
user_id: collection.id_tcg_user, // uuid of User object
name: collection.name,
description: collection.description,
collection_type: collection.collection_type,
};
}),
);
Expand Down
35 changes: 0 additions & 35 deletions packages/api/src/ticketing/collection/services/gorgias/index.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/api/src/ticketing/collection/services/gorgias/mappers.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/api/src/ticketing/collection/services/gorgias/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/api/src/ticketing/collection/services/jira/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class JiraService implements ICollectionService {
});

const resp = await axios.get(
`${connection.account_url}/rest/api/3/user/groups`,
`${connection.account_url}/rest/api/3/project/search`,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -49,7 +49,7 @@ export class JiraService implements ICollectionService {
this.logger.log(`Synced jira collections !`);

return {
data: resp.data._results,
data: resp.data,
message: 'Jira collections retrieved',
statusCode: 200,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class JiraCollectionMapper implements ICollectionMapper {
): UnifiedCollectionOutput {
const unifiedCollection: UnifiedCollectionOutput = {
name: collection.name,
description: collection.name,
collection_type: 'PROJECT',
};

return unifiedCollection;
Expand Down
27 changes: 26 additions & 1 deletion packages/api/src/ticketing/collection/services/jira/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
export type JiraCollectionOutput = {
groupId: string;
avatarUrls: AvatarUrls;
id: string;
insight: Insight;
key: string;
name: string;
projectCategory: ProjectCategory;
self: string;
simplified: boolean;
style: string;
};

type AvatarUrls = {
'16x16': string;
'24x24': string;
'32x32': string;
'48x48': string;
};

type Insight = {
lastIssueUpdateTime: string; // Consider using Date type if appropriate
totalIssueCount: number;
};

type ProjectCategory = {
description: string;
id: string; // Or number if the ID is always numeric
name: string;
self: string;
};
Expand Down
Loading

0 comments on commit da3bd0c

Please sign in to comment.