diff --git a/src/data/db/find.ts b/src/data/db/find.ts index 1938bac..a410061 100644 --- a/src/data/db/find.ts +++ b/src/data/db/find.ts @@ -126,9 +126,15 @@ export async function findRoomWithMessageId( } }); if (!room) { + console.debug('Room not found'); + return null; + } + if (room.epochs[0]) { + return room.epochs[0].messages[0]; + } else { + console.debug('Epoch not found'); return null; } - return room.epochs[0].messages[0]; } catch (err) { console.error(err); throw err; diff --git a/src/data/mock.ts b/src/data/mock.ts index 561fb37..50dbb15 100644 --- a/src/data/mock.ts +++ b/src/data/mock.ts @@ -41,12 +41,17 @@ export default function Mock(io: SocketIOServer) { setInterval(() => { const message: MessageI = { id: faker.number.bigInt().toString(), - roomId: BigInt('20945462742745557191488383979949684808523754877925170533224967224808050898610'), + roomId: BigInt( + '15365950124115259122299397335353503712492707509718474633204755132763780105662' + ), message: picker.pick(), timeStamp: Date.now().toString(), epoch: Math.floor(Date.now() / 10000) }; console.log('SENDING TEST MESSAGE'); - io.emit('messageBroadcast', message); + io.to('15365950124115259122299397335353503712492707509718474633204755132763780105662').emit( + 'messageBroadcast', + message + ); }, 10000); } diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index 7e4ffc9..e95ec1f 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -157,7 +157,7 @@ export function initEndpoints(app: Express, adminAuth: RequestHandler) { }); } } else { - res.status(400).json({ message: 'Claim Code already used123' }); + res.status(400).json({ message: 'Claim Code already used' }); return; } const roomIds = foundCode.roomIds; @@ -372,9 +372,7 @@ export function initEndpoints(app: Express, adminAuth: RequestHandler) { return Promise.all(createCodes) .then(() => { - res - .status(200) - .json({ message: 'Claim codes added successfully', codes }); + res.status(200).json({ message: 'Claim codes added successfully', codes }); }) .catch((err) => { console.error(err); @@ -512,23 +510,27 @@ export function initEndpoints(app: Express, adminAuth: RequestHandler) { }) ); - app.post('/room/:roomId/addAdmin', adminAuth, asyncHandler(async (req: Request, res: Response) => { - const { roomId } = req.params; - const { idc } = req.body as { idc: string }; - try { - await prisma.rooms.update({ - where: { - roomId: roomId - }, - data: { - adminIdentities: { - push: idc + app.post( + '/room/:roomId/addAdmin', + adminAuth, + asyncHandler(async (req: Request, res: Response) => { + const { roomId } = req.params; + const { idc } = req.body as { idc: string }; + try { + await prisma.rooms.update({ + where: { + roomId: roomId + }, + data: { + adminIdentities: { + push: idc + } } - } - }) - res.status(200).json({ message: `Admin added to room ${roomId}` }); - } catch (err) { - res.status(500).json({ error: 'Internal Server Error' }); - } - })); + }); + res.status(200).json({ message: `Admin added to room ${roomId}` }); + } catch (err) { + res.status(500).json({ error: 'Internal Server Error' }); + } + }) + ); }