|
| 1 | +import {AirbyteRecord} from 'faros-airbyte-cdk/src/protocol'; |
| 2 | + |
| 3 | +import {Converter, DestinationRecord} from '../converter'; |
| 4 | + |
| 5 | +export interface AsanaProject { |
| 6 | + gid: string; |
| 7 | +} |
| 8 | + |
| 9 | +export interface AsanaSection { |
| 10 | + gid: string; |
| 11 | + name: string; |
| 12 | + project?: AsanaProject; |
| 13 | +} |
| 14 | + |
| 15 | +export interface AsanaUser { |
| 16 | + gid: string; |
| 17 | + name?: string; |
| 18 | + email?: string; |
| 19 | +} |
| 20 | + |
| 21 | +interface TmsTaskType { |
| 22 | + category: TmsTaskCategory; |
| 23 | + detail: string; |
| 24 | +} |
| 25 | + |
| 26 | +enum TmsTaskCategory { |
| 27 | + Bug = 'Bug', |
| 28 | + Custom = 'Custom', |
| 29 | + Story = 'Story', |
| 30 | + Task = 'Task', |
| 31 | +} |
| 32 | + |
| 33 | +/** Common functions shares across Asana converters */ |
| 34 | +export class AsanaCommon { |
| 35 | + // Max length for free-form description text fields such as issue body |
| 36 | + static readonly MAX_DESCRIPTION_LENGTH = 1000; |
| 37 | + |
| 38 | + static toTmsTaskType(type: string): TmsTaskType { |
| 39 | + const detail = type.toLowerCase(); |
| 40 | + switch (detail) { |
| 41 | + case 'bug': |
| 42 | + return {category: TmsTaskCategory.Bug, detail}; |
| 43 | + case 'story': |
| 44 | + return {category: TmsTaskCategory.Story, detail}; |
| 45 | + case 'task': |
| 46 | + return {category: TmsTaskCategory.Task, detail}; |
| 47 | + default: |
| 48 | + return {category: TmsTaskCategory.Custom, detail}; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + static tms_User(user: AsanaUser, source: string): DestinationRecord { |
| 53 | + return { |
| 54 | + model: 'tms_User', |
| 55 | + record: { |
| 56 | + uid: user.gid, |
| 57 | + name: user.name || null, |
| 58 | + emailAddress: user.email || null, |
| 59 | + source, |
| 60 | + }, |
| 61 | + }; |
| 62 | + } |
| 63 | + |
| 64 | + static tms_TaskBoard(section: AsanaSection, source: string): DestinationRecord { |
| 65 | + return { |
| 66 | + model: 'tms_TaskBoard', |
| 67 | + record: { |
| 68 | + uid: section.gid, |
| 69 | + name: section.name, |
| 70 | + source, |
| 71 | + }, |
| 72 | + }; |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/** Asana converter base */ |
| 77 | +export abstract class AsanaConverter extends Converter { |
| 78 | + /** All Asana records should have id property */ |
| 79 | + id(record: AirbyteRecord): any { |
| 80 | + return record?.record?.data?.gid; |
| 81 | + } |
| 82 | +} |
0 commit comments