1 00:00:00,820 --> 00:00:06,700 In the last video we left off having just created a class User right here once again if you see a warning 2 00:00:06,760 --> 00:00:09,070 around this class definition that's totally fine. 3 00:00:09,070 --> 00:00:11,440 We're going to fix it up in just a second. 4 00:00:11,440 --> 00:00:14,700 So in this video I want to focus on our implementation of a user. 5 00:00:14,740 --> 00:00:19,360 Remember we had said that a user should have a couple of different properties assigned to it. 6 00:00:19,390 --> 00:00:24,860 There will be randomly generated that should probably be like a user's name and their location as well. 7 00:00:25,760 --> 00:00:30,660 To get started I think that we should define a couple of different fields on our User class. 8 00:00:30,740 --> 00:00:34,570 Then we can figure out how to randomly generate those properties all right. 9 00:00:34,620 --> 00:00:39,550 I'm gonna flip back over to my class definition and inside of here I'm going to assign two different 10 00:00:39,550 --> 00:00:40,980 properties to my user. 11 00:00:41,200 --> 00:00:46,780 I'm going to say that every user is going to have a name property that has a string and a location property 12 00:00:47,440 --> 00:00:54,070 that's going to be an object that has a latitude that is a number and a longitude that is a number as 13 00:00:54,070 --> 00:00:54,340 well. 14 00:00:55,120 --> 00:00:56,770 So that stands for latitude. 15 00:00:56,830 --> 00:00:59,170 LNG stands for longitude. 16 00:00:59,170 --> 00:01:05,080 Remember we can use latitude and longitude to model a physical location in the world. 17 00:01:05,080 --> 00:01:11,020 So we're going to eventually randomly generate a latitude and longitude assign it to this user and use 18 00:01:11,020 --> 00:01:15,360 that data to decide where to map a user on our Google Map interface. 19 00:01:17,530 --> 00:01:17,840 Okay. 20 00:01:17,860 --> 00:01:22,340 So now that we've defined these properties right here we need to eventually initialize them. 21 00:01:22,390 --> 00:01:28,000 Remember every time we define a property we need to in either initialize it on the same exact line or 22 00:01:28,000 --> 00:01:30,050 inside the constructor. 23 00:01:30,160 --> 00:01:34,700 Usually we will initialize the property on the same line if it's gonna be some hardcoded value. 24 00:01:34,840 --> 00:01:40,300 But in this case we want to randomly generate a name and a latitude and longitude so we will instead 25 00:01:40,300 --> 00:01:44,920 do our initialization inside of a constructor function instead. 26 00:01:45,070 --> 00:01:48,100 So I'm going to define my constructor function right here. 27 00:01:48,100 --> 00:01:49,840 Like so all right. 28 00:01:49,840 --> 00:01:53,790 So we've got our place to initialize the name latitude longitude. 29 00:01:53,830 --> 00:01:56,710 All we need now is our randomly generated data. 30 00:01:56,800 --> 00:02:01,300 So for that let's take a look at some documentation for a library that we're going to use to generate 31 00:02:01,300 --> 00:02:03,680 that information all right. 32 00:02:03,710 --> 00:02:05,500 So quick link right here. 33 00:02:05,580 --> 00:02:11,950 We're gonna go to NPM J.S. dot com and take a look at the documentation for a package called Faker The 34 00:02:11,950 --> 00:02:16,650 fake or package gives us the ability to randomly generate a bunch of different types of information 35 00:02:16,980 --> 00:02:20,210 which makes it really well suited for the project we are working on right now. 36 00:02:20,820 --> 00:02:27,450 So I'm going to go to NPM J.S. dot com once here I'm going to search for faker at the top and I should 37 00:02:27,450 --> 00:02:29,490 see it as one the first results on here. 38 00:02:31,840 --> 00:02:33,440 All right so here's the documentation. 39 00:02:33,590 --> 00:02:35,190 You can scroll down a little bit. 40 00:02:36,080 --> 00:02:40,580 And underneath API right here or some not API next section down here we go. 41 00:02:40,610 --> 00:02:42,140 API methods. 42 00:02:42,230 --> 00:02:45,830 This is the absolute extent of all the documentation we get. 43 00:02:45,870 --> 00:02:47,820 Unfortunately it's not super detailed. 44 00:02:47,870 --> 00:02:53,720 So what this is essentially saying is that the faker package has a module inside of it called address 45 00:02:54,230 --> 00:03:01,070 and we can use the address module to randomly generate a zip code a city street name a county a country 46 00:03:01,070 --> 00:03:02,660 state latitude longitude. 47 00:03:02,690 --> 00:03:04,670 Well those look really relevant. 48 00:03:04,670 --> 00:03:11,660 And so on likewise there is a company module that we can use to randomly generate a catchphrase or a 49 00:03:11,660 --> 00:03:18,600 company name and so on if you scroll down a little bit more you'll also find a section inside of here 50 00:03:18,630 --> 00:03:21,770 called name. 51 00:03:22,030 --> 00:03:26,650 And we can use this module to generate a first name last name and so on. 52 00:03:26,760 --> 00:03:32,030 So as you might guess we're gonna use this name module to generate some information for our user. 53 00:03:32,030 --> 00:03:39,230 We'll use the company module backup here to generate some random information for the companies we create 54 00:03:39,230 --> 00:03:40,970 inside of our app. 55 00:03:40,970 --> 00:03:46,460 And finally for both the user and the company we'll use the address module to generate a random latitude 56 00:03:46,490 --> 00:03:49,050 and longitude. 57 00:03:49,150 --> 00:03:52,870 So looks like the faker module is really going to take care of all of our data requirements for our 58 00:03:52,870 --> 00:03:54,010 application. 59 00:03:54,010 --> 00:03:56,230 So all we have to do is install this thing. 60 00:03:56,430 --> 00:04:01,010 So to install this package I need to flip back or add my terminal inside of my project directory. 61 00:04:01,170 --> 00:04:08,430 I'm going to stop the running partial server with control C then I'll do an npm install Baker like so. 62 00:04:08,660 --> 00:04:10,600 And that's pretty much it. 63 00:04:10,640 --> 00:04:15,440 Now the package is pretty small so it should complete installation rather quickly once it's all done 64 00:04:15,440 --> 00:04:18,850 it will start up partial once again with partial index. 65 00:04:18,880 --> 00:04:21,670 Each demo All right. 66 00:04:21,670 --> 00:04:27,340 So now we can flip back over to our Ed and make use of faker to do so I'm gonna go to the top of the 67 00:04:27,340 --> 00:04:35,200 file inside my user file and I'm going to import the faker module import statements inside of typescript 68 00:04:35,260 --> 00:04:39,030 look identical to import statements in yes 2015. 69 00:04:39,070 --> 00:04:44,170 So if you've ever worked on a react or angular application you're probably gonna be right at home. 70 00:04:44,260 --> 00:04:47,620 In other words to access a module that we install with NPM. 71 00:04:47,710 --> 00:04:55,960 We have to do is write out import faker from faker like so that's going to reach into our package to 72 00:04:55,980 --> 00:04:58,150 me node modules directory right here. 73 00:04:58,560 --> 00:05:03,120 It's gonna find that faker module that we just installed and it's going to give us access to all the 74 00:05:03,120 --> 00:05:07,090 code inside there through a variable called faker. 75 00:05:07,100 --> 00:05:09,100 Now there's just one little issue here. 76 00:05:09,200 --> 00:05:14,780 If we hover over faker we're going to see a little error message right here it says could not find a 77 00:05:14,780 --> 00:05:17,680 declaration file for module faker. 78 00:05:17,720 --> 00:05:22,730 Now this is an error or a warning that you're going to see many many many times as you start to work 79 00:05:22,730 --> 00:05:24,170 on types of projects. 80 00:05:24,170 --> 00:05:27,950 So let's take a quick pause right here and talk about why we are seeing this little warning message.