Junior — Middle+
Grouping received messages by dates with room name
livecode
Task condition
The system has two available endpoints: one returns an array of rooms, and the other — an array of messages. You need to make requests to both resources, add the name of the corresponding room to each message, and collect messages into a structure where the key is the string representation of the start of the day in ISO format, and the value is a message object without the roomId field but with a roomName field. Below are the data types and an example of the expected result.
interface IRoom {
id: number;
name: string;
type: string;
}
interface IMessage {
roomId: IRoom['id'];
id: number;
text: string;
ts: Date;
}
// // The GET '/rooms' endpoint returns IRoom[]
// // The GET '/messages' endpoint returns IMessage[]
// // You need to request messages and rooms and group messages by days
type ProcessedMessage = Omit<IMessage, 'roomId'> & {
roomName: IRoom['name'];
};
type ProcessedData = Record<string, ProcessedMessage>;
// // The string key is the ISO representation of the start of the day ('2022-06-23T00:00:00')
// // Example result:
//
// '2023-03-23T00:00:00': { // ISO representation of the start of the day
// "roomName": "Room name", // name of the room from rooms
// "id": 1,
// "text": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
// "ts": Thu Mar 23 2023 12:15:15 GMT+0200 (Eastern European Time)
// }
// ...