1 00:00:01,030 --> 00:00:02,600 We have installed the Mongoose update. 2 00:00:02,620 --> 00:00:07,480 If current module into our tickets service let's now go back over to our editor we're gonna wire this 3 00:00:07,480 --> 00:00:11,260 thing up to our ticket model and then start to write out a couple of tests just to make sure that it 4 00:00:11,260 --> 00:00:13,150 behaves as expected. 5 00:00:13,160 --> 00:00:18,870 So back inside my editor I'm gonna find the tickets service make sure inside a ticket service we've 6 00:00:18,870 --> 00:00:22,950 been working inside of orders inside they're going to find the models directory and find the ticket 7 00:00:22,950 --> 00:00:25,400 to yes file then at the very top. 8 00:00:25,440 --> 00:00:32,080 I will import update if current plugin from Mongoose update if 9 00:00:37,240 --> 00:00:40,960 we're going to wire this thing up to our ticket schema that we created a little bit lower on inside 10 00:00:40,960 --> 00:00:43,960 the file so I can scroll on down a little bit to our ticket schema. 11 00:00:43,960 --> 00:00:49,300 Here it is right here and then right after the ticket Schema Definition we're gonna add in two lines 12 00:00:49,300 --> 00:00:55,000 of configuration by going to first say ticket schema plugin and passing the update. 13 00:00:55,000 --> 00:01:00,550 If current plugin and then right above that very important do we put this right above. 14 00:01:00,650 --> 00:01:04,580 We're also going to tell muggers that we want to track the version of all these different documents 15 00:01:04,820 --> 00:01:10,670 using the field version so using some property named version instead of the default of underscore underscore 16 00:01:10,670 --> 00:01:16,760 V which as we've seen is the default version field with Mongoose so to rename that field we're going 17 00:01:16,760 --> 00:01:26,120 to write out ticket schema set version key to simply version instead and that's it now by making this 18 00:01:26,120 --> 00:01:27,500 change the version key right here. 19 00:01:27,500 --> 00:01:32,510 There's one other little change we have to make inside of our ticket dock interface so I can scroll 20 00:01:32,510 --> 00:01:37,840 up a little bit here's the ticket dock interface and remember the goal of this interface was to list 21 00:01:37,840 --> 00:01:42,540 out all the different properties that a document has or an instance of a ticket has. 22 00:01:42,550 --> 00:01:46,540 So this was an interface that list out not only the properties that a ticket has though specifically 23 00:01:46,540 --> 00:01:52,300 a title price and user I.D. but it also includes all the properties that a normal document has as well. 24 00:01:52,300 --> 00:01:56,770 One of the properties listed inside of the Mongoose Scott document interface is underscore underscore 25 00:01:56,770 --> 00:02:02,230 V and that's what would normally allow us to write out some code such as ticket dot underscore underscore 26 00:02:02,230 --> 00:02:03,010 V. 27 00:02:03,070 --> 00:02:07,030 Normally if we had a ticket and if you're working on the ticket document we could write this out and 28 00:02:07,060 --> 00:02:11,620 typescript would be absolutely okay with that because inside of this interface definition is something 29 00:02:11,620 --> 00:02:15,610 that says that a ticket has an underscore underscore the property. 30 00:02:15,610 --> 00:02:16,750 So we just change that. 31 00:02:16,760 --> 00:02:21,040 We are now saying that to access the version fields we want to write out Beal to write out something 32 00:02:21,040 --> 00:02:27,580 such as ticket dot version this version property is not defined inside of the document interface. 33 00:02:27,580 --> 00:02:31,120 Nothing inside there says that a document has a version property. 34 00:02:31,420 --> 00:02:36,190 So to help typescript to understand that a instance of a ticket has a version property you and I have 35 00:02:36,190 --> 00:02:38,020 to manually add it to the ticket doc. 36 00:02:38,050 --> 00:02:44,120 Interface so version is going to be a number like so and that is what is going to allow us to write 37 00:02:44,120 --> 00:02:50,330 out something such as ticket Doc version without touch script complaining at us get some believe it 38 00:02:50,330 --> 00:02:54,980 or not that is it for wiring up this optimistic concurrency control stuff but at this point I dunno 39 00:02:54,980 --> 00:02:59,510 about you I'm thinking what did that do for us and that's why I would really like to write out a quick 40 00:02:59,510 --> 00:03:04,370 test or two I want to write out a test and make sure that this version field is going to be tracked 41 00:03:04,430 --> 00:03:09,270 automatically and make sure that if we try to save some record out of the appropriate order we're gonna 42 00:03:09,290 --> 00:03:16,420 see some kind of error inside of my model struct free again inside of my ticket service I'm going to 43 00:03:16,420 --> 00:03:22,330 create a new folder of underscore underscore test underscore underscore inside of there I'll make a 44 00:03:22,330 --> 00:03:25,250 new file of ticket test T.S. 45 00:03:27,970 --> 00:03:34,240 and then at the top we'll immediately start to write our test I'm going to import the ticket model from 46 00:03:34,330 --> 00:03:40,260 up one directory ticket and then we're going to write out for right now just one simple test and we'll 47 00:03:40,260 --> 00:03:48,900 get this description of it implements optimistic concurrency control we can probably think of a better 48 00:03:48,900 --> 00:03:54,000 title for this test but I just want you to kind of have this term around to see a reminder of what this 49 00:03:54,000 --> 00:03:57,730 stuff is all about it rather than having this video take a really long time. 50 00:03:57,740 --> 00:04:01,200 However let's take a pause right here and then write out the implementation for this test in just a 51 00:04:01,200 --> 00:04:01,530 moment.