|
|
|
@ -1688,13 +1688,59 @@ return {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.addMediaToInsensor = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const { hardwareId, customerId, type } = req.params;
|
|
|
|
|
// const { urls, mediaType } = req.body;
|
|
|
|
|
|
|
|
|
|
// if (!hardwareId || !customerId || !type || !urls || !mediaType) {
|
|
|
|
|
// return reply.status(400).send({ success: false, message: "Missing required fields" });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const insensor = await Insensors.findOne({ hardwareId, customerId, type });
|
|
|
|
|
// if (!insensor) {
|
|
|
|
|
// return reply.status(404).send({ success: false, message: "Insensor not found" });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const mediaItems = urls.map(url => ({ url, createdAt: new Date() }));
|
|
|
|
|
|
|
|
|
|
// if (mediaType === 'video') {
|
|
|
|
|
// insensor.manualTestVideos.push(...mediaItems);
|
|
|
|
|
// } else if (mediaType === 'material') {
|
|
|
|
|
// insensor.materialReceivedPictures.push(...mediaItems);
|
|
|
|
|
// } else if (mediaType === 'workStatus') {
|
|
|
|
|
// insensor.workStatusPictures.push(...mediaItems);
|
|
|
|
|
// } else {
|
|
|
|
|
// return reply.status(400).send({ success: false, message: "Invalid mediaType" });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// await insensor.save();
|
|
|
|
|
|
|
|
|
|
// // ✅ fetch the updated document as plain object
|
|
|
|
|
// const updatedInsensor = await Insensors.findOne({ hardwareId, customerId, type }).lean();
|
|
|
|
|
// console.log("updatedInsensor",updatedInsensor)
|
|
|
|
|
// return reply.send({
|
|
|
|
|
// success: true,
|
|
|
|
|
// message: "Media saved successfully",
|
|
|
|
|
// data: updatedInsensor
|
|
|
|
|
// });
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.error("Error adding media to insensor:", error);
|
|
|
|
|
// return reply.status(500).send({ success: false, message: "Internal server error" });
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addMediaToInsensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { hardwareId, customerId, type } = req.params;
|
|
|
|
|
const { urls, mediaType } = req.body;
|
|
|
|
|
// const { hardwareId, customerId, type } = req.params;
|
|
|
|
|
// const { video, material, workStatus, product_status } = req.body;
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
const { hardwareId, type, video, material, workStatus, product_status } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hardwareId || !customerId || !type || !urls || !mediaType) {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "Missing required fields" });
|
|
|
|
|
if (!hardwareId || !customerId || !type) {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "Missing required params" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const insensor = await Insensors.findOne({ hardwareId, customerId, type });
|
|
|
|
@ -1702,27 +1748,34 @@ exports.addMediaToInsensor = async (req, reply) => {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "Insensor not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mediaItems = urls.map(url => ({ url, createdAt: new Date() }));
|
|
|
|
|
// Append if arrays are provided
|
|
|
|
|
if (Array.isArray(video) && video.length) {
|
|
|
|
|
const items = video.map(url => ({ url, createdAt: new Date() }));
|
|
|
|
|
insensor.manualTestVideos.push(...items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(material) && material.length) {
|
|
|
|
|
const items = material.map(url => ({ url, createdAt: new Date() }));
|
|
|
|
|
insensor.materialReceivedPictures.push(...items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mediaType === 'video') {
|
|
|
|
|
insensor.manualTestVideos.push(...mediaItems);
|
|
|
|
|
} else if (mediaType === 'material') {
|
|
|
|
|
insensor.materialReceivedPictures.push(...mediaItems);
|
|
|
|
|
} else if (mediaType === 'workStatus') {
|
|
|
|
|
insensor.workStatusPictures.push(...mediaItems);
|
|
|
|
|
} else {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "Invalid mediaType" });
|
|
|
|
|
if (Array.isArray(workStatus) && workStatus.length) {
|
|
|
|
|
const items = workStatus.map(url => ({ url, createdAt: new Date() }));
|
|
|
|
|
insensor.workStatusPictures.push(...items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update product_status if provided
|
|
|
|
|
if (product_status && ['pending', 'complete'].includes(product_status)) {
|
|
|
|
|
insensor.product_status = product_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await insensor.save();
|
|
|
|
|
|
|
|
|
|
// ✅ fetch the updated document as plain object
|
|
|
|
|
const updatedInsensor = await Insensors.findOne({ hardwareId, customerId, type }).lean();
|
|
|
|
|
console.log("updatedInsensor",updatedInsensor)
|
|
|
|
|
const updated = await Insensors.findOne({ hardwareId, customerId, type }).lean();
|
|
|
|
|
return reply.send({
|
|
|
|
|
success: true,
|
|
|
|
|
message: "Media saved successfully",
|
|
|
|
|
data: updatedInsensor
|
|
|
|
|
data: updated
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error adding media to insensor:", error);
|
|
|
|
@ -1732,8 +1785,6 @@ exports.addMediaToInsensor = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.mastrerList = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId, installationId } = req.params;
|
|
|
|
|