From 87060488f5b5cc09cbf1bbbbaa3271dc1c0eead8 Mon Sep 17 00:00:00 2001
From: Ian Philips <iansphilips@gmail.com>
Date: Wed, 7 Sep 2022 07:13:34 -0600
Subject: [PATCH] Convert market to lite market for Phil

---
 web/lib/firebase/groups.ts                   | 3 ++-
 web/pages/api/v0/group/by-id/[id]/markets.ts | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/web/lib/firebase/groups.ts b/web/lib/firebase/groups.ts
index 36bfe7cc..0366fe0b 100644
--- a/web/lib/firebase/groups.ts
+++ b/web/lib/firebase/groups.ts
@@ -86,9 +86,10 @@ export async function listGroupContracts(groupId: string) {
     contractId: string
     createdTime: number
   }>(groupContracts(groupId))
-  return Promise.all(
+  const contracts = await Promise.all(
     contractDocs.map((doc) => getContractFromId(doc.contractId))
   )
+  return filterDefined(contracts)
 }
 
 export function listenForOpenGroups(setGroups: (groups: Group[]) => void) {
diff --git a/web/pages/api/v0/group/by-id/[id]/markets.ts b/web/pages/api/v0/group/by-id/[id]/markets.ts
index f7538277..e9610a20 100644
--- a/web/pages/api/v0/group/by-id/[id]/markets.ts
+++ b/web/pages/api/v0/group/by-id/[id]/markets.ts
@@ -1,6 +1,7 @@
 import { NextApiRequest, NextApiResponse } from 'next'
 import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
 import { listGroupContracts } from 'web/lib/firebase/groups'
+import { toLiteMarket } from 'web/pages/api/v0/_types'
 
 export default async function handler(
   req: NextApiRequest,
@@ -8,7 +9,9 @@ export default async function handler(
 ) {
   await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
   const { id } = req.query
-  const contracts = await listGroupContracts(id as string)
+  const contracts = (await listGroupContracts(id as string)).map((contract) =>
+    toLiteMarket(contract)
+  )
   if (!contracts) {
     res.status(404).json({ error: 'Group not found' })
     return