From fa6fb7ed2ffc4da48d18b0c08c2f711b7bdf5d6a Mon Sep 17 00:00:00 2001 From: mouryasujit Date: Fri, 14 Apr 2023 00:35:43 +0530 Subject: [PATCH 1/3] adding the std bank schema and updating the syntax of the files todo:jwt for authentication --- models/std_bank.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 models/std_bank.js diff --git a/models/std_bank.js b/models/std_bank.js new file mode 100644 index 0000000..41db132 --- /dev/null +++ b/models/std_bank.js @@ -0,0 +1,94 @@ +const { connector } = require("./databaseUtil"); + +const BankSchema = { + userId: { + type: String, + required: true, + unique: true, + }, + bank_name: { + type: String, + required: true, + minLength: 7, + }, + bank_acc: { + type: String, + required: true, + unique: true, + }, + bank_branch: { + type: String, + required: true, + }, + bank_ifsc: { + type: String, + required: true, + maxLength: 11, + minLength: 11, + }, + bank_micr: { + type: String, + required: true, + maxLength: 9, + minLength: 9, + }, +}; + +const Bank = new connector.model("Bank", BankSchema); + +export const AddBankdetails = async (req, res) => { + const id = req.body.userId; + const newBank = new Bank({ + userId: id, //we will get it after by jwt + ...req.body, + }); + try { + const existing = await Bank.findOne({ userId: id }); + if (existing) return res.status(400).send("Bank details already exists"); + await newBank.save(); + res.status(201).json("Bank account details added"); + } catch (error) { + console.log(error); + } +}; +export const GetBankdetails = async (req, res) => { + const id = req.params.id; //get it by jwt as user loggs in we will have it; + try { + const data = await Bank.findOne({ userId: id }); + if (!data) return res.status(404).send("No data found for this id"); + + res.status(200).json(data); + } catch (error) { + console.log(error); + } +}; +export const updateBankdetails = async (req, res) => { + const id = req.params.id; + try { + const data = await Bank.findOne({ _id: id }); + if (!data) return res.status(404).send("bank account details not found"); + + // if(data.userId !==req.userId ) thsi statement will help us know that if the user is the specific user trying to update + const datas = await Bank.findByIdAndUpdate( + req.params.id, + { $set: req.body }, + { new: true } + ); + res.status(200).json(datas); + } catch (error) { + console.log(error); + } +}; +export const deleteBankdetails = async (req, res) => { + const id = req.params.id; + try { + const data = await Bank.findOne({ _id: id }); + if (!data) return res.status(404).send("bank account details not found"); + // if(data.userId !==req.userId ) this statement will help us know that if the user is the specific user trying to delete + + await Bank.findByIdAndDelete(req.params.id); + res.status(200).send("Bank account deleted"); + } catch (error) { + console.log(error); + } +}; From 691e9f500bb5ff20755f72596127dd5d89f6b2b6 Mon Sep 17 00:00:00 2001 From: mouryasujit Date: Fri, 14 Apr 2023 00:48:59 +0530 Subject: [PATCH 2/3] Adding the crud operation and adding schema for student college updateding the syntax as requested --- models/std_bank.js | 94 -------------------------------- models/std_college.js | 123 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 94 deletions(-) delete mode 100644 models/std_bank.js create mode 100644 models/std_college.js diff --git a/models/std_bank.js b/models/std_bank.js deleted file mode 100644 index 41db132..0000000 --- a/models/std_bank.js +++ /dev/null @@ -1,94 +0,0 @@ -const { connector } = require("./databaseUtil"); - -const BankSchema = { - userId: { - type: String, - required: true, - unique: true, - }, - bank_name: { - type: String, - required: true, - minLength: 7, - }, - bank_acc: { - type: String, - required: true, - unique: true, - }, - bank_branch: { - type: String, - required: true, - }, - bank_ifsc: { - type: String, - required: true, - maxLength: 11, - minLength: 11, - }, - bank_micr: { - type: String, - required: true, - maxLength: 9, - minLength: 9, - }, -}; - -const Bank = new connector.model("Bank", BankSchema); - -export const AddBankdetails = async (req, res) => { - const id = req.body.userId; - const newBank = new Bank({ - userId: id, //we will get it after by jwt - ...req.body, - }); - try { - const existing = await Bank.findOne({ userId: id }); - if (existing) return res.status(400).send("Bank details already exists"); - await newBank.save(); - res.status(201).json("Bank account details added"); - } catch (error) { - console.log(error); - } -}; -export const GetBankdetails = async (req, res) => { - const id = req.params.id; //get it by jwt as user loggs in we will have it; - try { - const data = await Bank.findOne({ userId: id }); - if (!data) return res.status(404).send("No data found for this id"); - - res.status(200).json(data); - } catch (error) { - console.log(error); - } -}; -export const updateBankdetails = async (req, res) => { - const id = req.params.id; - try { - const data = await Bank.findOne({ _id: id }); - if (!data) return res.status(404).send("bank account details not found"); - - // if(data.userId !==req.userId ) thsi statement will help us know that if the user is the specific user trying to update - const datas = await Bank.findByIdAndUpdate( - req.params.id, - { $set: req.body }, - { new: true } - ); - res.status(200).json(datas); - } catch (error) { - console.log(error); - } -}; -export const deleteBankdetails = async (req, res) => { - const id = req.params.id; - try { - const data = await Bank.findOne({ _id: id }); - if (!data) return res.status(404).send("bank account details not found"); - // if(data.userId !==req.userId ) this statement will help us know that if the user is the specific user trying to delete - - await Bank.findByIdAndDelete(req.params.id); - res.status(200).send("Bank account deleted"); - } catch (error) { - console.log(error); - } -}; diff --git a/models/std_college.js b/models/std_college.js new file mode 100644 index 0000000..f7870d4 --- /dev/null +++ b/models/std_college.js @@ -0,0 +1,123 @@ +const { connector } = require("./databaseUtil"); + +const CollegeSchema = { + userId: { + type: String, + required: true, + unique: true, + }, + AdmissionYear: { + type: String, + required: true, + }, + StudentCode: { + type: String, + }, + Rollno: { + type: String, + }, + AdmissionStatus: { + type: String, + required: true, + }, + AdmissionPattern: { + type: String, + }, + Admissioncategory: { + type: String, + required: true, + }, + SeatDesc: { + type: String, + }, + QuotaType: { + type: String, + required: true, + }, + QuotaType: { + type: String, + required: true, + }, + Boarder: { + type: Boolean, + }, + Seattype: { + type: String, + required: true, + }, + Seatsubtype: { + type: String, + required: true, + }, + EligibilityNo: { + type: String, + required: true, + }, + EnrollmentNo: { + type: String, + required: true, + unique: true, + }, +}; + +const College = new connector.model("College", CollegeSchema); + +export const AddCollegeDetails = async (req, res) => { + const id = req.body.id; + const newCollegeDetails = new College({ + userId: id, + ...req.body, + }); + try { + const data = await College.findById(id); + if (data) + return res.status(400).send("One user can have only one college details"); + + await newCollegeDetails.save(); + res.status(201).send("user has been created"); + } catch (error) { + console.log(error); + } +}; +export const GetCollegeDetails = async (req, res) => { + const id = req.params.id; + try { + const data = await College.findById(id); + if (!data) + return res + .status(400) + .send("No data found for this id please add your data"); + + res.status(200).json(data); + } catch (error) { + console.log(error); + } +}; + +export const updateCollegeDetails = async (req, res) => { + const id = req.body.id; + try { + const finddata = await College.findById(id); + if (!finddata) res.status(404).send("No data found for this user"); + + const data = await College.findByIdAndUpdate( + req.params.id, + { $set: req.body }, + { new: true } + ); + console.log(data); + } catch (error) { + console.log(error); + } +}; +export const deleteCollegeDetails = async (req, res) => { + const id = req.body.id; + try { + const finddata = await College.findById(id); + if (!finddata) res.status(404).send("No data found for this user"); + await College.findByIdAndDelete(req.params.id); + res.status(200).send("details deleted successfully"); + } catch (error) { + console.log(error); + } +}; From 2ac820c0a38e1d8028acd70257d7d9dda698d2a8 Mon Sep 17 00:00:00 2001 From: mouryasujit Date: Mon, 17 Apr 2023 16:16:40 +0530 Subject: [PATCH 3/3] adding the std bank schema and updating the syntax of the files --- models/std_college.js | 67 ++++--------------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) diff --git a/models/std_college.js b/models/std_college.js index f7870d4..ba9283d 100644 --- a/models/std_college.js +++ b/models/std_college.js @@ -1,6 +1,6 @@ const { connector } = require("./databaseUtil"); -const CollegeSchema = { +const StudentCollegeSchema = { userId: { type: String, required: true, @@ -60,64 +60,9 @@ const CollegeSchema = { }, }; -const College = new connector.model("College", CollegeSchema); +const studentcollegeCollege = new connector.model( + "StudentCollegeSchema", + StudentCollegeSchema +); -export const AddCollegeDetails = async (req, res) => { - const id = req.body.id; - const newCollegeDetails = new College({ - userId: id, - ...req.body, - }); - try { - const data = await College.findById(id); - if (data) - return res.status(400).send("One user can have only one college details"); - - await newCollegeDetails.save(); - res.status(201).send("user has been created"); - } catch (error) { - console.log(error); - } -}; -export const GetCollegeDetails = async (req, res) => { - const id = req.params.id; - try { - const data = await College.findById(id); - if (!data) - return res - .status(400) - .send("No data found for this id please add your data"); - - res.status(200).json(data); - } catch (error) { - console.log(error); - } -}; - -export const updateCollegeDetails = async (req, res) => { - const id = req.body.id; - try { - const finddata = await College.findById(id); - if (!finddata) res.status(404).send("No data found for this user"); - - const data = await College.findByIdAndUpdate( - req.params.id, - { $set: req.body }, - { new: true } - ); - console.log(data); - } catch (error) { - console.log(error); - } -}; -export const deleteCollegeDetails = async (req, res) => { - const id = req.body.id; - try { - const finddata = await College.findById(id); - if (!finddata) res.status(404).send("No data found for this user"); - await College.findByIdAndDelete(req.params.id); - res.status(200).send("details deleted successfully"); - } catch (error) { - console.log(error); - } -}; +module.exports = {};