MCPcopy Create free account
hub / github.com/Devographics/Monorepo / initProjects

Function initProjects

api/src/load/projects.ts:9–28  ·  view source on GitHub ↗
({ context }: { context: RequestContext })

Source from the content-addressed store, hash-verified

7const idFieldName = 'slug'
8
9export const initProjects = async ({ context }: { context: RequestContext }) => {
10 const { db } = context
11 const projectsCollection = await getProjectsCollection()
12
13 console.log('// 🅱️ Adding Best of JS projects to DB…')
14 await projectsCollection.deleteMany({})
15
16 const response = await fetch('https://bestofjs-static-api-v2.vercel.app/projects-full.json')
17 const BestOfJSData: any = await response.json()
18 const projectsData = BestOfJSData.projects.filter((p: any) => !!p[idFieldName])
19
20 // format all ids (- to _)
21 let data = projectsData.map((project: any) => {
22 const id = formatId(project[idFieldName])
23 return { ...project, _id: id, id }
24 })
25 // TODO: filter out any project that is already in entities
26 await projectsCollection.insertMany(data)
27 console.log(` -> Inserted ${projectsData.length} projects.`)
28}

Callers 2

initDbCacheFunction · 0.90
startFunction · 0.90

Calls 2

getProjectsCollectionFunction · 0.90
formatIdFunction · 0.85

Tested by

no test coverage detected