69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
import mongoose from "mongoose";
|
|
|
|
const TaskSchema = new mongoose.Schema(
|
|
{
|
|
taskId: {
|
|
type: String,
|
|
unique: true,
|
|
required: true,
|
|
},
|
|
task: {
|
|
type: String,
|
|
required: true,
|
|
enum: ["Visit Retailers", "Update Sales Data", "Update Inventory Data", "Collect KYC"], // Restrict to specific tasks
|
|
},
|
|
note: {
|
|
type: String,
|
|
required: function () {
|
|
return this.task === "Collect KYC";
|
|
},
|
|
},
|
|
taskStatus: {
|
|
type: String,
|
|
required: true,
|
|
enum: ["Pending", "In Progress", "Completed"],
|
|
},
|
|
taskPriority: {
|
|
type: String,
|
|
required: true,
|
|
enum: ["Low", "Medium", "High"],
|
|
},
|
|
taskDueDate: {
|
|
type: String,
|
|
required: true,
|
|
match: /^\d{2}\/\d{2}\/\d{4}$/,
|
|
},
|
|
taskAssignedTo: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "SalesCoOrdinator",
|
|
required: true,
|
|
},
|
|
taskAssignedBy: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: "TerritoryManager",
|
|
required: true,
|
|
},
|
|
addedFor: {
|
|
type: String,
|
|
enum: ['PrincipalDistributor', 'RetailDistributor'],
|
|
required: function () {
|
|
return this.task === "Update Inventory Data";
|
|
},
|
|
},
|
|
addedForId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
refPath: 'addedFor',
|
|
required: function () {
|
|
return this.task === "Update Inventory Data";
|
|
},
|
|
},
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
const Task = mongoose.model("Task", TaskSchema);
|
|
|
|
export default Task;
|