-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleAPI.js
36 lines (30 loc) · 912 Bytes
/
exampleAPI.js
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
module.exports = ({app, validate, SERVICES, VALIDATORS}) => {
const {
exampleService,
dbService,
elasticSearchService
} = SERVICES;
app.get("/example", async (req, res) => {
return res.status(200).json({message:"Hello World - Example3"})
});
app.post("/example", validate(VALIDATORS.example), async (req, res) => {
try{
let resp = await exampleService.get(req.body.name);
let test = await dbService.query('example');
let testES = await elasticSearchService.client().search({
index: 'my-index',
body: { foo: 'bar' }
});
if(resp){
res.json({message:`Example saved`})
}
else{
res.status(500).json({message:"Unable to save example"})
}
}
catch(e){
console.error(e)
res.status(500).json({message:"Unable to save example"})
}
});
}