1
+ import { isObject } from "@/helpers" ;
1
2
import type { GitHubGraphQl } from "@/services/github/types" ;
2
3
import { GitHub } from "@/types" ;
3
4
import { convertStringToURL } from "@/utils" ;
@@ -91,16 +92,22 @@ export function fromGraphQlData(
91
92
}
92
93
}
93
94
95
+ type ParsedFundingLink = {
96
+ url : string ;
97
+ platform : string ;
98
+ } ;
99
+
94
100
export function fromDbObject (
95
101
row : ParamsObject ,
96
102
) : Result < GitHub . Repository , unknown > {
97
103
try {
98
104
const parsedLatestRelease = row . latestRelease
99
105
? JSON . parse ( row . latestRelease as string )
100
106
: undefined ;
101
- const parsedFundingLinks = row . fundingLinks
102
- ? JSON . parse ( row . fundingLinks as string )
103
- : undefined ;
107
+
108
+ const parsedFundingLinks : ParsedFundingLink [ ] = row . fundingLinks
109
+ ? ( JSON . parse ( row . fundingLinks as string ) as ParsedFundingLink [ ] )
110
+ : [ ] ;
104
111
const repo = new GitHub . Repository ( {
105
112
id : row . id as string ,
106
113
name : row . name as string ,
@@ -120,7 +127,7 @@ export function fromDbObject(
120
127
isFork : ! ! ( row . isFork as number ) ,
121
128
isPrivate : ! ! ( row . isPrivate as number ) ,
122
129
isTemplate : ! ! ( row . isTemplate as number ) ,
123
- latestRelease : parsedLatestRelease
130
+ latestRelease : isObject ( parsedLatestRelease )
124
131
? {
125
132
name : parsedLatestRelease . name as string ,
126
133
publishedAt : DateTime . fromISO (
@@ -153,14 +160,21 @@ export function fromDbObject(
153
160
: undefined ,
154
161
updatedAt : DateTime . fromISO ( row . updatedAt as string ) . toUTC ( ) ,
155
162
importedAt : DateTime . fromISO ( row . importedAt as string ) . toUTC ( ) ,
156
- languages : row . languages ? JSON . parse ( row . languages as string ) : [ ] ,
163
+ languages : row . languages
164
+ ? ( JSON . parse ( row . languages as string ) as string [ ] )
165
+ : [ ] ,
157
166
} ) ;
158
167
159
- for ( const link of parsedFundingLinks ) {
160
- repo . fundingLinks . push ( {
161
- url : convertStringToURL ( link . url ) ,
162
- platform : link . platform ,
163
- } ) ;
168
+ if ( parsedFundingLinks && Array . isArray ( parsedFundingLinks ) ) {
169
+ for ( const link of parsedFundingLinks ) {
170
+ repo . fundingLinks . push ( {
171
+ url : convertStringToURL ( link . url ) ,
172
+ platform :
173
+ GitHub . FundingPlatform [
174
+ link . platform as keyof typeof GitHub . FundingPlatform
175
+ ] ,
176
+ } ) ;
177
+ }
164
178
}
165
179
return ok ( repo ) ;
166
180
} catch ( error ) {
0 commit comments