({ context }: { context: RequestContext })
| 7 | const idFieldName = 'slug' |
| 8 | |
| 9 | export 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 | } |
no test coverage detected