Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions backend/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ export const database = {

createOrder({ spotId, userId, items }) {
const parsedItems = items.map((item) => {
if (
!item ||
typeof item!== 'object' ||
Array.isArray(item)
)
{
throw new Error('Invalid item format');
}
if(
//if item has it's own property
Object.prototype.hasOwnProperty.call(item, 'name') ||
Object.prototype.hasOwnProperty.call(item, 'unitPrice') ||
Object.prototype.hasOwnProperty.call(item, 'total')
)
{
throw new Error('Do not provide name, unitPrice, or total. These are derived from catalog. ')
}
const quantity = Number(item.quantity || 0);
if (!item.productId || !Number.isInteger(quantity) || quantity <= 0) {
throw new Error('Each order item must include productId and a positive integer quantity');
Expand Down