-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplan.txt
105 lines (96 loc) · 5.04 KB
/
plan.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
[+] Start with npm init command
[+] Install some dependencies for the project
- express, nodemon, dotenv
-esm // To use javascript {import} Not require
[+] Create a server.js file for making project
[+] We will create a .env file and define our PORT there
[+] Than we will create a {Config} folder and inside it {index.js}
- We will import all variables that is defined in .env file and than export it
- So, we can use it in our server file
[+] Than create a folder for Routes and inside it a file {index.js}
- Use express.router and export and than import it in server.js file
[+] Than create a controller folder and inside it make a auth folder and index.js and than {registerController.js} file inside the auth
- And write the register logic inside this file
[+] Follow the checklist that your logic follow or Not for Register
[1] Validate the request
[2] Authorise the request
[3] Check if user is in the database already
[4] Hash the password
[5] prepare model
[6] Store in database
[7] Generate the JWT Token
[8] Send response
Dependencies
- joi // For valiadation of email, username etc.
-mongoose
-jsonwebtoken // For Token Generation
[+] Create a middlewares folder and inside it {errorHandler.js} file export and import it in server.js file to dispay the error.
[NOTE] : IMPORT IN SERVEr.JS at LOW POINT OR DOWN OR JUST ABOVE THE CONNECTION
[+] Create a DEBUG_MODE = true in .env file. So, we will not show our server error details to the user
[3] Now we check the 3rd rule in our request
- For this, we have to write code in try & catch block. And find that user is already exist or not
- And if exist than we will show the error. And for this we have to make a folder services and inside it {customErrorHandler.js} file. to write our custom error and display to the user in frontEnd
[+] Create the model folder and {index.js & user.js}
[+] Create the schema and export to registerController file
- Follow the checklist from 4
[7] create a file {JwtServices.js} in services folder and write the code to generate the jsonwebtoken and import it in registerController.js
- Than save the user details and send the access_token
[+] LogIn method starts
- Create the login route in routes.js file
[1] valiadation
[2] Check the email exist or not
[3] Compare password
[4] Token generation
[+] Who am i : making get request to know the details using the token generated by the JWT
- make 'me' route
NOTE : TESTING THIS IN GET REQUEST HEADER SECTION & Check "Authorization" : Bearer {token}
ANFD TOKEN WILL BE THE LOGIN GENERATED TOKEN
- Create a userController.js and write the code
- Create a service of verify token in JwtService
- create a auth.js middleware to verify the token for correct user to display the id
- create a custom error of not Found
[+] Refresh token
- Send refresh_token also from the registerController.js
- Make another key in .env file for this
- import that key in registerController.js
- make model refreshToken.js and create model to store the token
- import in registerController and create and send to the user
- do same in loginController.js
[+] Make route for refresh and refreshController.js in auth folder
[1] Validation
[2] checking token in database
[3] token generation
[4] save in the database
[+] Logout
- make route
[-] Validation
[-] route testing in HEADER , AUTHORIZATION Bearer access_token & In JSON refresh_token
////////// Making product section from here ///////
[+] Create the post route for the product
[+] Create the model for the product
[+] Dependencies for multiForm data
- multer
[+] Multer setup in the productController file
[+] Create a folder named 'uploads' to store the image
NOTE: IMAGE FILENAME SHOULD BE UNIQUE
[+] Set Image size
[+] validation using joi
[+] Sending and creating the file in the database
////////////Updating the product file
[+] Create the route and test link on the thunderClient
[+] make the admin middleware
[+] create the update functionality on the productController
//////////Delete the product
[+] Create the route and test route in thunderClient
[+] Create the destroy functionality on the productController
// Get all products
[+] Create the route and test route in the thunderClient functionality
[+] Than we write the index functionality in the productController to display our data
[+] But we need to display the image in the form of
//http://localhost:5000/uploads/92759-473.png. So, for thie we use getter method in the product model
// Get the single product
[+] Create the route and test route in the thunderClient
NOTE: FOR IMAGE DESTROY FUNCTIONALITY. we will use ._doc.image because
image will call getter and we will get the file this:
http://localhost/uploads/93747823-387.png
but we are adding this http://localhost manually on destroy functionality. so, we dont want the full address of image so we will use _doc.image it will make the image path to uploads/o374298-3987.png