Skip to content

Commit

Permalink
moongooseError
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-webdev committed Oct 21, 2023
1 parent 1d14096 commit 6ac6ab7
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 250 deletions.
6 changes: 3 additions & 3 deletions React-V1/server/controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ const insertHouses = async () => {
await houseDetail.upsert({ houseID: 1, houseName: "House2", cost: 700, insurancePrice: 200, taxPrice: 200, energyGain: 40});
await houseDetail.upsert({ houseID: 2, houseName: "House3", cost: 800, insurancePrice: 300, taxPrice: 300, energyGain: 60});
}
insertHouses();
// insertHouses();

const getHouseList = (req, res) => {
houseDetail.find({}, (err, houseList) => {
Expand Down Expand Up @@ -905,7 +905,7 @@ const insertEnergy = async () => {
await energyDetail.upsert({ energyID: 1, cost: 200, energyGain: 40});
await energyDetail.upsert({ energyID: 2, cost: 300, energyGain: 60});
}
insertEnergy();
// insertEnergy();

const getEnergyList = (req, res) => {
energyDetail.find({}, (err, energyList) => {
Expand Down Expand Up @@ -946,7 +946,7 @@ const insertLF = async () => {
await lfDetail.upsert({lfID: 1, cost: 200, loanAgainstLF: 60})
await lfDetail.upsert({lfID: 2, cost: 300, loanAgainstLF: 70})
}
insertLF();
// insertLF();

// To fetch all Life Insurances available.
const getLFList = (req,res) => {
Expand Down
40 changes: 16 additions & 24 deletions React-V1/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ app.use(express.json());
app.use(bodyParser.json());
app.use(express.urlencoded());
app.use(cors());
//Giving access to itch.io

app.use(helmet.frameguard({ action: 'SAMEORIGIN' }));
// app.use(cors({
// origin: ['cryptostein.itch.io/','cryptostein.itch.io/plearn', 'itch.io/'],
// optionsSuccessStatus: 200
// }));
// app.options("*", cors());

var allowedOrigins = ['*', 'https://singular-granita-0e1259.netlify.app'];
app.use(function (req, res, next) {
var origin = req.headers.origin;
Expand All @@ -30,30 +26,26 @@ app.use(function (req, res, next) {
res.header("Access-Control-Allow-Credentials", "true");
next();
});
// const allowedOrigins = ['https://singular-granita-0e1259.netlify.app', '*'];
// app.use(cors({
// origin: function(origin, callback){
// if(!origin) return callback(null, true);
// if(allowedOrigins.indexOf(origin) === -1){
// var msg = 'The CORS policy for this site does not allow access from the specified Origin.';
// return callback(new Error(msg), false);
// }
// return callback(null, true);
// }
// }));

const router = require("./routes/routes");
app.use("/", router);

// Database Connection
mongoose.connect(mongoURI,
{
useNewUrlParser: true, useUnifiedTopology: true
}, () => {
console.log("Your DB is connected.");
}
)
// mongoose.connect(mongoURI,
// {
// // useNewUrlParser: true, useUnifiedTopology: true
// }, () => {
// console.log("Your DB is connected.");
// }
// )

async function connectDB(){
await mongoose.connect(mongoURI).then(
() => {console.log("Your DB is connected")},
err => {console.log(err)}
);
}
connectDB();
app.get('/test', (req,res) => {
res.send("Hello User");
})
Expand Down
4 changes: 2 additions & 2 deletions React-V1/server/model/bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bankLoanSchema = new mongoose.Schema({
});

bankLoanSchema.statics.upsert = async function (record){
await this.findOneAndUpdate({ loanID: record.loanID }, record, {
await this.find({ loanID: record.loanID }, record, {
upsert: true,
new: true,
});
Expand All @@ -24,7 +24,7 @@ const bankDepositSchema = new mongoose.Schema({
});

bankDepositSchema.statics.upsert = async function (record){
await this.findOneAndUpdate({ depositID: record.depositID }, record, {
await this.find({ depositID: record.depositID }, record, {
upsert: true,
new: true,
});
Expand Down
Loading

0 comments on commit 6ac6ab7

Please sign in to comment.