DATE formate changes

master^2
Bhaskar 4 months ago
parent fa0505acdc
commit 19d4134452

@ -5346,6 +5346,71 @@ exports.particularCategory = async (req, reply) => {
// exports.assignCategorizeIssue = async (request, reply) => {
// const { supportId } = request.params;
// const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;
// if (!support_teamMemberId || !startDate || !endDate || !category || !masterHardwareId) {
// return reply.code(400).send({ error: 'support_teamMemberId, startDate, endDate, category, and masterHardwareId are required' });
// }
// const support = await Support.findOne({ supportId });
// if (!support) {
// return reply.code(404).send({ error: 'Support record not found' });
// }
// const teamMembers = support.team_member?.team_member || [];
// const teamMember = teamMembers.find(m => m.support_teamMemberId === support_teamMemberId);
// if (!teamMember) {
// return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
// }
// const start = new Date(startDate);
// const end = new Date(endDate);
// if (isNaN(start) || isNaN(end)) {
// return reply.code(400).send({ error: 'Invalid startDate or endDate' });
// }
// // ✅ Format to "DD-MM-YYYY HH:mm:ss"
// const formattedStart = moment(start).format("DD-MM-YYYY HH:mm:ss");
// const formattedEnd = moment(end).format("DD-MM-YYYY HH:mm:ss");
// let assignedCount = 0;
// support.categorizedIssues.forEach(issue => {
// if (
// issue.masterHardwareId === masterHardwareId &&
// issue.category === category
// ) {
// issue.assignedTo = {
// name: teamMember.name,
// support_teamMemberId: teamMember.support_teamMemberId,
// phone: teamMember.phone,
// email: teamMember.email,
// startDate: formattedStart, // 👈 use formatted date
// endDate: formattedEnd // 👈 use formatted date
// };
// assignedCount++;
// }
// });
// if (assignedCount === 0) {
// return reply.code(404).send({ message: 'No matching issues found for assignment' });
// }
// await support.save();
// return reply.send({
// message: `Assigned ${assignedCount} categorized issue(s) to ${teamMember.name}`,
// assignedTo: teamMember.support_teamMemberId
// });
// };
// const moment = require('moment'); // Ensure moment is installed
exports.assignCategorizeIssue = async (request, reply) => {
const { supportId } = request.params;
const { support_teamMemberId, startDate, endDate, category, masterHardwareId } = request.body;
@ -5366,15 +5431,16 @@ exports.assignCategorizeIssue = async (request, reply) => {
return reply.code(400).send({ error: `Team member ID ${support_teamMemberId} not found` });
}
const start = new Date(startDate);
const end = new Date(endDate);
if (isNaN(start) || isNaN(end)) {
return reply.code(400).send({ error: 'Invalid startDate or endDate' });
// ✅ Parse using moment with expected format
const start = moment(startDate, "DD-MM-YYYY HH:mm", true);
const end = moment(endDate, "DD-MM-YYYY HH:mm", true);
if (!start.isValid() || !end.isValid()) {
return reply.code(400).send({ error: 'Invalid startDate or endDate format. Use DD-MM-YYYY HH:mm' });
}
// ✅ Format to "DD-MM-YYYY HH:mm:ss"
const formattedStart = moment(start).format("DD-MM-YYYY HH:mm:ss");
const formattedEnd = moment(end).format("DD-MM-YYYY HH:mm:ss");
const formattedStart = start.format("DD-MM-YYYY HH:mm:ss");
const formattedEnd = end.format("DD-MM-YYYY HH:mm:ss");
let assignedCount = 0;
@ -5388,8 +5454,8 @@ exports.assignCategorizeIssue = async (request, reply) => {
support_teamMemberId: teamMember.support_teamMemberId,
phone: teamMember.phone,
email: teamMember.email,
startDate: formattedStart, // 👈 use formatted date
endDate: formattedEnd // 👈 use formatted date
startDate: formattedStart,
endDate: formattedEnd
};
assignedCount++;
}
@ -5410,9 +5476,6 @@ exports.assignCategorizeIssue = async (request, reply) => {
exports.getCategorizedIssue = async (request, reply) => {
try {
const { support_teamMemberId } = request.params;

Loading…
Cancel
Save