Contact done
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user