Add Model for backend
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const cropSchema = new mongoose.Schema(
|
||||
{
|
||||
name: { type: String, required: true },
|
||||
farm: { type: mongoose.Schema.Types.ObjectId, ref: "Farm", required: true },
|
||||
plantedDate: { type: Date, required: true, default: Date.now() },
|
||||
harvestDate: { type: Date },
|
||||
growthStage: {
|
||||
type: String,
|
||||
enum: ["Planted", "Growing", "Ready to Harvest"],
|
||||
default: "Planted",
|
||||
},
|
||||
healthStatus: { type: String, default: "Healthy" },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const Crop = mongoose.model("Crop", cropSchema);
|
||||
|
||||
module.exports = Crop;
|
||||
@@ -0,0 +1,36 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const farmSchema = new mongoose.Schema(
|
||||
{
|
||||
name: { type: String, required: true },
|
||||
location: { type: String, required: true },
|
||||
owner: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
waterContent: { type: String, required: true },
|
||||
soilType: { type: String, required: true },
|
||||
fertilizer: [
|
||||
{
|
||||
name: { type: String },
|
||||
quantity: { type: Number },
|
||||
addedAt: { type: Date, default: Date.now },
|
||||
},
|
||||
],
|
||||
pestisides: [
|
||||
{
|
||||
name: { type: String },
|
||||
quantity: { type: Number },
|
||||
addedAt: { type: Date, default: Date.now },
|
||||
},
|
||||
],
|
||||
crops: [{ type: mongoose.Schema.Types.ObjectId, ref: "Crop" }],
|
||||
finances: { type: mongoose.Schema.Types.ObjectId, ref: "Finance" },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const Farm = mongoose.model("Farm", farmSchema);
|
||||
|
||||
module.exports = Farm;
|
||||
@@ -0,0 +1,21 @@
|
||||
const mongoose = require("mongoose");
|
||||
const financeSchema = new mongoose.Schema(
|
||||
{
|
||||
farm: { type: mongoose.Schema.Types.ObjectId, ref: "Farm", required: true },
|
||||
transactions: [
|
||||
{
|
||||
type: { type: String, enum: ["Expense", "Revenue"], required: true },
|
||||
amount: { type: Number, required: true },
|
||||
description: { type: String },
|
||||
date: { type: Date, default: Date.now },
|
||||
},
|
||||
],
|
||||
totalExpenses: { type: Number, default: 0 },
|
||||
totalRevenue: { type: Number, default: 0 },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const Finance = mongoose.model("Finance", financeSchema);
|
||||
|
||||
module.exports = Finance;
|
||||
@@ -1,51 +0,0 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const meetingSchema = new mongoose.Schema(
|
||||
{
|
||||
meetingDate: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
meetingTime: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
mentorName: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
mentiName: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
mentorId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
mentiId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
default: "Pending",
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
paymentStatus: {
|
||||
type: "Status",
|
||||
default: "Pending",
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
const Meeting = mongoose.model("Meeting", meetingSchema);
|
||||
|
||||
module.exports = Meeting;
|
||||
@@ -0,0 +1,31 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const taskSchema = new mongoose.Schema(
|
||||
{
|
||||
farm: { type: mongoose.Schema.Types.ObjectId, ref: "Farm", required: true },
|
||||
crop: { type: mongoose.Schema.Types.ObjectId, ref: "Crop" },
|
||||
taskType: {
|
||||
type: String,
|
||||
enum: [
|
||||
"Sowing",
|
||||
"Watering",
|
||||
"Fertilization",
|
||||
"Pest Control",
|
||||
"Harvesting",
|
||||
],
|
||||
required: true,
|
||||
},
|
||||
description: { type: String },
|
||||
assignedDate: { type: Date, required: true, default: Date.now },
|
||||
status: {
|
||||
type: String,
|
||||
enum: ["Pending", "Completed"],
|
||||
default: "Pending",
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const Task = mongoose.model("Task", taskSchema);
|
||||
|
||||
module.exports = Task;
|
||||
@@ -11,21 +11,9 @@ const userSchema = new mongoose.Schema(
|
||||
maxLength: [30, "Please Enter the valid name"],
|
||||
minLength: [2, "Name should have more than 5 characters"],
|
||||
},
|
||||
|
||||
skills: [
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
],
|
||||
uniqueRole: {
|
||||
type: String,
|
||||
},
|
||||
country: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -41,23 +29,9 @@ const userSchema = new mongoose.Schema(
|
||||
type: String,
|
||||
default: "/images/profile.jpeg",
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
default: "user",
|
||||
},
|
||||
mainInterest: [
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
],
|
||||
documents: [
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
],
|
||||
meettingFees: {
|
||||
type: Number,
|
||||
},
|
||||
role: { type: String, enum: ["farmer", "admin"], default: "farmer" },
|
||||
farms: [{ type: mongoose.Schema.Types.ObjectId, ref: "Farm" }],
|
||||
|
||||
resetPasswordToken: String,
|
||||
resetPasswordExpiry: Date,
|
||||
},
|
||||
|
||||
+1
-53
@@ -19,16 +19,6 @@ const corsOptions = {
|
||||
credentials: true,
|
||||
};
|
||||
|
||||
const server = createServer(app);
|
||||
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: process.env.FRONTEND_URI,
|
||||
methods: ["GET", "PUT", "POST", "PATCH", "DELETE"],
|
||||
credentials: true,
|
||||
},
|
||||
});
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
app.use(express.json({ limit: "16kb" }));
|
||||
app.use(express.urlencoded({ extended: true, limit: "16kb" }));
|
||||
@@ -41,46 +31,4 @@ app.get("/", (req, res) => {
|
||||
|
||||
app.use("/api/v1", userRoute);
|
||||
|
||||
const emailToSocketIdMap = new Map();
|
||||
const socketidToEmailMap = new Map();
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
// console.log(`Socket Connected`, socket.id);
|
||||
socket.on("room:join", (data) => {
|
||||
const { email, room } = data;
|
||||
emailToSocketIdMap.set(email, socket.id);
|
||||
socketidToEmailMap.set(socket.id, email);
|
||||
io.to(room).emit("user:joined", { email, id: socket.id });
|
||||
socket.join(room);
|
||||
io.to(socket.id).emit("room:join", data);
|
||||
});
|
||||
|
||||
socket.on("message", ({ message, room }) => {
|
||||
// console.log(message);
|
||||
// console.log("Message is : ", message, "Room is : ", room);
|
||||
//for sending the message all the users that are connected < --- > io.emit("receive-message", message);
|
||||
//for sending the message for all the user except us <----> socket.broadcast.emit("receive-message", message);
|
||||
socket.join(room);
|
||||
io.to(room).emit("receive-message", message); // For sending the message for perticular room or user
|
||||
});
|
||||
|
||||
socket.on("user:call", ({ to, offer }) => {
|
||||
io.to(to).emit("incomming:call", { from: socket.id, offer });
|
||||
});
|
||||
|
||||
socket.on("call:accepted", ({ to, ans }) => {
|
||||
io.to(to).emit("call:accepted", { from: socket.id, ans });
|
||||
});
|
||||
|
||||
socket.on("peer:nego:needed", ({ to, offer }) => {
|
||||
//console.log("peer:nego:needed", offer);
|
||||
io.to(to).emit("peer:nego:needed", { from: socket.id, offer });
|
||||
});
|
||||
|
||||
socket.on("peer:nego:done", ({ to, ans }) => {
|
||||
// console.log("peer:nego:done", ans);
|
||||
io.to(to).emit("peer:nego:final", { from: socket.id, ans });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = server;
|
||||
module.exports = app;
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ const server = require("./app.js");
|
||||
const dotenv = require("dotenv");
|
||||
const cloudinary = require("cloudinary").v2;
|
||||
const DB_connect = require("./Database/DB_connect.js");
|
||||
const app = require("./app.js");
|
||||
|
||||
// dotenv Configuration
|
||||
dotenv.config({
|
||||
@@ -17,7 +18,7 @@ cloudinary.config({
|
||||
DB_connect();
|
||||
|
||||
// Listening the port
|
||||
server.listen(process.env.PORT, () => {
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log("Server is Running on ", process.env.PORT);
|
||||
console.log("Frontend URI : ", process.env.FRONTEND_URI);
|
||||
});
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "index.js",
|
||||
"use": "@vercel/node"
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"src": "/api/v1/(.*)",
|
||||
"dest": "index.js"
|
||||
},
|
||||
{
|
||||
"src": "/(.*)",
|
||||
"dest": "index.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user