Kevin Powell - CommunityKP-C
Kevin Powell - Communityβ€’15mo agoβ€’
16 replies
vince

How to build this db model

Working on a NoSQL implementation of this discord bot me and my friend are setting up. What it'll do is iterate through all messages and get the amount of emojis each user has across all their messages.

I was wondering what a good model for this would be? Should we build a model for each User, and then iterate through all their emojis? I have this so far:

type Emoji = {
  emoji: string;
  count: number;
};

export default class User {
  constructor(
    public server: string,
    public username: string,
    public emojis: Emoji[],
  ) {}
}


This way, we can just do something like:
// psuedocode
const serverUsers = users.filter((user) => {
  return user.server === server;
});

users.sort((a, b) => {
  const userACount = a.emojis.find((emoji) => {
    return (emoji.emoji === 'chart').count;
  });

  const userBCount = b.emojis.find((emoji) => {
    return (emoji.emoji === 'chart').count;
  });

  return userACount > userBCount; // I know this won't work lol gotta think about it
});
Was this page helpful?