Skip to content

Commit

Permalink
feat: @mongoose/validate-restaurant method
Browse files Browse the repository at this point in the history
  • Loading branch information
jaineil committed Oct 25, 2021
1 parent 1b8b567 commit bb44295
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions server/controllers/restaurant.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,45 @@ export class RestaurantController {
res.status(500).send('Could not create a restaurant');
}
}

validateRestaurantSignin = async (req, res) => {
console.log(req.body);

const emailId = req.body.emailId;
const password = req.body.password;

try {
const response = await Restaurant.findOne({ $and: [{ emailId: emailId }, { password: password }] });
console.log(JSON.stringify(response));

if (response) {

const restaurantId = response.id;
console.log(restaurantId);

res.cookie("restaurantId", restaurantId, {
maxAge: 3600000,
httpOnly: false,
path: "/"
});
req.session.user = restaurantId;

res.status(200).send({
validCredentials: true
});

res.status(200).send({
validCredentials: true
});

} else {
console.log('User mismatch');
res.status(400).send({ validCredentials: false });
}

} catch (err) {
console.error('Error => ', err);
res.status(500).send('Could not validate customer');
}
}
}
2 changes: 1 addition & 1 deletion server/models/restaurant.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Schema = mongoose.Schema;

const restaurantSchema = new Schema({
name: { type: String },
emailId: { type: String },
emailId: { type: String, unique: true },
password: { type: String },
contactNumber: { type: String },
street: { type: String },
Expand Down
1 change: 1 addition & 0 deletions server/routes/restaurant.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const restaurantRoutes = express.Router();
const restaurantController = new RestaurantController();

restaurantRoutes.post('/create-restaurant', restaurantController.create);
restaurantRoutes.get('/validate-restaurant', restaurantController.validateRestaurantSignin);

export default restaurantRoutes;

0 comments on commit bb44295

Please sign in to comment.