Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Routes/incomeRoute.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import express from "express"
import bodyParser from "body-parser";
import confirmation from "../controllers/confirmation.js";
// import incom

import {readIncome , createIncome} from "../controllers/incomeController.js";
const router = express.Router();
router.use(bodyParser.json());
router.post ("/createincome", createIncome);
router.get ("/get", readIncome);
router.get ("/get",confirmation, readIncome);


export default router;
4 changes: 3 additions & 1 deletion controllers/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import confirmation from "../Models/confirmation.js";

const checkVotes = async (req, res) => {
try {
const users = await confirmation.find().limit(100); // Retrieve the latest 100 users
const users = await confirmation.find().limit(100);

const trueVotes = users.filter(user => user.vote === true);
const falseVotes = users.filter(user => user.vote === false);
Expand All @@ -11,7 +11,9 @@ const checkVotes = async (req, res) => {
message: "Vote check completed",
trueVotes: trueVotes.length,
falseVotes: falseVotes.length,

});

} catch (err) {
console.log("Error caught:", err);
res.status(500).json({
Expand Down
87 changes: 52 additions & 35 deletions controllers/response.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
import confirmation from "../Models/confirmation.js";
import teamsSchema from "../Models/teamsModel.js";

import confirmation from "../Models/confirmation.js"
const vote = async (req, res) => {
try {
const data = req.body;

if (typeof data.vote !== 'boolean') {
return res.status(400).json({ message: "Invalid vote value" });
}

let existingUser = await confirmation.findOne({ email: data.email });
if (existingUser) {
return res.status(409).json({ message: "Email is already voted" });
}

let voteInstance = new confirmation({
email: data.email,
vote: data.vote,
});


let result = await voteInstance.save();

res.status(200).json({
message: "Data saved successfully",
error: null,
data: result,
});
} catch (err) {
console.log("Error caught:", err);
res.status(500).json({
message: "Failed to save the data",
error: "Failed"
try {
const data = req.body;

// Find the team that the user's email belongs to
const team = await teamsSchema.findOne({
"members.email": data.email
});
if (!team) {
return res.status(404).json({
message: "User's email not found in any team"
});
}

// Check if the email has already voted
let existingUser = await confirmation.findOne({
team:data.name,
email: data.email
});
if (existingUser) {
return res.status(409).json({
message: "Email has already voted"
});
}
};

export default vote;


if (typeof data.vote !== 'boolean') {
return res.status(400).json({ message: "Invalid vote value" });
}

let voteInstance = new confirmation({

email: data.email,
vote: data.vote,
});

let result = await voteInstance.save();
const TeamName= team.name
res.status(200).json({
TeamName,
message: "Data saved successfully",

data: result,
});
} catch (err) {
console.log("Error caught:", err);
res.status(500).json({
message: "Failed to save the data",
error: "Failed"
});
}
};

export default vote;
4 changes: 1 addition & 3 deletions controllers/userRegisterController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const secretKey = '@@key'//This is my secret key
const SignUpController=async(req,res)=>{
try{
const data=req.body


if (data.length === 0) {
if (data.length === 0) {
return res.status(400).json({ message: "Empty data" });
}
const salt = await bcrypt.genSalt(8);
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import cors from "cors"
import member from "./Routes/userRegisterRoutes.js"

import teamsRoute from "./Routes/teamsRoute.js"

import response from "./Routes/response.js";

import joinTeam from "./Routes/joinTeamRoute.js"


Expand All @@ -23,8 +26,10 @@ import expenseRoute from "./Routes/expenseRoute.js";
import incomeRoute from "./Routes/incomeRoute.js";
import transferRoute from "./Routes/transferRoute.js"
import addExpense from "./Routes/expenseRoute.js"

import confirmSms from "./Routes/confirmSmsRoute.js"


import savingroute from "./routes/savingroute.js";

import bankroute from "./routes/bankroute.js";
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "babel-node index.js",
"dev": "nodemon index.js",



"start": "node index.js"


"dev": "nodemon index.js"




Expand Down