1
00:00:00,330 --> 00:00:00,870
Wonderful.

2
00:00:01,290 --> 00:00:05,280
Now let's keep on moving, and we'll set up a review.

3
00:00:05,790 --> 00:00:13,800
So Starwood review model, just like with product user, and I think that's about it for the models,

4
00:00:13,800 --> 00:00:14,190
correct?

5
00:00:14,580 --> 00:00:22,830
Create a review dress in models, create schema and for time being set up following properties with

6
00:00:22,830 --> 00:00:26,610
foreign values and yes, lots and more functionality in there.

7
00:00:27,030 --> 00:00:35,640
And I also want you to set up properties for user and for product because we need to keep in mind that

8
00:00:35,670 --> 00:00:45,030
when we're creating a review, not only we want to have a user like we have a product, but we also

9
00:00:45,030 --> 00:00:48,640
want to attach product that review correct.

10
00:00:49,110 --> 00:00:55,980
So review should be tied to two things not only user, but also to a product.

11
00:00:56,370 --> 00:01:02,490
And eventually, I also want you to set up time stamps and export of the review model.

12
00:01:02,700 --> 00:01:07,410
So let's navigate to a models we're looking for.

13
00:01:07,450 --> 00:01:08,460
Are you?

14
00:01:09,520 --> 00:01:09,870
Yes.

15
00:01:10,530 --> 00:01:13,590
And in here you want to grab first mangoes.

16
00:01:14,460 --> 00:01:21,100
Konst mangoes is equal to your acquire and then mangoes run.

17
00:01:21,300 --> 00:01:22,770
You want to set up our schema.

18
00:01:22,860 --> 00:01:31,770
So let's call this Konst review schema that is equal to a mango schema or schema.

19
00:01:32,070 --> 00:01:34,140
And here, let's bask in the rating.

20
00:01:34,440 --> 00:01:39,310
So that's going to be the first thing, and that is going to be a type number.

21
00:01:39,330 --> 00:01:46,080
So type, type, number, and let's add a few more values where essentially I'm going to go with min

22
00:01:46,470 --> 00:01:46,890
one.

23
00:01:46,940 --> 00:01:50,730
So minimum will be one and Max will be five.

24
00:01:51,450 --> 00:01:54,300
And I also want to set it up as required.

25
00:01:55,200 --> 00:01:56,220
Set up our array.

26
00:01:56,250 --> 00:01:56,880
True.

27
00:01:57,310 --> 00:02:00,660
And as far as the message, please provide.

28
00:02:01,440 --> 00:02:04,770
And let's say, review, rating or just rating.

29
00:02:05,460 --> 00:02:06,540
That's really up to you.

30
00:02:07,460 --> 00:02:11,640
Want our copy and paste just so I can speed this up a little bit?

31
00:02:11,850 --> 00:02:14,460
And next property value will be title.

32
00:02:14,940 --> 00:02:16,290
It's going to be type string.

33
00:02:19,110 --> 00:02:23,310
Title type string, let's trim it right away.

34
00:02:24,270 --> 00:02:27,450
So string and let's say trim.

35
00:02:28,230 --> 00:02:28,700
True.

36
00:02:29,190 --> 00:02:31,740
Now, minimax, we are more than one.

37
00:02:32,680 --> 00:02:41,020
And let's just add required, it's just basically leave required, and we'll call this please provide.

38
00:02:41,990 --> 00:02:46,880
Review Battle and let's also set up some kind of maxlength.

39
00:02:47,420 --> 00:02:50,720
So let's go with max and length.

40
00:02:51,110 --> 00:02:56,540
Max length in this case, and we're looking for a value off.

41
00:02:57,050 --> 00:02:58,810
I mean, I'm going to go with it.

42
00:02:58,970 --> 00:02:59,930
That's really up to you.

43
00:03:00,880 --> 00:03:05,890
Also, we want to set up a comment here, so it's this way.

44
00:03:06,340 --> 00:03:09,610
Copy and paste call this comment.

45
00:03:11,430 --> 00:03:13,860
Pipe string as far as trimming.

46
00:03:13,890 --> 00:03:15,660
I mean, I don't think we need to do that.

47
00:03:16,140 --> 00:03:23,310
And when it comes to required, yes, we'll say please provide a view and text and I'm not going to

48
00:03:23,310 --> 00:03:24,660
set up any kind of max link.

49
00:03:25,350 --> 00:03:30,870
And lastly, two more things we want to set up user and we want to set up the product.

50
00:03:31,260 --> 00:03:38,220
And if you remember, we needed to do that in the following way, we're going user one type will be

51
00:03:38,220 --> 00:03:38,590
what?

52
00:03:38,610 --> 00:03:43,280
Well, it's Mango's that schema dot and then object.

