diff --git a/src/lib/trpc/routers/postdata.router.ts b/src/lib/trpc/routers/postdata.router.ts index c7b4048..ad987cb 100644 --- a/src/lib/trpc/routers/postdata.router.ts +++ b/src/lib/trpc/routers/postdata.router.ts @@ -192,48 +192,41 @@ export const postDataApiRouter = createTRPCRouter({ console.log(`[+] Posting ${data.length} entries to the API`); + const res = await postDataToApi({ + sessions: userSessions, + data, + users, + draw, + }); + console.timeEnd("Time taken to post data to the API"); + + if (!res.ok) { + await removePostSession(); + return { ok: false, detail: res.detail }; + } + + console.log(`[+] Data posted to the API successfully`); + + await dbApiPostData.upsertData({ + id: getULID(), + drawId: +drawId.split(":")[1], + bookDate: date, + data, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + }); + + // Update the balance of the users after posting to the API + await updateBalanceOfPostUsers(users); + + console.log("[+] Data saved to the database"); + + await postDataCacheStore.del(input.cachedDataKey); + await removePostSession(); return { ok: true, - data: [], - users: [], - detail: "Data posted successfully", + detail: "Data successfully posted to API", + errors: undefined, }; - - // const res = await postDataToApi({ - // sessions: userSessions, - // data, - // users, - // draw, - // }); - // console.timeEnd("Time taken to post data to the API"); - - // if (!res.ok) { - // await removePostSession(); - // return { ok: false, detail: res.detail }; - // } - - // console.log(`[+] Data posted to the API successfully`); - - // await dbApiPostData.upsertData({ - // id: getULID(), - // drawId: +drawId.split(":")[1], - // bookDate: date, - // data, - // createdAt: new Date().toISOString(), - // updatedAt: new Date().toISOString(), - // }); - - // // Update the balance of the users after posting to the API - // await updateBalanceOfPostUsers(users); - - // console.log("[+] Data saved to the database"); - - // await postDataCacheStore.del(input.cachedDataKey); - // await removePostSession(); - // return { - // ok: true, - // detail: "Data successfully posted to API", - // errors: undefined, - // }; }), });