Skip to content

Commit

Permalink
adding linear comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimtron-10 committed Aug 8, 2024
1 parent fe83ba5 commit 33e34ea
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LinearCollectionInput, LinearCollectionOutput } from '@ticketing/collection/services/linear/types';

import { LinearTagInput, LinearTagOutput } from '@ticketing/tag/services/linear/types';

import { LinearTeamInput, LinearTeamOutput } from '@ticketing/team/services/linear/types';
Expand Down Expand Up @@ -183,7 +185,7 @@ export type OriginalTeamInput =
export type OriginalAttachmentInput = null;
export type OriginalCollectionInput =
| JiraCollectionInput
| GitlabCollectionInput;
| GitlabCollectionInput | LinearCollectionInput;

export type TicketingObjectInput =
| OriginalTicketInput
Expand Down Expand Up @@ -253,7 +255,7 @@ export type OriginalAttachmentOutput =

export type OriginalCollectionOutput =
| JiraCollectionOutput
| GitlabCollectionOutput;
| GitlabCollectionOutput | LinearCollectionOutput;

export type TicketingObjectOutput =
| OriginalTicketOutput
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/ticketing/collection/collection.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LinearCollectionMapper } from './services/linear/mappers';
import { LinearService } from './services/linear';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { BullQueueModule } from '@@core/@core-services/queues/queue.module';
Expand Down Expand Up @@ -36,6 +38,8 @@ import { IngestDataService } from '@@core/@core-services/unification/ingest-data
/* PROVIDERS MAPPERS */
JiraCollectionMapper,
GitlabCollectionMapper,
LinearService,
LinearCollectionMapper,
],
exports: [SyncService, ServiceRegistry, WebhookService],
})
Expand Down
65 changes: 65 additions & 0 deletions packages/api/src/ticketing/collection/services/linear/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Injectable } from '@nestjs/common';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { TicketingObject } from '@ticketing/@lib/@types';
import { ApiResponse } from '@@core/utils/types';
import axios from 'axios';
import { ActionType, handle3rdPartyServiceError } from '@@core/utils/errors';
import { ServiceRegistry } from '../registry.service';
import { ICollectionService } from '@ticketing/collection/types';
import { LinearCollectionOutput, LinearCollectionInput } from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class LinearService implements ICollectionService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
TicketingObject.collection.toUpperCase() + ':' + LinearService.name,
);
this.registry.registerService('linear', this);
}

async sync(data: SyncParam): Promise<ApiResponse<LinearCollectionOutput[]>> {
try {
const { linkedUserId } = data;

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'linear',
vertical: 'ticketing',
},
});

const projectQuery = {
"query": "query { projects { nodes { id, name, description } }}"
};

let resp = await axios.post(
`${connection.account_url}`,
projectQuery, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
this.logger.log(`Synced linear collections !`);

return {
data: resp.data.data.projects.nodes,
message: 'Linear collections retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
69 changes: 69 additions & 0 deletions packages/api/src/ticketing/collection/services/linear/mappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ICollectionMapper } from '@ticketing/collection/types';
import { LinearCollectionInput, LinearCollectionOutput } from './types';
import {
UnifiedTicketingCollectionInput,
UnifiedTicketingCollectionOutput,
} from '@ticketing/collection/types/model.unified';
import { MappersRegistry } from '@@core/@core-services/registries/mappers.registry';
import { Injectable } from '@nestjs/common';
import { Utils } from '@ticketing/@lib/@utils';

@Injectable()
export class LinearCollectionMapper implements ICollectionMapper {
constructor(private mappersRegistry: MappersRegistry, private utils: Utils) {
this.mappersRegistry.registerService(
'ticketing',
'collection',
'linear',
this,
);
}
desunify(
source: UnifiedTicketingCollectionInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): LinearCollectionInput {
return;
}

unify(
source: LinearCollectionOutput | LinearCollectionOutput[],
connectionId: string,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedTicketingCollectionOutput | UnifiedTicketingCollectionOutput[] {
// If the source is not an array, convert it to an array for mapping
const sourcesArray = Array.isArray(source) ? source : [source];

return sourcesArray.map((collection) =>
this.mapSingleCollectionToUnified(
collection,
connectionId,
customFieldMappings,
),
);
}

private mapSingleCollectionToUnified(
collection: LinearCollectionOutput,
connectionId: string,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedTicketingCollectionOutput {
const unifiedCollection: UnifiedTicketingCollectionOutput = {
remote_id: collection.id,
remote_data: collection,
name: collection.name,
description: collection.description,
collection_type: 'PROJECT',
};

return unifiedCollection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface LinearCollection {
id: string
name: string
description: string
}

export type LinearCollectionInput = Partial<LinearCollection>;
export type LinearCollectionOutput = LinearCollectionInput;

0 comments on commit 33e34ea

Please sign in to comment.