Deleted useless folders such as backend, node_modules, files such as package-lock. Also, modified readme.

This commit is contained in:
K
2025-02-23 09:02:28 +05:30
parent 54c7dbc940
commit 7dd344f722
406 changed files with 1 additions and 119215 deletions
-22
View File
@@ -1,22 +0,0 @@
const mongoose = require("mongoose");
const cropSchema = new mongoose.Schema(
{
name: { type: String, required: true },
farm: { type: mongoose.Schema.Types.ObjectId, ref: "Farm", required: true },
image: { type: String },
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;
-37
View File
@@ -1,37 +0,0 @@
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,
},
size: { type: String },
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;
-21
View File
@@ -1,21 +0,0 @@
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;
-31
View File
@@ -1,31 +0,0 @@
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;
-85
View File
@@ -1,85 +0,0 @@
const mongoose = require("mongoose");
const bcrypt = require("bcrypt");
const jwt = require("jsonwebtoken");
const crypto = require("crypto");
const userSchema = new mongoose.Schema(
{
name: {
type: String,
required: [true, "Please Enter your name"],
maxLength: [30, "Please Enter the valid name"],
minLength: [2, "Name should have more than 5 characters"],
},
country: {
type: String,
},
email: {
type: String,
required: true,
unique: true,
lowerCase: true,
},
password: {
type: String,
required: true,
minLength: [6, "Password should have more than 6 characters"],
},
avatar: {
type: String,
default: "/images/profile.jpeg",
},
role: { type: String, enum: ["farmer", "admin"], default: "farmer" },
farms: [{ type: mongoose.Schema.Types.ObjectId, ref: "Farm" }],
resetPasswordToken: String,
resetPasswordExpiry: Date,
},
{
timestamps: true,
}
);
userSchema.pre("save", async function (next) {
if (!this.isModified("password")) return next();
this.password = await bcrypt.hash(this.password, 10);
return next();
});
userSchema.methods.isPasswordCorrect = async function (password) {
return await bcrypt.compare(password, this.password);
};
userSchema.methods.generateRefreshToken = async function () {
return await jwt.sign(
{
_id: this._id,
email: this.email,
},
process.env.REFRESH_TOKEN_SECRET
// {
// expiresIn: process.env.REFRESH_TOKEN_EXPIRY,
// }
);
};
userSchema.methods.getResetPassword = async function () {
// Generating token
const resetToken = await crypto.randomBytes(20).toString("hex");
// Hashing and adding reset password token to userschema
this.resetPasswordToken = crypto
.createHash("sha256")
.update(resetToken)
.digest("hex");
this.resetPasswordExpiry = Date.now() + 15 * 60 * 1000;
return resetToken;
};
const User = mongoose.model("User", userSchema);
module.exports = User;