Skip to content
Open

haha #19

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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# MessApp
gaand mari hui h

72 changes: 0 additions & 72 deletions backend/controllers/Customer.controller.js

This file was deleted.

133 changes: 133 additions & 0 deletions backend/controllers/Customer_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import client from "../db";

export const View_mess = async (req, res) => {

let exists;
try {
exists = await client.query("select * from Mess ");
} catch (err) {
console.log(err);
}
console.log(exists.rows);
res.status(200).send(exists.rows);
};


export const Subscribe_mess = async (req, res) => {
const { User_id, Mess_id, tokens } = req.body;
// INSERT INTO TableName (DateColumn) VALUES (CURRENT_DATE);
let exists;
try {
exists = await client.query("INSERT INTO Subscription(User_id,Mess_id,tokens,Daily_tokens,Subscription_date) VALUES($1,$2,$3,1,CURRENT_DATE);", [
User_id, Mess_id, tokens
]);
} catch (err) {
console.log(err);
}
// console.log(exists.rows);
res.status(200).send("Successfully Subscribed!");
};

// use to alert user that subscription is about to end
export const Remaining_Daily_tokens = async (req,res) => {
const {User_id,Mess_id} = req.body;

let exists;

try {
exists = await client.query("Select Daily_tokens from Subscriptions where Mess_id=$1 and User_id = $2",
[
Mess_id,User_id
])
}catch(err) {
console.log(err);
}

res.status(200).send(exists.rowCount);
}

// when user changes number of tiffins per day
export const Change_daily_tokens = async (req, res) => {
const { User_id,Mess_id,Daily_tokens} = req.body;
let exists;
try {
exists = await client.query("UPDATE Subscription SET Daily_tokens=$3 where User_id=$1 and Mess_id=$2",
[
User_id,Mess_id,Daily_tokens
]);
} catch (err) {
console.log(err);
}
// console.log(exists.rows);
res.status(200).send("Successfully Updated Daily Tokens!");
};

export const Rate_Mess = async(req,res) => {

const {User_id,Mess_id,Rating} = req.body;

let exists;
try {
exists = await client.query("Select * from Ratings where User_id = $1 and Mess_id = $2",
[
User_id,Mess_id
]);
} catch (err) {
console.log(err);
}

if(exists.rowCount!=0)
{
res.status(500).send("Cannot Rate the same Mess multiple times");
}else
{
try {
exists = await client.query("Insert into Ratings(User_id,Mess_id,Rating) Values($1,$2,$3)",
[
User_id,Mess_id,Rating
]);
} catch (err) {
console.log(err);
}
}
res.status(200).send("Successfully Rated");
}

export const Update_profile = async (req, res) => {

const {User_id,Fname, Lname, Phone_num, Password, User_address} = req.body;

let exists;
try {
exists = await client.query("UPDATE Users SET Fname=$1, Lname=$2, Phone_num=$3, Password=$4, User_address=$5 where User_id=$6",
[
Fname, Lname, Phone_num, Password, User_address,User_id
]);
} catch (err) {
console.log(err);
}
// console.log(exists.rows);
res.status(200).send("Successfully Updated Profile!");
};

export const filter_mess = async(req,res) => {

const {Filter_rating} = req.body;
let exists;

try{
exists = await client.query("select * from Mess where Mess_id in (Select Mess_id from Ratings group by Mess_id having avg(Rating)>$1)",[Filter_rating]);
}catch(err){

console.log(err);
}
res.status(200).send(exists.body);
}

export const Make_payment = async(req,res) => {

}

// daily tokens in subscription
// seperate rating table user id mess id rating

110 changes: 0 additions & 110 deletions backend/controllers/Delivery_boy.controller.js

This file was deleted.

48 changes: 48 additions & 0 deletions backend/controllers/Sign_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import client from "../db.js";
export const createUser = async (req, res) => {
const { Fname, Lname, Phone_num, Email, Password, User_address, User_type} = req.body;
let exists;
try {
exists = await client.query(
"Select * from Users where Users.email=$1 and Users.type=$2;",
[Email,User_type]
);
} catch (err) {
console.log(err);
}

if (exists.rowCount != 0) {
res.status(500).send("User already Existed. Try Sign in instead ");
} else {
let newUser;
try {
newUser = await client.query(
"INSERT INTO Users(Fname, Lname, Phone_num, Email, Password, User_address, User_type) VALUES ($1,$2,$3,$4,$5,$6,$7);",
[Fname, Lname, Phone_num, Email, Password, User_address, User_type]
);
res.status(200).send("User has been created");
} catch (err) {
console.log(err);
}
}
};

export const logInUser = async (req, res) => {
console.log("Email");
const { Email, Password, User_type} = req.body;

let userExists;
try {
userExists = await client.query(
"select User_id from Users WHERE Email=$1 and Password=$2 and User_type=$3;",
[Email, Password, User_type]
);
} catch (err) {
console.log(err);
}
if (userExists.rowCount == 1) {
res.status(200).send(userExists.rows[0]);
} else {
res.status(500).send("User does not Exists");
}
};
Loading