parent
ff1ec095e1
commit
b78f84ffd0
6 changed files with 109 additions and 53 deletions
@ -1,12 +1,20 @@ |
|||||||
export default function stringifyList( |
export default function stringifyList( |
||||||
s: any[], |
s: any[], |
||||||
stringifyElem?: (e: any) => string, |
stringifyElem?: (e: any) => string, |
||||||
|
stringifyConnect?: (idx: number, e: any) => string, |
||||||
) { |
) { |
||||||
const stringify = stringifyElem || ((e: any) => e); |
if(!stringifyElem) { |
||||||
|
stringifyElem = (e: any) => e; |
||||||
|
} |
||||||
|
if(!stringifyConnect) { |
||||||
|
stringifyConnect = (idx: number, e: string) => { |
||||||
|
return (idx === 0) ? e : ", " + e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
var r = ""; |
var r = ""; |
||||||
if (s.length > 0) { r += stringify(s[0]) } |
for (let i = 0; i < s.length; i++) { |
||||||
for (let i = 1; i < s.length; i++) { |
r += stringifyConnect(i, stringifyElem(s[i])); |
||||||
r += ", " + stringify(s[i]); |
|
||||||
} |
} |
||||||
|
|
||||||
return r; |
return r; |
||||||
|
@ -0,0 +1,44 @@ |
|||||||
|
import * as api from '../../client/src/api'; |
||||||
|
import asJson from './asJson'; |
||||||
|
|
||||||
|
export function toApiTag(dbObj: any): api.TagDetails { |
||||||
|
return <api.TagDetails>{ |
||||||
|
tagId: dbObj['tags.id'], |
||||||
|
name: dbObj['tags.name'], |
||||||
|
parentId: dbObj['tags.parentId'], |
||||||
|
parent: dbObj.parent ? toApiTag(dbObj.parent) : undefined, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
export function toApiArtist(dbObj: any) { |
||||||
|
return <api.ArtistDetails>{ |
||||||
|
artistId: dbObj['artists.id'], |
||||||
|
name: dbObj['artists.name'], |
||||||
|
storeLinks: asJson(dbObj['artists.storeLinks']), |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
export function toApiSong(dbObj: any, artists: any[], tags: any[], albums: any[]) { |
||||||
|
return <api.SongDetails>{ |
||||||
|
songId: dbObj['songs.id'], |
||||||
|
title: dbObj['songs.title'], |
||||||
|
storeLinks: asJson(dbObj['songs.storeLinks']), |
||||||
|
artists: artists.map((artist: any) => { |
||||||
|
return toApiArtist(artist); |
||||||
|
}), |
||||||
|
tags: tags.map((tag: any) => { |
||||||
|
return toApiTag(tag); |
||||||
|
}), |
||||||
|
albums: albums.map((album: any) => { |
||||||
|
return toApiAlbum(album); |
||||||
|
}), |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
export function toApiAlbum(dbObj: any) { |
||||||
|
return <api.AlbumDetails>{ |
||||||
|
albumId: dbObj['albums.id'], |
||||||
|
name: dbObj['albums.name'], |
||||||
|
storeLinks: asJson(dbObj['albums.storeLinks']), |
||||||
|
}; |
||||||
|
} |
Loading…
Reference in new issue