customer details added
This commit is contained in:
parent
9983c73643
commit
3238facf79
@ -4,7 +4,12 @@ import { sendCakeOrderMail } from "../../utils/mailer.js";
|
||||
// POST → Create new cake order
|
||||
export const createCakeOrder = async (req, res) => {
|
||||
try {
|
||||
let { order, email, totalPieces, totalPrice, hst } = req.body;
|
||||
let { name, phone, cemail, email, order, totalPieces, totalPrice, hst } = req.body;
|
||||
|
||||
// ✅ Validation
|
||||
if (!name || !phone || !cemail) {
|
||||
return res.status(400).json({ message: "Name, phone, and email are required" });
|
||||
}
|
||||
|
||||
if (!order || typeof order !== "object") {
|
||||
return res.status(400).json({ message: "Order data is required" });
|
||||
@ -19,16 +24,26 @@ export const createCakeOrder = async (req, res) => {
|
||||
hst = parseFloat((totalPrice * 0.13).toFixed(2));
|
||||
}
|
||||
|
||||
const newOrder = await CakeOrder.create({ order, email, totalPieces, totalPrice, hst });
|
||||
// ✅ Create new order
|
||||
const newOrder = await CakeOrder.create({
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
cemail,
|
||||
order,
|
||||
totalPieces,
|
||||
totalPrice,
|
||||
hst,
|
||||
});
|
||||
|
||||
// Send email (async)
|
||||
// ✅ Send email (async)
|
||||
if (email) {
|
||||
sendCakeOrderMail(email, order, totalPieces, totalPrice, hst)
|
||||
sendCakeOrderMail(name, cemail, phone, email, order, totalPieces, totalPrice, hst)
|
||||
.then(() => console.log("Cake order email sent to", email))
|
||||
.catch((err) => console.error("Email send failed:", err));
|
||||
}
|
||||
|
||||
// ✅ Return HST in response
|
||||
// ✅ Return response
|
||||
res.status(201).json({
|
||||
message: "Cake order created successfully",
|
||||
data: newOrder,
|
||||
|
||||
@ -11,7 +11,10 @@ const FlavourSchema = new mongoose.Schema({
|
||||
// Main Cake Order schema
|
||||
const CakeOrderSchema = new mongoose.Schema(
|
||||
{
|
||||
email: { type: String, required: true },
|
||||
name: { type: String, required: true }, // ✅ New field
|
||||
phone: { type: String, required: true }, // ✅ New field
|
||||
cemail: { type: String, required: true }, // ✅ New field
|
||||
email: { type: String, required: true }, // ✅ Already existed, keep required
|
||||
order: {
|
||||
type: Map,
|
||||
of: [FlavourSchema], // Each category has an array of flavour objects
|
||||
@ -19,7 +22,7 @@ const CakeOrderSchema = new mongoose.Schema(
|
||||
},
|
||||
totalPieces: { type: Number, required: true },
|
||||
totalPrice: { type: Number, required: true },
|
||||
hst: { type: Number, required: false, default: 0 }, // ✅ Added HST field
|
||||
hst: { type: Number, default: 0 }, // HST
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
@ -63,7 +63,7 @@ export async function sendResetPasswordMail(email, token) {
|
||||
}
|
||||
|
||||
|
||||
export const sendCakeOrderMail = async (email, order, totalPieces, totalPrice, hst) => {
|
||||
export const sendCakeOrderMail = async (name, cemail, phone, email, order, totalPieces, totalPrice, hst) => {
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: "mail.metatron-admin-backend.metatronhost.com",
|
||||
@ -115,7 +115,21 @@ export const sendCakeOrderMail = async (email, order, totalPieces, totalPrice, h
|
||||
<img src="cid:banner" style="width:100%;max-height:300px;object-fit:cover;border-radius:0 0 20px 20px;"/>
|
||||
</div>
|
||||
<h2 style="color:rgb(255 135 174);font-family:'Brush Script MT',cursive;font-size:22px;margin-bottom:12px;font-weight:700;">Order Details</h2>
|
||||
|
||||
<div style="padding:15px 25px;text-align:center;">
|
||||
|
||||
<div style="background-color:#f8f8f8; padding:15px 20px; border-radius:10px; max-width:500px; margin:15px 0; font-family:Arial, sans-serif; color:#333;">
|
||||
<h4 style="margin-bottom:10px; color:#d72631; font-size:16px;">Customer Details</h4>
|
||||
<p style="margin:5px 0; font-size:14px;">
|
||||
<strong style="width:120px; display:inline-block;">Name:</strong> ${name}
|
||||
</p>
|
||||
<p style="margin:5px 0; font-size:14px;">
|
||||
<strong style="width:120px; display:inline-block;">Email:</strong> ${cemail}
|
||||
</p>
|
||||
<p style="margin:5px 0; font-size:14px;">
|
||||
<strong style="width:120px; display:inline-block;">Phone:</strong> ${phone}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<table style="width:100%;border-collapse:collapse;font-size:14px;margin:0 auto 15px;">
|
||||
<thead>
|
||||
<tr style="background-color:#faf4f0;color:#d72631;font-weight:600;">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user