git clone empty repo -> cd foldername -> npm init -> (package.json is made )
tsc --init (to have tsconfig file)
created index.ts in Main folder
dont forget to add scripts to package.json file for index.ts
- utility
- services
- routes
- models
- middlewares
- images
- images
- dto
- controllers
- config
Then we moved to contollers Folder to control AdminRoute and inside AdminControll.ts we created three functions that are
CreateVandor : for posting data
GetVandor : for getting all vandors
GetVandorbyID : getting vandor by ID
- router.post('/vandor',CreateVandor)
- router.post('/vandors',GetVandor )
- router.post('/vandor/:id',GetVandorbyID)
Now we moved to dto folder (Data Transfer Object)
We created Vandor Interface (you can say class)
For fetching data from url we will use body-parser in main file
Then we completed CreateVandor function in AdminControl.ts file
Inside Vandor Scema foods field is an array of object ids , basciaaly its forein key from Food Table
It's an array of objects, where each object is expected to be of type mongoose.Schema.ObjectId and is referring to the "food" model (specified by ref: "food")
Creating a vandor in AdminController.ts , checking if it already exists and using salt excrypting the password
A Password utility is made inside utility folder where generating salt and hashing is done.
Install below first :
As you can see now we are not able to see the password in JSON format which is good for security purpose , but in database they all are stored , so hacker will not be able to acess password or salt from json response as we have removed it .
20 dec 23
Storing helper classes in utility folder if data is not available or incorrect
Completed getVandors , getvandorById
The signature verification process involves the use of a secret key that only the server knows. The key is used to sign the JWT when it is created and to verify the signature when the JWT is presented to the server. The signature is a cryptographic hash generated using this secret key and the content of the JWT (header and payload).
In payload variable we are able to acess id , name , email , foodTypes
Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files
# PART 4