From bfbaaa9908fd281b2b41ba4ebf6b02a6df76e3ad Mon Sep 17 00:00:00 2001 From: mouryasujit Date: Fri, 14 Apr 2023 00:14:45 +0530 Subject: [PATCH 1/3] Adding the files for employee schema As requested i had updated the syntax and only changed 1 file use the syntax used by ecveryone todo: get jwt token to verify users --- models/emp_bank.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 models/emp_bank.js diff --git a/models/emp_bank.js b/models/emp_bank.js new file mode 100644 index 0000000..41db132 --- /dev/null +++ b/models/emp_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 ea67eff93f4b921a53d61b72c497eb84fd6e56f2 Mon Sep 17 00:00:00 2001 From: mouryasujit Date: Mon, 17 Apr 2023 20:41:33 +0530 Subject: [PATCH 2/3] Adding the files for emp schema --- models/emp_bankSchema.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 models/emp_bankSchema.js diff --git a/models/emp_bankSchema.js b/models/emp_bankSchema.js new file mode 100644 index 0000000..b0edfcb --- /dev/null +++ b/models/emp_bankSchema.js @@ -0,0 +1,41 @@ +const { connector } = require("./databaseUtil"); + +const EmpBankSchema = { + 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, + }, + appointment_approve_sg_dte: { + type: String, + }, +}; + +const Bank = new connector.model("EmpBank", EmpBankSchema); +module.exports = {}; From a144f1f69103fb0a609a44c0fe64ffdbfd0872b7 Mon Sep 17 00:00:00 2001 From: Sujitkumar Mourya <103282356+mouryasujit@users.noreply.github.com> Date: Mon, 17 Apr 2023 20:47:24 +0530 Subject: [PATCH 3/3] Delete emp_bank.js --- models/emp_bank.js | 94 ---------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 models/emp_bank.js diff --git a/models/emp_bank.js b/models/emp_bank.js deleted file mode 100644 index 41db132..0000000 --- a/models/emp_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); - } -};