Merge branch 'master' of http://128.199.30.231/possibillion/cheminova-api
This commit is contained in:
commit
c8ef641661
BIN
public/temp/tmp-1-1725006243826
Normal file
BIN
public/temp/tmp-1-1725006243826
Normal file
Binary file not shown.
BIN
public/temp/tmp-2-1725006297945
Normal file
BIN
public/temp/tmp-2-1725006297945
Normal file
Binary file not shown.
BIN
public/temp/tmp-3-1725006333870
Normal file
BIN
public/temp/tmp-3-1725006333870
Normal file
Binary file not shown.
BIN
public/temp/tmp-4-1725006454741
Normal file
BIN
public/temp/tmp-4-1725006454741
Normal file
Binary file not shown.
BIN
public/temp/tmp-5-1725006486479
Normal file
BIN
public/temp/tmp-5-1725006486479
Normal file
Binary file not shown.
BIN
public/temp/tmp-6-1725006529054
Normal file
BIN
public/temp/tmp-6-1725006529054
Normal file
Binary file not shown.
@ -11,7 +11,7 @@ export const addInventory = async (req, res) => {
|
||||
const { products, addedFor, addedForId } = req.body;
|
||||
const userId = req.user._id;
|
||||
const userType = req.userType;
|
||||
console.log("req.user", req.user);
|
||||
// console.log("req.user", req.user);
|
||||
const currentYear = new Date().getFullYear().toString().slice(-2);
|
||||
const randomChars = crypto.randomBytes(4).toString("hex").toUpperCase();
|
||||
const uniqueId = `${currentYear}-${randomChars}`;
|
||||
|
@ -165,6 +165,40 @@ export const getAllKycApproved = async (req, res) => {
|
||||
res.status(500).json({ message: "Server Error", error });
|
||||
}
|
||||
};
|
||||
export const getAllKycApprovedbytmid = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params; // Extracting `addedBy` ID from req.params
|
||||
const { tradename, page = 1, show = 10 } = req.query; // Extracting filters and pagination from req.query
|
||||
|
||||
const query = { status: "approved", addedBy: id }; // Base query with status and addedBy
|
||||
|
||||
if (tradename) {
|
||||
query.trade_name = new RegExp(tradename, "i"); // Adding trade_name filter with case-insensitive regex
|
||||
}
|
||||
|
||||
const skip = (page - 1) * show; // Calculating the number of documents to skip
|
||||
|
||||
// Fetch KYC documents from the database based on query, sorted by creation date, with pagination
|
||||
const retaildistributor = await KYC.find(query)
|
||||
.sort({ createdAt: -1 })
|
||||
.populate("principal_distributer", "name")
|
||||
.populate("addedBy")
|
||||
.skip(skip)
|
||||
.limit(parseInt(show));
|
||||
const total_data = await KYC.countDocuments(query);
|
||||
// Send the fetched data as a response
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
total_data: total_data,
|
||||
total_pages: Math.ceil(total_data / page),
|
||||
retaildistributor
|
||||
});
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the fetch operation
|
||||
console.error(error);
|
||||
res.status(500).json({ message: "Server Error", error });
|
||||
}
|
||||
};
|
||||
// Get Single KYC
|
||||
export const getKycById = async (req, res) => {
|
||||
try {
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
createKyc,
|
||||
getAllKyc,
|
||||
getAllKycApproved,
|
||||
getAllKycApprovedbytmid,
|
||||
getAllKycRejected,
|
||||
getAllPrincipalDistributers,
|
||||
getKycById,
|
||||
@ -30,6 +31,9 @@ router
|
||||
router
|
||||
.route("/kyc/getAllapproved/")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllKycApproved);
|
||||
router
|
||||
.route("/kyc/getAllapprovedbytmid/:id")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllKycApprovedbytmid);
|
||||
router
|
||||
.route("/kyc/get-single-kyc/:id")
|
||||
.get(
|
||||
|
@ -1,6 +1,9 @@
|
||||
import Task from "./TaskModel.js";
|
||||
import crypto from "crypto";
|
||||
import cron from "node-cron";
|
||||
import { sendPushNotification } from "../../Utils/sendPushNotification.js";
|
||||
import SalesCoOrdinator from "../SalesCoOrdinators/SalesCoOrdinatorModel.js";
|
||||
import TerritoryManager from "../TerritoryManagers/TerritoryManagerModel.js";
|
||||
// Function to update task statuses
|
||||
const updateOverdueTasks = async () => {
|
||||
try {
|
||||
@ -17,6 +20,17 @@ const updateOverdueTasks = async () => {
|
||||
for (const task of overdueTasks) {
|
||||
task.taskStatus = "Pending";
|
||||
await task.save();
|
||||
// Fetch the Sales Coordinator who is assigned the task
|
||||
const salesCoordinator = await SalesCoOrdinator.findById(task.taskAssignedTo);
|
||||
|
||||
if (salesCoordinator) {
|
||||
const fcmToken = salesCoordinator.fcm_token;
|
||||
if (fcmToken) {
|
||||
// Send push notification
|
||||
const message = `Your task "${task.task}" is Pending.`;
|
||||
await sendPushNotification(fcmToken, "Task Status Updated", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Overdue tasks updated to "Pending".');
|
||||
@ -26,7 +40,7 @@ const updateOverdueTasks = async () => {
|
||||
};
|
||||
|
||||
// Schedule the cron job to run daily at midnight
|
||||
cron.schedule("10 0 * * *", updateOverdueTasks, {
|
||||
cron.schedule("10 1 * * *", updateOverdueTasks, {
|
||||
timezone: "Asia/Kolkata",
|
||||
});
|
||||
|
||||
@ -92,7 +106,23 @@ export const assignTask = async (req, res) => {
|
||||
addedForId,
|
||||
tradename,
|
||||
});
|
||||
// Fetch the FCM token of the assigned sales coordinator
|
||||
const salesCoordinator = await SalesCoOrdinator.findById(taskAssignedTo);
|
||||
|
||||
if (!salesCoordinator) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Sales Coordinator not found.",
|
||||
});
|
||||
}
|
||||
|
||||
const fcmToken = salesCoordinator.fcm_token;
|
||||
|
||||
if (fcmToken) {
|
||||
// Send push notification
|
||||
const message = `You have been assigned a new task: ${task}`;
|
||||
await sendPushNotification(fcmToken, "New Task Assigned", message);
|
||||
}
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: "Task assigned successfully",
|
||||
@ -222,7 +252,33 @@ export const updateTaskStatus = async (req, res) => {
|
||||
// Update the task status to "Completed"
|
||||
task.taskStatus = "Completed";
|
||||
await task.save();
|
||||
// Fetch the Sales Coordinator who completed the task
|
||||
const salesCoordinator = await SalesCoOrdinator.findById(req.user._id);
|
||||
|
||||
if (!salesCoordinator) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Sales Coordinator not found.",
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch the FCM token of the Territory Manager
|
||||
const territoryManager = await TerritoryManager.findById(task.taskAssignedBy);
|
||||
|
||||
if (!territoryManager) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Territory Manager not found.",
|
||||
});
|
||||
}
|
||||
|
||||
const fcmToken = territoryManager.fcm_token;
|
||||
|
||||
if (fcmToken) {
|
||||
// Send push notification
|
||||
const message = `Task "${task.task}" has been completed by ${salesCoordinator.name}.`;
|
||||
await sendPushNotification(fcmToken, "Task Completed", message);
|
||||
}
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Task status updated to Completed.",
|
||||
|
Loading…
Reference in New Issue
Block a user