Skip to content

Commit b965bc7

Browse files
committed
Integration with frontend
1 parent 492a22f commit b965bc7

32 files changed

+1262
-33
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/check_db.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import mongoose from 'mongoose';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
async function check() {
7+
await mongoose.connect(process.env.MONGO_URI);
8+
console.log('Connected to:', mongoose.connection.host);
9+
console.log('Database Name:', mongoose.connection.name);
10+
11+
const admin = mongoose.connection.useDb('admin').db.admin();
12+
const dbs = await admin.listDatabases();
13+
14+
for (const dbInfo of dbs.databases) {
15+
const db = mongoose.connection.useDb(dbInfo.name);
16+
const collections = await db.db.listCollections().toArray();
17+
if (collections.some(c => c.name === 'users')) {
18+
const user = await db.db.collection('users').findOne({ email: /r@gmail.com/i });
19+
if (user) {
20+
console.log(`FOUND USER IN DB "${dbInfo.name}":`, user.email);
21+
console.log('User Role:', user.role);
22+
return;
23+
}
24+
}
25+
}
26+
console.log('USER r@gmail.com NOT FOUND IN ANY DATABASE');
27+
await mongoose.disconnect();
28+
}
29+
30+
check().catch(console.error);

scripts/create_receptionist.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import mongoose from 'mongoose';
2+
import bcrypt from 'bcrypt';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
const userSchema = new mongoose.Schema({
8+
name: String,
9+
email: { type: String, unique: true },
10+
password: { type: String },
11+
role: { type: String },
12+
status: { type: String, default: 'Active' },
13+
phno: String
14+
});
15+
16+
const User = mongoose.model('User', userSchema);
17+
18+
async function create() {
19+
await mongoose.connect(process.env.MONGO_URI);
20+
console.log('Connected to Atlas');
21+
22+
const email = 'r@gmail.com';
23+
const plainPassword = 'reception@123';
24+
const hashedPassword = await bcrypt.hash(plainPassword, 10);
25+
26+
// Check if exists
27+
const existing = await User.findOne({ email: /r@gmail.com/i });
28+
if (existing) {
29+
console.log('User already exists, updating password and role...');
30+
existing.password = hashedPassword;
31+
existing.role = 'receptionist';
32+
existing.status = 'Active';
33+
await existing.save();
34+
} else {
35+
console.log('Creating new receptionist user...');
36+
const user = new User({
37+
name: 'Default Receptionist',
38+
email: email,
39+
password: hashedPassword,
40+
role: 'receptionist',
41+
status: 'Active',
42+
phno: '1234567890'
43+
});
44+
await user.save();
45+
}
46+
47+
console.log('Verification:');
48+
const check = await User.findOne({ email: /r@gmail.com/i });
49+
console.log('Final User in DB:', JSON.stringify({ email: check.email, role: check.role, status: check.status }, null, 2));
50+
51+
await mongoose.disconnect();
52+
}
53+
54+
create().catch(console.error);

