Contact done

This commit is contained in:
Edin Dazdarevic
2017-04-13 17:23:46 +02:00
parent 6ef680a7d3
commit 233437e1c1
7 changed files with 198 additions and 50 deletions

View File

@@ -17,6 +17,43 @@ const AGENTURA_KEY = process.env.AGENTURA_KEY || '1somethingverysecret';
let db;
router.post('/contact/:listingId', async (req, res, next) => {
try {
const listingId = req.params.listingId;
const body = req.body;
const contactRequests = db.collection('contact_requests');
if (!body.email) {
res.status(422);
res.end('Email is required');
return
}
if (!body.name) {
res.status(422);
res.end('Name is required');
return
}
const result = await contactRequests.insertOne({
name : body.name,
email : body.email,
listingId,
message : body.message,
phone : body.phone,
alert : body.alert
});
res.status(200);
res.end();
} catch (e) {
console.log('error:', e);
next(e);
}
});
router.get('/search/listings/:id', async (req, res, next) => {
try {
const id = req.params.id;