Skip to content

Commit b7802dc

Browse files
committed
insert done
1 parent 0378928 commit b7802dc

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

app.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const express = require("express");
44
const client = require("./client");
55

66
const path = require("path");
7+
const { employees } = require("./dummyEmp");
78

89
const app = express();
910

@@ -17,6 +18,25 @@ app.use(
1718
})
1819
);
1920

21+
app.post("/insert", (req, res) => {
22+
client.insert(
23+
{
24+
email: req.body.email,
25+
firstName: req.body.firstName,
26+
lastName: req.body.lastName,
27+
},
28+
(err, response) => {
29+
if (!err) {
30+
console.log("Success");
31+
res.redirect("/");
32+
console.log(response);
33+
} else {
34+
console.log(err.details);
35+
}
36+
}
37+
);
38+
});
39+
2040
app.get("/", (req, res) => {
2141
// Getting getAll function from the client
2242
client.getAll({}, (err, response) => {

protos/employee.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package employee;
1010
service Employee{
1111
rpc getDetails (EmployeeRequest) returns (EmployeeResponse) {}
1212
rpc getAll (Empty) returns (EmployeeRepeatedResponse) {}
13+
rpc insert (EmployeeDetails) returns (EmployeeResponse) {}
1314
}
1415

1516
// used to indicate that there is no request to be sent

server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function getDetails(call, callback) {
3434
});
3535
}
3636

37+
function insert(call, callback) {
38+
let newrecord = call.request;
39+
newrecord.id = 4;
40+
employees.push(newrecord);
41+
callback(null, { message: newrecord });
42+
}
43+
3744
function getAll(call, callback) {
3845
callback(null, {
3946
message: employees,
@@ -49,6 +56,7 @@ function main() {
4956
server.addService(employeeProto.Employee.service, {
5057
getDetails: getDetails,
5158
getAll: getAll,
59+
insert: insert,
5260
});
5361

5462
server.bind("0.0.0.0:3001", grpc.ServerCredentials.createInsecure()); // Binds to a port -- createInsecure() is given to say there is no authentication in the server

test.http

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POST http://localhost:3000/insert
2+
Content-Type: application/json
3+
4+
{
5+
"email": "test@test.com",
6+
"firstName": "Dovah",
7+
"lastName": "kiin"
8+
}

views/details.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ html(lang="en")
1212
th last Name
1313
tr
1414
td
15-
fname= details.firstName
15+
email= details.email
1616
td
17-
lname= details.lastName
17+
fname= details.firstName
1818
td
19-
email= details.email
19+
lname= details.lastName

views/home.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ html(lang="en")
1212
th last Name
1313
each val in details
1414
tr
15+
td
16+
email= val.email
1517
td
1618
fname= val.firstName
1719
td
1820
lname= val.lastName
19-
td
20-
email= val.email
2121

0 commit comments

Comments
 (0)