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.
Showing
5 changed files
with
142 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,67 @@ | ||
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 { ITeamService } from '@ticketing/team/types'; | ||
import { LinearTeamOutput } from './types'; | ||
import { SyncParam } from '@@core/utils/types/interface'; | ||
|
||
@Injectable() | ||
export class LinearService implements ITeamService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private logger: LoggerService, | ||
private cryptoService: EncryptionService, | ||
private registry: ServiceRegistry, | ||
) { | ||
this.logger.setContext( | ||
TicketingObject.team.toUpperCase() + ':' + LinearService.name, | ||
); | ||
this.registry.registerService('linear', this); | ||
} | ||
|
||
async sync(data: SyncParam): Promise<ApiResponse<LinearTeamOutput[]>> { | ||
try { | ||
const { linkedUserId } = data; | ||
|
||
const connection = await this.prisma.connections.findFirst({ | ||
where: { | ||
id_linked_user: linkedUserId, | ||
provider_slug: 'linear', | ||
vertical: 'ticketing', | ||
}, | ||
}); | ||
|
||
const teamQuery = { | ||
"query": "query { teams { nodes { id, name, description } }}" | ||
}; | ||
|
||
let resp = await axios.post( | ||
`${connection.account_url}`, | ||
teamQuery, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${this.cryptoService.decrypt( | ||
connection.access_token, | ||
)}`, | ||
}, | ||
}); | ||
this.logger.log(`Synced linear teams !`); | ||
|
||
return { | ||
data: resp.data.data.teams.nodes, | ||
message: 'Linear teams retrieved', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
|
59 changes: 59 additions & 0 deletions
59
packages/api/src/ticketing/team/services/linear/mappers.ts
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,59 @@ | ||
import { ITeamMapper } from '@ticketing/team/types'; | ||
import { LinearTeamInput, LinearTeamOutput } from './types'; | ||
import { | ||
UnifiedTicketingTeamInput, | ||
UnifiedTicketingTeamOutput, | ||
} from '@ticketing/team/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 LinearTeamMapper implements ITeamMapper { | ||
constructor(private mappersRegistry: MappersRegistry, private utils: Utils) { | ||
this.mappersRegistry.registerService('ticketing', 'team', 'linear', this); | ||
} | ||
desunify( | ||
source: UnifiedTicketingTeamInput, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): LinearTeamInput { | ||
return; | ||
} | ||
|
||
unify( | ||
source: LinearTeamOutput | LinearTeamOutput[], | ||
connectionId: string, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): UnifiedTicketingTeamOutput | UnifiedTicketingTeamOutput[] { | ||
// If the source is not an array, convert it to an array for mapping | ||
const sourcesArray = Array.isArray(source) ? source : [source]; | ||
|
||
return sourcesArray.map((team) => | ||
this.mapSingleTeamToUnified(team, connectionId, customFieldMappings), | ||
); | ||
} | ||
|
||
private mapSingleTeamToUnified( | ||
team: LinearTeamOutput, | ||
connectionId: string, | ||
customFieldMappings?: { | ||
slug: string; | ||
remote_id: string; | ||
}[], | ||
): UnifiedTicketingTeamOutput { | ||
const unifiedTeam: UnifiedTicketingTeamOutput = { | ||
remote_id: team.id, | ||
remote_data: team, | ||
name: team.name, | ||
description: team.description, | ||
}; | ||
|
||
return unifiedTeam; | ||
} | ||
} |
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,8 @@ | ||
export type LinearTeam = { | ||
id: string | ||
name: string | ||
description: string | ||
}; | ||
|
||
export type LinearTeamInput = Partial<LinearTeam>; | ||
export type LinearTeamOutput = LinearTeamInput; |
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