Hardware cart and service cart

master
Bhaskar 11 months ago
parent a28365d866
commit 6b9e817084

@ -10,7 +10,7 @@ const fastify = require("fastify")({
return uuidv4();
},
});
const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors,generatequatationId} = require("../models/store");
const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors,generatequatationId, HardwareCart, ServiceCart} = require("../models/store");
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
@ -1228,3 +1228,61 @@ exports.getSinleQuotationData = async (req, reply) => {
});
}
};
exports.addToCartHardwareItems = async (req, reply) => {
try {
const { productId, productName, description, GST, unitPrice, quantity, totalAmount, serialId } = req.body;
const gstAmount = (GST / 100) * totalAmount;
const grandTotal = totalAmount + gstAmount;
const newCartItem = new HardwareCart({
productId,
productName,
description,
GST,
unitPrice,
quantity,
totalAmount,
grandTotal,
serialId
});
const savedItem = await newCartItem.save();
reply.code(201).send({ message: 'Item added to cart', data: savedItem });
} catch (error) {
console.error(error);
reply.code(500).send({ message: 'Error adding item to cart', error });
}
};
exports.addToCartService = async (req, reply) => {
try {
const { productId, productName, description, GST, unitPrice, quantity, totalAmount, serialId,installationId } = req.body;
const gstAmount = (GST / 100) * totalAmount;
const grandTotal = totalAmount + gstAmount;
const newCartItem = new ServiceCart({
installationId,
productId,
productName,
description,
GST,
unitPrice,
quantity,
totalAmount,
grandTotal,
serialId
});
const savedItem = await newCartItem.save();
reply.code(201).send({ message: 'Item added to cart', data: savedItem });
} catch (error) {
console.error(error);
reply.code(500).send({ message: 'Error adding item to cart', error });
}
};

@ -289,7 +289,38 @@ const sensorquotationSchema = new mongoose.Schema({
qutation_total_price: { type: String, default: null },
});
const hardwareCartSchema = new mongoose.Schema({
productId: { type: String},
productName: { type: String },
description: { type: String, default: null },
GST: { type: Number, min: 0 },
unitPrice: { type: Number, min: 0 },
quantity: { type: Number, min: 1 },
grandTotal: { type: Number, min: 0 },
totalAmount: { type: Number, min: 0 }, // Amount before GST
serialId: { type: String, default: null },
category: { type: String, enum: ['slaves', 'master', 'switches'], default: 'slaves' },
discount: { type: Number, default: 0, min: 0 },
}, {
timestamps: true,
});
const serviceCartSchema = new mongoose.Schema({
installationId: {type: String},
productId: { type: String},
productName: { type: String },
description: { type: String, default: null },
GST: { type: Number, min: 0 },
unitPrice: { type: Number, min: 0 },
quantity: { type: Number, min: 1 },
grandTotal: { type: Number, min: 0 },
totalAmount: { type: Number, min: 0 }, // Amount before GST
serialId: { type: String, default: null },
category: { type: String, enum: ['slaves', 'master', 'switches'], default: 'slaves' },
discount: { type: Number, default: 0, min: 0 },
}, {
timestamps: true,
});
const Insensors = mongoose.model('Insensors', insensorsSchema);
const Store = mongoose.model("Store", storeSchema);
@ -300,6 +331,8 @@ const sensorquotationSchema = new mongoose.Schema({
const SensorQuotation = mongoose.model('SensorQuotationSchema', sensorquotationSchema);
const Install = mongoose.model("Install", installationschema);
const HardwareCart = mongoose.model("HardwareCart", hardwareCartSchema);
const ServiceCart = mongoose.model("ServiceCart", serviceCartSchema);
module.exports = { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,generatequatationId};
module.exports = { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,generatequatationId, HardwareCart, ServiceCart};

@ -881,5 +881,52 @@ fastify.get("/api/getSingleQuotationData/:quotationId", {
handler: storeController.getSinleQuotationData,
});
fastify.post("/api/cart/hardwareItem", {
schema: {
description: "To add items to the Hardwarecart",
tags: ["Cart"],
summary: "Add item to Hardwarecart",
body: {
type: "object",
properties: {
productId: { type: "string", description: "Unique identifier for the product" },
productName: { type: "string", description: "Name of the product" },
description: { type: "string", description: "Product description", default: null },
GST: { type: "number", description: "GST applied to the product", minimum: 0 },
unitPrice: { type: "number", description: "Unit price of the product", minimum: 0 },
quantity: { type: "integer", description: "Quantity of the product", minimum: 1 },
totalAmount: { type: "number", description: "Total amount before GST", minimum: 0 },
serialId: { type: "string", description: "Serial identifier for the cart item", default: null }
},
//required: ["productId", "productName", "GST", "unitPrice", "quantity", "totalAmount"]
},
},
handler: storeController.addToCartHardwareItems
});
fastify.post("/api/cart/installationService", {
schema: {
description: "To add items to the Installation Service",
tags: ["Cart"],
summary: "Add item to Installation Service",
body: {
type: "object",
properties: {
installationId: { type: "string" },
productId: { type: "string"},
productName: { type: "string" },
description: { type: "string" },
GST: { type: "number", description: "GST applied to the product", minimum: 0 },
unitPrice: { type: "number", description: "Unit price of the product", minimum: 0 },
quantity: { type: "integer", description: "Quantity of the product", minimum: 1 },
totalAmount: { type: "number", description: "Total amount before GST", minimum: 0 },
serialId: { type: "string", description: "Serial identifier for the cart item", default: null }
},
//required: ["productId", "productName", "GST", "unitPrice", "quantity", "totalAmount"]
},
},
handler: storeController.addToCartService
});
next();
};

Loading…
Cancel
Save