-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created user registtation and vendor
- Loading branch information
1 parent
4f25b10
commit e317398
Showing
7 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Request, Response } from "express"; | ||
import Vendor from "../database/models/vendor"; | ||
import { saveVendor } from "../services/vendorServices"; | ||
|
||
export const registerVendor = async (req: Request, res: Response) => { | ||
const {userId, storeName, address, TIN, bankAccount, paymentDetails} = req.body | ||
if(!storeName || !address || !TIN || !bankAccount || !paymentDetails){ | ||
return res.status(400).json({message: "Please fill all the fields"}) | ||
} | ||
try { | ||
const result = await saveVendor(req.body) | ||
return res.status(200).json({message: "Vendor registered successfully", result}) | ||
} catch (error: any) { | ||
return res.status(500).json({message: error.message}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import express from "express" | ||
const route = express.Router() | ||
import { registerVendor } from "../controllers/vendor.controller" | ||
|
||
route.post('/registerVendor', registerVendor) | ||
|
||
export default route |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import User from "../database/models/user"; | ||
|
||
import bcrypt from 'bcrypt' | ||
export const saveUser = async (data: any) => { | ||
const { username, email, password } = data; | ||
const { name, email, password } = data; | ||
const hashedPwd = bcrypt.hashSync(password, 10) | ||
const insertUser = await User.create({ | ||
username: username, | ||
name: name, | ||
email: email, | ||
password: password, | ||
password: hashedPwd, | ||
}); | ||
return insertUser; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Vendor from "../database/models/vendor"; | ||
|
||
export const saveVendor = async (data: any) => { | ||
const {userId, storeName, address, TIN, bankAccount, paymentDetails} = data | ||
|
||
const insertVendor = await Vendor.create({ | ||
userId: userId, | ||
storeName: storeName, | ||
address: address, | ||
TIN: TIN, | ||
bankAccount: bankAccount, | ||
paymentDetails | ||
}) | ||
|
||
return insertVendor; | ||
} |