scripts/debug_auth.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import mongoose from 'mongoose';
2+
import bcrypt from 'bcrypt';
3+
import dotenv from 'dotenv';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
dotenv.config({ path: path.join(__dirname, '../.env') });
11+
12+
const userSchema = new mongoose.Schema({
13+
email: String,
14+
password: { type: String, select: true },
15+
role: String,
16+
status: String,
17+
});
18+
19+
const User = mongoose.model('User', userSchema);
20+
21+
async function debug() {
22+
const uris = [
23+
'mongodb://mongo:27017/hospital_backend',
24+
'mongodb://localhost:27018/hospital_backend',
25+
process.env.MONGO_URI
26+
];
27+
28+
let connected = false;
29+
for (const uri of uris) {
30+
try {
31+
if (!uri) continue;
32+
console.log(`Trying to connect to: ${uri}`);
33+
await mongoose.connect(uri, { serverSelectionTimeoutMS: 2000 });
34+
connected = true;
35+
console.log('Connected Successfully');
36+
break;
37+
} catch (err) {
38+
console.warn(`Connection to ${uri} failed: ${err.message}`);
39+
}
40+
}
41+
42+
if (!connected) {
43+
console.error('COULD NOT CONNECT TO ANY DATABASE');
44+
process.exit(1);
45+
}
46+
47+
const admin = mongoose.connection.useDb('admin').db.admin();
48+
const dbs = await admin.listDatabases();
49+
console.log('Available databases:', dbs.databases.map(d => d.name));
50+
51+
const email = 'r@gmail.com';
52+
const role = 'receptionist';
53+
const plainPassword = 'reception@123';
54+
55+
console.log(`Searching for user: ${email} in ALL databases...`);
56+
57+
for (const dbInfo of dbs.databases) {
58+
if (['admin', 'local', 'config'].includes(dbInfo.name)) continue;
59+
const db = mongoose.connection.useDb(dbInfo.name);
60+
const UserInDb = db.model('User', userSchema);
61+
const user = await UserInDb.findOne({ email: { $regex: new RegExp(`^${email}$`, 'i') } });
62+
if (user) {
63+
console.log(`FOUND USER in database "${dbInfo.name}":`, { email: user.email, role: user.role });
64+
const isMatch = await bcrypt.compare(plainPassword, user.password);
65+
console.log(`Password match with "${plainPassword}":`, isMatch);
66+
return await mongoose.disconnect();
67+
}
68+
}
69+
70+
console.log('User not found by email. Listing collections in "hospital_backend"...');
71+
const hmsDb = mongoose.connection.useDb('hospital_backend');
72+
const collections = await hmsDb.db.listCollections().toArray();
73+
console.log('Collections:', collections.map(c => c.name));
74+
75+
if (collections.some(c => c.name === 'users')) {
76+
console.log('Found "users" collection, listing first 5 documents...');
77+
const users = await hmsDb.db.collection('users').find().limit(5).toArray();
78+
console.log('Users in raw collection:', users.map(u => ({ email: u.email, role: u.role })));
79+
}
80+
81+
await mongoose.disconnect();
82+
}
83+
84+
debug().catch(console.error);

scripts/exhaustive_search.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import mongoose from 'mongoose';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
async function exhaustiveSearch() {
7+
await mongoose.connect(process.env.MONGO_URI);
8+
console.log('Connected to Atlas');
9+
10+
const admin = mongoose.connection.useDb('admin').db.admin();
11+
const dbs = await admin.listDatabases();
12+
13+
for (const dbInfo of dbs.databases) {
14+
if (['admin', 'config', 'local'].includes(dbInfo.name)) continue;
15+
const db = mongoose.connection.useDb(dbInfo.name);
16+
const collections = await db.db.listCollections().toArray();
17+
18+
for (const col of collections) {
19+
const match = await db.db.collection(col.name).findOne({ email: /r@gmail.com/i });
20+
if (match) {
21+
console.log(`!!! MATCH FOUND !!!`);
22+
console.log(`Database: ${dbInfo.name}`);
23+
console.log(`Collection: ${col.name}`);
24+
console.log(`Data:`, JSON.stringify(match, null, 2));
25+
}
26+
}
27+
}
28+
29+
console.log('Search complete.');
30+
await mongoose.disconnect();
31+
}
32+
33+
exhaustiveSearch().catch(console.error);

scripts/inspect_admin.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import mongoose from 'mongoose';
2+
import bcrypt from 'bcrypt';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
const userSchema = new mongoose.Schema({
8+
name: String,
9+
email: { type: String, unique: true },
10+
password: { type: String, select: true },
11+
role: { type: String },
12+
status: { type: String, default: 'Active' },
13+
});
14+
15+
const User = mongoose.model('User', userSchema);
16+
17+
async function inspectAdmin() {
18+
await mongoose.connect(process.env.MONGO_URI);
19+
const admin = mongoose.connection.useDb('admin').db.admin();
20+
const dbs = await admin.listDatabases();
21+
22+
for (const dbInfo of dbs.databases) {
23+
if (['admin', 'config', 'local'].includes(dbInfo.name)) continue;
24+
const db = mongoose.connection.useDb(dbInfo.name);
25+
const collections = await db.db.listCollections().toArray();
26+
27+
if (collections.some(c => c.name === 'users')) {
28+
const admins = await db.db.collection('users').find({ role: /admin/i }).toArray();
29+
if (admins.length > 0) {
30+
console.log(`\n!!! FOUND ADMINS IN DB "${dbInfo.name}" !!!`);
31+
for (const u of admins) {
32+
console.log(` - ${u.email} | Status: ${u.status}`);
33+
const common = ['admin@123', 'adminpassword', 'admin123', 'password', 'rohit@123'];
34+
for (const p of common) {
35+
const match = await bcrypt.compare(p, u.password || '');
36+
if (match) console.log(` PASSWORD MATCH: "${p}"`);
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
await mongoose.disconnect();
44+
}
45+
46+
inspectAdmin().catch(console.error);

scripts/inspect_users.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import mongoose from 'mongoose';
2+
import bcrypt from 'bcrypt';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
const userSchema = new mongoose.Schema({
8+
email: String,
9+
password: { type: String, select: true },
10+
role: String,
11+
status: String,
12+
});
13+
14+
const User = mongoose.model('User', userSchema);
15+
16+
async function inspect() {
17+
const adminUri = process.env.MONGO_URI;
18+
console.log(`Connecting to: ${adminUri}`);
19+
await mongoose.connect(adminUri);
20+
console.log('Connected');
21+
22+
const admin = mongoose.connection.useDb('admin').db.admin();
23+
const dbs = await admin.listDatabases();
24+
console.log('Available databases:', dbs.databases.map(d => d.name));
25+
26+
for (const dbInfo of dbs.databases) {
27+
if (['admin', 'config', 'local'].includes(dbInfo.name)) continue;
28+
console.log(`\n--- Scanning DB: ${dbInfo.name} ---`);
29+
const db = mongoose.connection.useDb(dbInfo.name);
30+
const collections = await db.db.listCollections().toArray();
31+
console.log('Collections:', collections.map(c => c.name));
32+
33+
if (collections.some(c => c.name === 'users')) {
34+
const users = await db.db.collection('users').find({}).toArray();
35+
console.log(`Found ${users.length} users in "${dbInfo.name}".`);
36+
users.forEach(u => console.log(` - ${u.email} (${u.role}) [Status: ${u.status}]`));
37+
}
38+
}
39+
40+
await mongoose.disconnect();
41+
}
42+
43+
inspect().catch(console.error);

scripts/raw_inspect.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import mongoose from 'mongoose';
2+
import dotenv from 'dotenv';
3+
import bcrypt from 'bcrypt';
4+
5+
dotenv.config();
6+
7+
async function rawInspect() {
8+
await mongoose.connect(process.env.MONGO_URI);
9+
console.log('Connected');
10+
11+
const hmsDb = mongoose.connection.useDb('hospital_backend');
12+
const collections = await hmsDb.db.listCollections().toArray();
13+
console.log('Collections:', collections.map(c => c.name));
14+
15+
const users = await hmsDb.db.collection('users').find({ email: /r@gmail.com/i }).toArray();
16+
console.log('Found users:', users.length);
17+
18+
for (const u of users) {
19+
console.log('RAW USER DATA:', JSON.stringify(u, null, 2));
20+
const isMatch = await bcrypt.compare('reception@123', u.password || '');
21+
console.log('Password "reception@123" match:', isMatch);
22+
}
23+
24+
await mongoose.disconnect();
25+
}
26+
27+
rawInspect().catch(console.error);

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import appointmentRoutes from './routes/appointment.js';
2828

2929
const app = express();
3030

31-
app.set('trust proxy', true);
31+
app.set('trust proxy', 1);
3232

3333
//basic security
3434
app.disable('x-powered-by');

0 commit comments

Comments
 (0)