53
00:03:43,650 --> 00:03:44,040
Correct.

54
00:03:44,850 --> 00:03:49,920
So object and an I.D. As far as reference, we go with user.

55
00:03:50,670 --> 00:03:51,840
So user.

56
00:03:52,020 --> 00:04:00,060
And then lastly, we have a required so that equal to true and the same deal with a product because

57
00:04:00,060 --> 00:04:06,900
again, I know I'm repeating myself, but reviews are tied to user and the product.

58
00:04:07,620 --> 00:04:10,650
So user leaves a review on the product.

59
00:04:10,950 --> 00:04:11,280
Correct.

60
00:04:11,610 --> 00:04:12,840
That kind of makes sense.

61
00:04:13,350 --> 00:04:18,149
So say your product type same acquired the same.

62
00:04:18,600 --> 00:04:22,970
Now the difference is the RF ref now is a product, right?

63
00:04:22,980 --> 00:04:25,260
And we want to set up those timestamps time.

64
00:04:26,230 --> 00:04:28,770
Stamps and that is equal to.

65
00:04:29,170 --> 00:04:31,180
True, true here.

66
00:04:31,390 --> 00:04:32,830
And then we want to export that.

67
00:04:32,950 --> 00:04:38,350
So we go here with module exports is equal to a mongoose.

68
00:04:39,460 --> 00:04:42,880
Model and we go with a review.

69
00:04:43,690 --> 00:04:47,470
Review Karma and then review schema.

70
00:04:47,800 --> 00:04:56,080
And lastly, I want to add a piece of functionality which is going to ensure that user can leave only

71
00:04:56,080 --> 00:04:58,360
one review per product.

72
00:04:58,780 --> 00:05:07,150
Again, let me repeat the goal here is that so the user can leave only one review per product.

73
00:05:07,360 --> 00:05:13,210
And even though normally I show you how something fails and then the fix, in this case, it's going

74
00:05:13,210 --> 00:05:21,370
to be a little bit different because otherwise, if you already add some data in a database, it's not

75
00:05:21,370 --> 00:05:22,330
going to work.

76
00:05:22,900 --> 00:05:27,940
And then you'll just have to run around like a headless chicken, and therefore I'll write or show you

77
00:05:27,940 --> 00:05:28,480
the fix.

78
00:05:28,510 --> 00:05:33,730
Now, let me also tell you right away that there are two ways how we can do that.

79
00:05:33,730 --> 00:05:39,760
So one is going to be using the indexing right on a schema that's going to be something that I'm going

80
00:05:39,770 --> 00:05:42,760
to show you right now, and the other one is going to be in the controller.

81
00:05:43,090 --> 00:05:49,840
So once you get to create review controller, I'll show you another way how we can do that.

82
00:05:50,140 --> 00:05:58,660
And the idea is following where if you remember in Mongoose, we had an option to add unique.

83
00:05:58,990 --> 00:06:04,420
So if I go to a sorry, not user controller, we're looking for user review.

84
00:06:04,960 --> 00:06:08,970
Remember for email, we set this one unique equal to true.

85
00:06:08,980 --> 00:06:15,760
But if you remember, it's not really validation, it's the index that the Mongoose sets it up.

86
00:06:16,390 --> 00:06:22,180
So then if you try to add the same email, then you'll get back the error.

87
00:06:22,870 --> 00:06:29,740
Now, in this case, it's a little bit different, though, because I want to set up a compound index.

88
00:06:30,100 --> 00:06:34,780
I want to set up index for both for the user and a product.

89
00:06:35,080 --> 00:06:37,420
It's not like I can go here with unique and then unique.

90
00:06:37,840 --> 00:06:38,770
It's not going to work.

91
00:06:39,190 --> 00:06:44,830
The way we set that one up is following where we go with schema name in our case schema.

92
00:06:45,070 --> 00:06:52,600
And then if you want to have a compound index, meaning a index that entails multiple fields, you go

93
00:06:52,600 --> 00:06:53,860
with product.

94
00:06:54,430 --> 00:07:01,090
So the name of the field here, in my case, I'm going to go with product one user one and then we still

95
00:07:01,090 --> 00:07:06,850
need to set up that unique, true, unique and we're sort of equal to true.

96
00:07:07,060 --> 00:07:15,910
And once we save it, the result is going to be falling where the user can leave only one review per

97
00:07:15,910 --> 00:07:16,330
product.

98
00:07:16,660 --> 00:07:22,400
So it's not like user can just come in there and leave 100 reviews with a bad rating.

99
00:07:22,420 --> 00:07:27,640
No, only one review per product per user.

100
00:07:28,120 --> 00:07:29,290
Hopefully, that makes sense.

101
00:07:29,710 --> 00:07:31,960
And now I can proceed to the next step.

