(handle, { api })
| 48 | } |
| 49 | |
| 50 | export async function fetchWorld(handle, { api }) { |
| 51 | /* `user` takes a handle, `userWorld` takes the id it resolves to: the world |
| 52 | tables are keyed on userId, so passing the handle straight through returns |
| 53 | an empty world rather than an error, which reads exactly like a private one. */ |
| 54 | const user = (await gql(api, USER, { id: handle }))?.user; |
| 55 | if (!user) throw new Error(`No daily.dev user called "${handle}".`); |
| 56 | const world = await gql(api, WORLD, { id: user.id }); |
| 57 | |
| 58 | const raw = world.userWorld ?? []; |
| 59 | const districts = raw |
| 60 | .map(({ reads, niche }) => ({ |
| 61 | niche: niche.slug, |
| 62 | topic: niche.title, |
| 63 | reads, |
| 64 | level: levelOf(reads), |
| 65 | })) |
| 66 | .filter((d) => d.level > 0) |
| 67 | .sort((a, b) => b.reads - a.reads); |
| 68 | |
| 69 | return { user, districts }; |
| 70 | } |
no test coverage detected