From 507011e4c5f5808ae6ed7cbf2ce88fe4ad000fa5 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Mon, 7 Dec 2020 16:50:10 -0800 Subject: [PATCH] Update seeds to remove asyncForEach --- api/db/seeds.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/api/db/seeds.js b/api/db/seeds.js index 4ae898b..47b8607 100644 --- a/api/db/seeds.js +++ b/api/db/seeds.js @@ -23,20 +23,17 @@ const POSTS = [ }, ] -const asyncForEach = async (array, callback) => { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array) - } -} - async function main() { const existing = await db.post.findMany() - asyncForEach(POSTS, async (post) => { + for (let i = 0; i < POSTS.length; i++) { + const post = POSTS[i] + + // only inserts a post if one with the exact same title doesn't already exist if (!existing.find((ex) => ex.title === post.title)) { await db.post.create({ data: post }) } - }) + } } main()