-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into orderCancel
- Loading branch information
Showing
19 changed files
with
338 additions
and
74 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,51 @@ | ||
|
||
import { hasOrder, changeOrdertoIn, changeOrdertoWait } from '../../model/reserveModel.js'; | ||
|
||
function ReqIsNumber(s) { | ||
return parseFloat(s).toString() !== "NaN"; | ||
} | ||
|
||
export async function changeOrderStatus(req, res) { | ||
try { | ||
const { restaurantId, tableId, reservationId, phone } = req.body; | ||
console.log(restaurantId) | ||
console.log(tableId) | ||
console.log(reservationId) | ||
console.log(phone) | ||
|
||
if (!restaurantId || !phone || !phone.startsWith('09') || !ReqIsNumber(restaurantId)) { | ||
return res.status(400).json({ error: 'Wrong format in request body.' }); | ||
} | ||
const phoneNum = parseInt(phone, 10); | ||
const isOrdered = await hasOrder(restaurantId,phoneNum); | ||
|
||
if (!isOrdered) { | ||
return res.status(404).json({ | ||
error: 'Phone not found in orderList.', | ||
}); | ||
} | ||
|
||
|
||
if (tableId !== null) { | ||
const orderstatusIn = await changeOrdertoIn(restaurantId, phoneNum, tableId) | ||
console.log(orderstatusIn); | ||
if(orderstatusIn === null ){ | ||
return res.status(404).json({ error: 'No data found' }); | ||
} | ||
return res.status(200).json({ data: {orderId:orderstatusIn} }) | ||
} | ||
|
||
if (reservationId !== null) { | ||
const orderstatusWait = await changeOrdertoWait(restaurantId, phoneNum, reservationId) | ||
console.log(orderstatusWait); | ||
if(orderstatusWait === null ){ | ||
return res.status(404).json({ error: 'No data found' }); | ||
} | ||
return res.status(200).json({ data: {orderId:orderstatusWait} }) | ||
} | ||
|
||
} catch (error) { | ||
console.error('Error in tableCancel:', error); | ||
return res.status(500).json({ error: 'Internal server 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
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
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
Oops, something went wrong.