-
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
82d3ad3
commit 9d98de1
Showing
5 changed files
with
75 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use server" | ||
export async function saveReservation(reservationData: any) { | ||
const res = await fetch("http://localhost:8080/api/saveReservation", { | ||
method: "POST", | ||
cache: "no-store", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(reservationData), | ||
}); | ||
const data = await res.json(); | ||
return data; | ||
} |
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,14 +1,33 @@ | ||
import Description from "@/components/gallery/description"; | ||
import { getDestination } from "@/api/destination"; | ||
import { saveReservation } from "@/api/orders"; | ||
|
||
const Destination = async ({ params }: { params: { destination: string } }) => { | ||
const destination = await getDestination(params.destination); | ||
console.log(destination); | ||
return ( | ||
<> | ||
<Description {...destination.destination} /> | ||
</> | ||
); | ||
const reservationData = { | ||
id: destination.id, | ||
title: destination.title, | ||
host: destination.host, | ||
price: destination.price, | ||
description: destination.description | ||
}; | ||
const reserve = await saveReservation(reservationData); | ||
try { | ||
if (reserve.ok) { | ||
console.log('Data saved successfully'); | ||
} else { | ||
console.error('Error saving data'); | ||
} | ||
} catch (error) | ||
{ | ||
console.error('Error saving data', error); | ||
} | ||
return ( | ||
<> | ||
<Description {...destination.destination} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Destination; |
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,11 @@ | ||
const reservation = require('../models/ordersModel'); | ||
const saveReservation = async (req, res) => { | ||
const reservations = req.body; | ||
try { | ||
const reservedData = await reservation.saveReservation(reservations); | ||
res.json({ status: 'ok', reservedData }); | ||
} catch (error) { | ||
res.json({ status: 'error', error: error.message }); | ||
} | ||
} | ||
module.exports = {saveReservation} |
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,17 @@ | ||
const mongoose=require('mongoose'); | ||
const reservation = new mongoose.Schema({ | ||
id: String, | ||
title: String, | ||
host: String, | ||
price: Number, | ||
description: String, | ||
from: Date, | ||
to: Date, | ||
}); | ||
|
||
reservation.statics.saveReservation = async function (data) { | ||
const reservation = new this.insertMany(data); | ||
return reservation.save(); | ||
}; | ||
|
||
module.exports = mongoose.model('Reservation', reservation); |
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,10 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
const { | ||
saveReservation, | ||
} = require("../controllers/ordersController"); | ||
|
||
// Sign in route , creating user | ||
router.post("/saveReservation", saveReservation); | ||
module.exports = router; |