forked from panoratech/Panora
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ab3e03
commit fe83ba5
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { ITagService } from '@ticketing/tag/types'; | ||
import { LinearTagOutput } from './types'; | ||
import { SyncParam } from '@@core/utils/types/interface'; | ||
|
||
@Injectable() | ||
export class LinearService implements ITagService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private logger: LoggerService, | ||
private cryptoService: EncryptionService, | ||
private registry: ServiceRegistry, | ||
) { | ||
this.logger.setContext( | ||
TicketingObject.tag.toUpperCase() + ':' + LinearService.name, | ||
); | ||
this.registry.registerService('linear', this); | ||
} | ||
|
||
async sync(data: SyncParam): Promise<ApiResponse<LinearTagOutput[]>> { | ||
try { | ||
const { linkedUserId, id_ticket } = data; | ||
|
||
const connection = await this.prisma.connections.findFirst({ | ||
where: { | ||
id_linked_user: linkedUserId, | ||
provider_slug: 'linear', | ||
vertical: 'ticketing', | ||
}, | ||
}); | ||
|
||
const labelQuery = { | ||
"query": "query { issueLabels { nodes { id name } }}" | ||
}; | ||
|
||
let resp = await axios.post( | ||
`${connection.account_url}`, | ||
labelQuery, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${this.cryptoService.decrypt( | ||
connection.access_token, | ||
)}`, | ||
}, | ||
}); | ||
this.logger.log(`Synced linear tags !`); | ||
|
||
return { | ||
data: resp.data.data.issueLabels.nodes, | ||
message: 'Linear tags retrieved', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ITagMapper } from '@ticketing/tag/types'; | ||
import { LinearTagInput, LinearTagOutput } from './types'; | ||
import { | ||
UnifiedTicketingTagInput, | ||
UnifiedTicketingTagOutput, | ||
} from '@ticketing/tag/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 LinearTagMapper implements ITagMapper { | ||
constructor(private mappersRegistry: MappersRegistry, private utils: Utils) { | ||
this.mappersRegistry.registerService('ticketing', 'tag', 'linear', this); | ||
} | ||
desunify( | ||
source: UnifiedTicketingTagInput, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): LinearTagInput { | ||
return; | ||
} | ||
|
||
unify( | ||
source: LinearTagOutput | LinearTagOutput[], | ||
connectionId: string, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): UnifiedTicketingTagOutput | UnifiedTicketingTagOutput[] { | ||
// If the source is not an array, convert it to an array for mapping | ||
const sourcesArray = Array.isArray(source) ? source : [source]; | ||
|
||
return sourcesArray.map((tag) => | ||
this.mapSingleTagToUnified(tag, connectionId, customFieldMappings), | ||
); | ||
} | ||
|
||
private mapSingleTagToUnified( | ||
tag: LinearTagOutput, | ||
connectionId: string, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): UnifiedTicketingTagOutput { | ||
const unifiedTag: UnifiedTicketingTagOutput = { | ||
remote_id: tag.id, | ||
remote_data: tag, | ||
name: tag.name, | ||
}; | ||
|
||
return unifiedTag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface LinearTag { | ||
id: string | ||
name: string | ||
} | ||
|
||
export type LinearTagInput = Partial<LinearTag>; | ||
export type LinearTagOutput = LinearTagInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters