-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (33 loc) · 1.74 KB
/
Copy pathindex.js
File metadata and controls
37 lines (33 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const express = require("express");
require("dotenv").config();
require("./db");
const cors = require("cors");
const port = process.env.PORT;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
const employeeRouter = require("./routers/employeeRouter");
const Employee = require("./models/employeeModel");
app.use("/employee", employeeRouter);
// Seed employees if not already present
async function seedEmployees() {
const count = await Employee.countDocuments();
if (count === 0) {
await Employee.insertMany([
{ firstName: 'Vinayak', lastName: 'Sharma', email: 'vinayak.sharma@ems.com', contact: 9999999999, designation: 'CEO' },
{ firstName: 'Amit', lastName: 'Verma', email: 'amit.verma@ems.com', contact: 8888888888, designation: 'CTO' },
{ firstName: 'Priya', lastName: 'Singh', email: 'priya.singh@ems.com', contact: 7777777777, designation: 'HR Manager' },
{ firstName: 'Rahul', lastName: 'Mehra', email: 'rahul.mehra@ems.com', contact: 6666666666, designation: 'Lead Developer' },
{ firstName: 'Sneha', lastName: 'Patel', email: 'sneha.patel@ems.com', contact: 5555555555, designation: 'UI/UX Designer' },
{ firstName: 'Arjun', lastName: 'Rao', email: 'arjun.rao@ems.com', contact: 4444444444, designation: 'QA Engineer' },
{ firstName: 'Meera', lastName: 'Nair', email: 'meera.nair@ems.com', contact: 3333333333, designation: 'Marketing Head' },
{ firstName: 'Rohit', lastName: 'Sinha', email: 'rohit.sinha@ems.com', contact: 2222222222, designation: 'Operations Manager' },
]);
console.log('Seeded 8 employees including CEO Vinayak Sharma.');
}
}
seedEmployees();
app.listen(port, () => {
console.log(`Your App is Running at ${port}`);
});