mirror of
https://github.com/Discreetly/server.git
synced 2026-04-17 03:00:55 -04:00
fix message bug if the epoch didn't exist yet (#77)
Also updated the mock roomId
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user