Skip to content

Commit

Permalink
Step 4.2: Resolve last message based on messages array
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Urigo committed May 20, 2020
1 parent e86306a commit 5ab032e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 0 additions & 4 deletions db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ export const chats = [
id: '1',
name: 'Ethan Gonzalez',
picture: 'https://randomuser.me/api/portraits/thumb/men/1.jpg',
lastMessage: '1',
messages: ['1'],
},
{
id: '2',
name: 'Bryan Wallace',
picture: 'https://randomuser.me/api/portraits/thumb/men/2.jpg',
lastMessage: '2',
messages: ['2'],
},
{
id: '3',
name: 'Avery Stewart',
picture: 'https://randomuser.me/api/portraits/thumb/women/1.jpg',
lastMessage: '3',
messages: ['3'],
},
{
id: '4',
name: 'Katie Peterson',
picture: 'https://randomuser.me/api/portraits/thumb/women/2.jpg',
lastMessage: '4',
messages: ['4'],
},
];
6 changes: 4 additions & 2 deletions schema/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ const resolvers = {

Chat: {
messages(chat: any) {
return messages.filter(m => chat.messages.includes(m.id));
return messages.filter((m) => chat.messages.includes(m.id));
},

lastMessage(chat: any) {
return messages.find((m) => m.id === chat.lastMessage);
const lastMessage = chat.messages[chat.messages.length - 1];

return messages.find((m) => m.id === lastMessage);
},
},

Expand Down

0 comments on commit 5ab032e

Please sign in to comment.