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
2 changes: 2 additions & 0 deletions week-1/offline-class-1/level-1/02-Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ explainParseInt("42");
explainParseInt("42px");
explainParseInt("3.14");

console.log("The first thing is done")

function explainParseFloat(value) {
console.log("Original Value:", value);
let result = parseFloat(value);
Expand Down
6 changes: 4 additions & 2 deletions week-1/offline-class-1/level-2/01-Class.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class Animal {
this.legCount = legCount
}
describe() {
return `${this.name} has ${this.legCount} legs`
console.log(`${this.name} has ${this.legCount} legs`)
return 0;
}
}


let animal = new Animal("dog",4);
animal.describe();
2 changes: 1 addition & 1 deletion week-1/offline-class-1/level-2/02-Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function dateMethods() {
// Setting components of the date
currentDate.setFullYear(2022);
console.log("After setFullYear:", currentDate);

currentDate.setMonth(5); // Setting month to June (zero-indexed)
console.log("After setMonth:", currentDate);

Expand Down
16 changes: 15 additions & 1 deletion week-3/03-mongo/db/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
const mongoose = require('mongoose');

// Connect to MongoDB
mongoose.connect('your-mongodb-url');
mongoose.connect('mongodb+srv://harshkumargupta630:[email protected]/');

// Define schemas
const AdminSchema = new mongoose.Schema({
// Schema definition here
username: String,
password: String
});

const UserSchema = new mongoose.Schema({
// Schema definition here

username:String,
password:String,
purchasedCourses:[{
type:mongoose.Schema.Types.ObjectId,
ref:'Course'

}]
});

const CourseSchema = new mongoose.Schema({
// Schema definition here
title:String,
description:String,
imageLink:String,
price:Number
});

const Admin = mongoose.model('Admin', AdminSchema);
Expand Down
16 changes: 16 additions & 0 deletions week-3/03-mongo/middleware/admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
// Middleware for handling auth
const {Admin} = require("../db");
function adminMiddleware(req, res, next) {
// Implement admin auth logic
// You need to check the headers and validate the admin from the admin DB. Check readme for the exact headers to be expected
const username=req.headers.username;
const password = req.headers.password;
Admin.findOne({
username,
password
})
.then(function(value){
if(value){
next();
} else{
res.status(403).json({
msg: "Admin doesnot exist"
})
}
})
}

module.exports = adminMiddleware;
19 changes: 19 additions & 0 deletions week-3/03-mongo/middleware/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
const { User } = require("../db")
function userMiddleware(req, res, next) {
// Implement user auth logic
// You need to check the headers and validate the user from the user DB. Check readme for the exact headers to be expected
const username = req.headers.username;
const password = req.headers.password;
User.findOne({
username,
password
})
.then(function(value){
if(value){
next();
} else{
res.status(403).json({
msg:"User doesnot exists"
})
}
})



}

module.exports = userMiddleware;