(value: unknown)
| 148 | } |
| 149 | |
| 150 | export function mapTrelloCard(value: unknown): TrelloCard { |
| 151 | if (!isRecordLike(value)) { |
| 152 | throw new Error('Trello returned an invalid card object') |
| 153 | } |
| 154 | |
| 155 | const rawLabels = Array.isArray(value.labels) ? value.labels : [] |
| 156 | const labels = rawLabels |
| 157 | .map((label) => mapTrelloLabel(label)) |
| 158 | .filter((label): label is TrelloLabel => label !== null) |
| 159 | const labelIds = getIdArray(value.idLabels) |
| 160 | |
| 161 | if (labelIds.length === 0) { |
| 162 | labelIds.push(...rawLabels.filter((label): label is string => typeof label === 'string')) |
| 163 | } |
| 164 | |
| 165 | return { |
| 166 | id: getRequiredString(value.id, 'id'), |
| 167 | name: getRequiredString(value.name, 'name'), |
| 168 | desc: typeof value.desc === 'string' ? value.desc : '', |
| 169 | url: getRequiredString(value.url, 'url'), |
| 170 | idBoard: getRequiredString(value.idBoard, 'idBoard'), |
| 171 | idList: getRequiredString(value.idList, 'idList'), |
| 172 | closed: typeof value.closed === 'boolean' ? value.closed : false, |
| 173 | labelIds, |
| 174 | labels, |
| 175 | due: getOptionalString(value.due), |
| 176 | dueComplete: getOptionalBoolean(value.dueComplete), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | export function mapTrelloBoard(value: unknown): TrelloBoard { |
| 181 | if (!isRecordLike(value)) { |
no test coverage detected