Skip to content

Commit

Permalink
change search api to promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmy committed Jan 13, 2024
1 parent 5fcf5f1 commit fa5b830
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export async function POST(req: Request) {


// -------Inserting search results to DB-------
filteredResults.forEach(async (result) => {
await prisma?.searchResult.create({
await Promise.all(filteredResults.map(result => {
return prisma?.searchResult.create({
data: {
caseName: result.case_title,
caseNeutralCit: result.case_neutral_cit,
Expand All @@ -188,7 +188,20 @@ export async function POST(req: Request) {
userId: user.id
}
})
})
}))
// filteredResults.forEach(async (result) => {
// await prisma?.searchResult.create({
// data: {
// caseName: result.case_title,
// caseNeutralCit: result.case_neutral_cit,
// caseActionNo: result.case_action_no,
// caseDate: result.case_date,
// caseUrl: result.url,
// searchId: searchRecord.id,
// userId: user.id
// }
// })
// })

return new Response(JSON.stringify({filteredResults, searchId: searchRecord.id}), {
headers: { 'Content-Type': 'application/json'}
Expand Down

0 comments on commit fa5b830

Please sign in to comment.