|
|
|
@ -3,7 +3,7 @@ const bcrypt = require('bcrypt');
|
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
const customJwtAuth = require("../customAuthJwt");
|
|
|
|
|
const { Deparments } = require("../models/Department");
|
|
|
|
|
const { Install, SensorStock, SensorQuotation, Order, Insensors, MasterSlaveData, ElectrictyWorkPictures, PlumbingWorkPictures, MaterialRecievedPictures, Support } = require("../models/store");
|
|
|
|
|
const { Install, SensorStock, SensorQuotation, Order, Insensors, MasterSlaveData, ElectrictyWorkPictures, PlumbingWorkPictures, MaterialRecievedPictures, Support, Repairorder } = require("../models/store");
|
|
|
|
|
const { Counter, User } = require("../models/User");
|
|
|
|
|
const { IotData, Tank } = require("../models/tanks");
|
|
|
|
|
const moment = require('moment-timezone');
|
|
|
|
@ -10923,3 +10923,48 @@ exports.resolveIssueIfAllConnected = async (req, reply) => {
|
|
|
|
|
return reply.code(500).send({ error: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createRepairOrder = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { supportId, customerId } = req.params;
|
|
|
|
|
const { storeId, replacements, status } = req.body;
|
|
|
|
|
|
|
|
|
|
// Validate required path params
|
|
|
|
|
if (!supportId || !customerId) {
|
|
|
|
|
return reply.code(400).send({ error: "supportId and customerId are required in path params" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate replacements
|
|
|
|
|
if (!Array.isArray(replacements) || replacements.length === 0) {
|
|
|
|
|
return reply.code(400).send({ error: "Replacements array is required in body and must contain at least one item" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const r of replacements) {
|
|
|
|
|
if (!["master", "slave", "sensor"].includes(r.type) || !r.oldHardwareId || !r.newHardwareId) {
|
|
|
|
|
return reply.code(400).send({ error: "Each replacement must have valid type, oldHardwareId, and newHardwareId" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the repair order
|
|
|
|
|
const newRepairOrder = await Repairorder.create({
|
|
|
|
|
customerId,
|
|
|
|
|
supportId,
|
|
|
|
|
storeId,
|
|
|
|
|
status: status || "pending",
|
|
|
|
|
replacements
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 201,
|
|
|
|
|
message: "Repair order created successfully",
|
|
|
|
|
repairOrder: newRepairOrder
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error creating repair order:", error);
|
|
|
|
|
return reply.code(500).send({ error: "Internal server error" });
|
|
|
|
|
}
|
|
|
|
|
};
|