feat: add POST /api/orders endpoint for customer order creation#54
Draft
zshanhui wants to merge 4 commits into
Draft
feat: add POST /api/orders endpoint for customer order creation#54zshanhui wants to merge 4 commits into
zshanhui wants to merge 4 commits into
Conversation
- Update merchant dashboard route from /merchant to /merchant-dashboard/:uuid - Add online ordering route pattern /online-ordering/:slug - Fix pnpm run dev description: it already uses nodemon --exec tsx, not node - Add seed data UUIDs section for testing convenience Co-authored-by: zshanhui <zshanhui@users.noreply.github.com>
- Add createOrder service function that creates customer, order, and line items - Add POST /api/orders route with input validation (400/422 error responses) - Add createOrder frontend API helper for checkout integration - Fix Orders.create to reliably return UUID on both SQLite and PostgreSQL - Fix Customers.create to accept optional mobile_phone field - Fix CJS/ESM interop for Customers and Merchants TS default exports - Add 6 unit tests covering happy path, validation, and edge cases Co-authored-by: zshanhui <zshanhui@users.noreply.github.com>
…TypeScript - orders.js → orders.ts: add OrderRow, OrderFilter, CreateParams interfaces - actions.js → actions.ts: add CreateOrderParams interface, typed imports, named exports - routes/orders.js → routes/orders.ts: typed Express handlers - Update CJS consumers (index.js, merchants.js) with .default for new TS exports - Convert test spec to use ESM import for actions Co-authored-by: zshanhui <zshanhui@users.noreply.github.com>
…rder API - merchantId field now accepts a UUID or hash_id string (not an integer) - Service resolves via getByUuid() then falls back to getByHashId() - Route rejects non-string merchantId with a 400 - Updated tests to seed merchants with UUID/hash_id and test both lookups - Updated frontend API helper type to string Co-authored-by: zshanhui <zshanhui@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the missing
POST /api/ordersendpoint that the online ordering frontend needs to create orders after checkout. All new server-side code is TypeScript.What it does
The endpoint accepts a JSON body and creates:
Request / Response
Changes
src/server/models/orders.tsOrderRow,OrderFilter,CreateParamsinterfaces. Fixedcreate()to reliably return UUID on SQLite.src/server/services/actions.tsCreateOrderParamsinterface, typed imports, named exports. Fixed CJS/ESM interop.src/server/routes/orders.tsPOST /route with input validation. Typed Express handlers.src/server/models/customers.tscreate()to accept optionalmobile_phonesrc/client/js/api/index.tsxcreateOrderfrontend API helperspecs/services/createOrder.spec.tssrc/server/index.jsrequire()for new TS default exportsrc/server/routes/merchants.jsrequire()for new TS default exportBug fixes included
Orders.createSQLite compatibility:.returning('uuid')is silently ignored by SQLite, so the old code returned a row ID instead of a UUID. Now generates the UUID first and returns it directly.CustomersandMerchantsTS modules useexport default, but CJSrequire()puts them at.default. The oldactions.jsdidn't handle this — now all three files are proper TypeScript with ESM imports.Demo
create_order_api_demo.mp4
Order created via
POST /api/ordersappears immediately in the merchant POS dashboard.Order detail showing API-created order with items and customer info
To show artifacts inline, enable in settings.