-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9f6e84
commit 1098b27
Showing
5 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PORT = 4000 | ||
MONGO_URL = mongodb+srv://vetmedman501:[email protected]/vetmedman?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true | ||
MONGO_URL = mongodb+srv://vetmedman501:[email protected]/vetmed?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true | ||
|
||
|
||
JWT_SECRET = secreatkeycanberandom | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const SearchQuery = require("../models/searchQueryModel"); | ||
const ErrorHandler = require("../utils/errorhandler"); | ||
const catchAsyncErrors = require("../middleware/catchAsyncError"); | ||
|
||
exports.createSearchQuery = catchAsyncErrors(async (req, res, next) => { | ||
const { query } = req.body; | ||
|
||
if (!query) { | ||
return next(new ErrorHandler("Query field is required", 400)); | ||
} | ||
|
||
try { | ||
const newSearchQuery = new SearchQuery({ | ||
query, | ||
}); | ||
|
||
await newSearchQuery.save(); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
message: "Search query saved successfully", | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const searchQuerySchema = new mongoose.Schema({ | ||
query: String, | ||
timestamp: { type: Date, default: Date.now }, | ||
}); | ||
|
||
module.exports = mongoose.model("SearchQueries", searchQuerySchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
const searchController = require("../controllers/searchQueryController"); | ||
const catchAsyncErrors = require("../middleware/catchAsyncError"); | ||
router.post("/search", catchAsyncErrors(searchController.createSearchQuery)); | ||
|
||
module.exports = router; |