
No Comments Yet
Be the first to share your thoughts and start the conversation.
Be the first to share your thoughts and start the conversation.
Complete source code available till this point of lesson is available at
By logging in, you'll unlock full access to this and other free tutorials on JSM Pro.
Why? Logging in lets us personalize your learning experience, track your progress, and keep you in the loop with new workshops, coding tips, and platform updates.
You'll also be the first to know about upcoming launches, events, and exclusive discounts.
No spam—just helpful content to level up your skills.
If that sounds fair, go ahead and log in to continue →
Enter your name and email to get instant access
In this lesson, we delve into the development of an interaction model essential for creating a recommendation algorithm. This interaction model will help track user actions and preferences within the application, ultimately enhancing user experience.
00:00:02 Let's create an interaction model.
00:00:05 Now what would an interaction even be?
00:00:08 Well, see, this is not something that you'll hear about in other YouTube videos or courses.
00:00:14 In this course, we'll go in a lot of depth to make sure that we develop a proper recommendation algorithm.
00:00:21 See, right here on the homepage, we can sort by newest, but we can also sort by recommended questions.
00:00:28 And I mean, how are you going to recommend the users some specific questions?
00:00:32 Sure, we can just ask them which languages they like at the start, but no.
00:00:36 In our case, later in the course, you'll develop a full-blown recommendation algorithm that tracks exactly what people are doing within the app.
00:00:46 Which types of questions they're upvoting, downvoting, which types of answers they're writing, which types of tags they're using,
00:00:52 and more.
00:00:53 So, let's develop it by creating a new model.
00:00:56 called interaction.model.ts.
00:01:00 We can start from the template model, and we can rename it to interaction.
00:01:05 Each interaction has to have a user who is doing that action.
00:01:10 So that's going to be of a type schema.types.objectid, which is a reference to a user, and it is required.
00:01:20 then we have to know what kind of action is it.
00:01:23 And that's going to be of a type string and required to true.
00:01:26 It can be upVote, downVote, view, askQuestions, or whatever you think of.
00:01:32 Next, we'll have an action ID.
00:01:34 So this will basically be a schema types object ID, which is going to be required to true.
00:01:40 And it can either be a question ID or the answer ID.
00:01:44 So it can either be a question ID, if they're viewing or answering on a specific question, It can maybe be an answer ID or even a user ID if they're viewing
00:01:53 specific user details.
00:01:54 So we know that that user is interested in tags that this user is writing about.
00:01:58 Finally, we're going to also have the action type, which is going to be of a type string.
00:02:05 required to true, and it'll be a special string of a type enum, which can either be question or answer.
00:02:14 Later on we can extend it, but for now I'm fine with tracking user actions on questions and answers of other people.
00:02:21 Let's define the interface.
00:02:23 It's going to have a user, which is of a types dot object ID.
00:02:28 It's going to have an action, which is going to be of a type string.
00:02:31 It's going to have an action ID, which is going to be of a types object ID.
00:02:36 And it's going to have an action type, which is going to be of a type string.
00:02:41 You could also put an enum here or just say that it could either be a question or an answer.
00:02:46 And that's it.
00:02:47 That's our interaction model.
00:02:49 Since it's the last model that we'll have in our database, we can also now delete the template model because we have no use for it anymore.
00:02:57 So take a look at this.
00:02:58 We have the account, answer, collection, interaction, question, tag, question, tag, user, and finally vote.
00:03:06 And all of these models together form the database architecture of our application.
00:03:13 Of course, as we use these different models, we'll dive deeper into how they interact, and we'll dive deeper into creating instances of these models based
00:03:22 on these schemas.
00:03:24 But I just want to let you know that with this database architecture in mind, you now actually have a better idea of how this entire application behaves.
00:03:33 That's why it's very important to be a full stack developer, so you get the full control of the database, the front end,
00:03:40 the back end, and in general, you just become so much better of a developer.
00:03:44 So we can say implement interaction model.
00:03:49 And with that, we'll very soon be able to put these models to use.
00:03:53 Great work.