A Prediction Market on the AT Protocol

feat(core.api.ts): prevent indexing bets on closed markets

Ciaran cde4ce14 ca393937

+7 -5
+7 -5
src/core/api.ts
··· 95 95 const existing = await db.query.betsTable.findFirst({ where: eq(betsTable.uri, uri) }); 96 96 if (existing) return; 97 97 98 + const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { closesAt: true } }); 99 + if (!indexedMarket || (new Date() > indexedMarket.closesAt)) return; 100 + 98 101 const betData: typeof betsTable.$inferInsert = { 99 102 uri, did, rev, rkey, cid, position, marketUri: market.uri, record, createdAt 100 103 } ··· 119 122 const { answer, market } = record; 120 123 const createdAt = new Date(record.createdAt); 121 124 122 - const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { did: true }}); 125 + const existing = await db.query.resolutionsTable.findFirst({ where: eq(resolutionsTable.uri, uri) }); 126 + if (existing) return; 127 + 128 + const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { did: true } }); 123 129 if (!indexedMarket) return; 124 130 125 131 const canUserEdit = did === indexedMarket.did; 126 132 if (!canUserEdit) return; 127 - 128 - const existing = await db.query.resolutionsTable.findFirst({ where: eq(resolutionsTable.uri, uri) }); 129 - if (existing) return; 130 - 131 133 132 134 const resolutionData: typeof resolutionsTable.$inferInsert = { 133 135 uri, did, rev, rkey, cid, answer, marketUri: market.uri, record, createdAt