add user done
This commit is contained in:
parent
ecbd327750
commit
befe4a2374
@ -15,7 +15,7 @@ const sendToken = (user, statusCode, res) => {
|
|||||||
// res.status(statusCode).json({
|
// res.status(statusCode).json({
|
||||||
|
|
||||||
success: true,
|
success: true,
|
||||||
// userId: user._id,
|
userId: user._id,
|
||||||
// userName: user.name,
|
// userName: user.name,
|
||||||
// userEmail: user.email,
|
// userEmail: user.email,
|
||||||
// userPhone: user.phone,
|
// userPhone: user.phone,
|
||||||
|
@ -53,6 +53,61 @@ export const AddshippingAddress = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const AddshippingAddressByAdmin = async (req, res) => {
|
||||||
|
// console.log("request came here ", req.params._id);
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
first_Name,
|
||||||
|
last_Name,
|
||||||
|
phone_Number,
|
||||||
|
street,
|
||||||
|
city,
|
||||||
|
state,
|
||||||
|
postalCode,
|
||||||
|
country,
|
||||||
|
} = req.body;
|
||||||
|
switch (true) {
|
||||||
|
//validation
|
||||||
|
case !first_Name: {
|
||||||
|
return res.status(404).json({ msg: "please provide first_Name" });
|
||||||
|
}
|
||||||
|
case !last_Name: {
|
||||||
|
return res.status(404).json({ msg: "please provide last_Name" });
|
||||||
|
}
|
||||||
|
case !phone_Number: {
|
||||||
|
return res.status(404).json({ msg: "please provide phone_Number" });
|
||||||
|
}
|
||||||
|
case !street: {
|
||||||
|
return res.status(404).json({ msg: "please provide street" });
|
||||||
|
}
|
||||||
|
case !city: {
|
||||||
|
return res.status(404).json({ msg: "please provide city" });
|
||||||
|
}
|
||||||
|
case !state: {
|
||||||
|
return res.status(404).json({ msg: "please provide state" });
|
||||||
|
}
|
||||||
|
case !postalCode: {
|
||||||
|
return res.status(404).json({ msg: "please provide postalCode" });
|
||||||
|
}
|
||||||
|
case !country: {
|
||||||
|
return res.status(404).json({ msg: "please provide country" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req.body.user = req.params._id;
|
||||||
|
const address = await shippingAddress.create(req.body);
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
address,
|
||||||
|
message: "shipping Address Added",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
// For website
|
// For website
|
||||||
export const getSingleUserSippingAddress = async (req, res) => {
|
export const getSingleUserSippingAddress = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@ -192,14 +247,13 @@ export const updateShippingAddress = async (req, res) => {
|
|||||||
state,
|
state,
|
||||||
postalCode,
|
postalCode,
|
||||||
country,
|
country,
|
||||||
}
|
};
|
||||||
const updateShippingAddress = await shippingAddress.findByIdAndUpdate(
|
const updateShippingAddress = await shippingAddress.findByIdAndUpdate(
|
||||||
{ _id: _id },
|
{ _id: _id },
|
||||||
{ $set: updateAddressData },
|
{ $set: updateAddressData },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
updateShippingAddress,
|
updateShippingAddress,
|
||||||
@ -215,8 +269,8 @@ export const updateShippingAddress = async (req, res) => {
|
|||||||
|
|
||||||
export const getSingleSippingAddress = async (req, res) => {
|
export const getSingleSippingAddress = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
let _id = req.params.id
|
let _id = req.params.id;
|
||||||
const address = await shippingAddress.findById({ _id: _id })
|
const address = await shippingAddress.findById({ _id: _id });
|
||||||
|
|
||||||
if (address) {
|
if (address) {
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
|
@ -6,11 +6,20 @@ import {
|
|||||||
getSingleUserSippingAddressForAdmin,
|
getSingleUserSippingAddressForAdmin,
|
||||||
updateShippingAddress,
|
updateShippingAddress,
|
||||||
getSingleSippingAddress,
|
getSingleSippingAddress,
|
||||||
|
AddshippingAddressByAdmin,
|
||||||
} from "./ShippingAddressController.js";
|
} from "./ShippingAddressController.js";
|
||||||
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
||||||
|
router
|
||||||
|
.route("/admin/new/:_id")
|
||||||
|
.post(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
AddshippingAddressByAdmin
|
||||||
|
);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/user/address/")
|
.route("/user/address/")
|
||||||
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
||||||
|
@ -11,6 +11,8 @@ import { Order } from "../Orders/orderModel.js";
|
|||||||
export const registerUser = async (req, res) => {
|
export const registerUser = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { name, email, password, phone } = req.body;
|
const { name, email, password, phone } = req.body;
|
||||||
|
// console.log("this is the password ", password, name, req.body);
|
||||||
|
|
||||||
let findUser = await User.findOne({ email });
|
let findUser = await User.findOne({ email });
|
||||||
if (findUser) {
|
if (findUser) {
|
||||||
return res
|
return res
|
||||||
@ -46,11 +48,16 @@ export const registerUser = async (req, res) => {
|
|||||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||||
|
|
||||||
subject: `Welcome to Smellika - Let the Shopping Begin!`,
|
subject: `Welcome to Smellika - Let the Shopping Begin!`,
|
||||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
html: ` <h1 style="color: #333; text-align: left; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||||
<strong style="color: #1b03a3; font-size: 16px"> Hey ${name},</strong>
|
<strong style="color: #1b03a3; font-size: 16px"> Hey ${name},</strong>
|
||||||
|
|
||||||
<p style="color: #555; font-size: 15px;">Welcome to Smellika! We're thrilled to have you on board. Get ready for a world of exclusive deals, exciting products, and seamless shopping experiences. Start exploring now!</p>
|
<p style="color: #555; font-size: 15px;">Welcome to Smellika! We're thrilled to have you on board. Get ready for a world of exclusive deals, exciting products, and seamless shopping experiences. Start exploring now!</p>
|
||||||
<br/>
|
<br/>
|
||||||
|
<p style="color: #555; font-size: 15px;">You can login into : https://smellika.com</p>
|
||||||
|
<br/>
|
||||||
|
<p style="color: #555; font-size: 15px;">Below are your login credentials:</p>
|
||||||
|
<p style="color: #555; font-size: 15px;">Email: ${email}</p>
|
||||||
|
<p style="color: #555; font-size: 15px;">Password: ${password}</p>
|
||||||
<span style="color: #555; font-size: 13px;">Happy shopping,</span><br/>
|
<span style="color: #555; font-size: 13px;">Happy shopping,</span><br/>
|
||||||
|
|
||||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||||
|
Loading…
Reference in New Issue
Block a user