Skip to content

✨ Validate book store write endpoints with zod schemas#1260

Merged
williamchong merged 2 commits into
likecoin:masterfrom
williamchong:develop
May 20, 2026
Merged

✨ Validate book store write endpoints with zod schemas#1260
williamchong merged 2 commits into
likecoin:masterfrom
williamchong:develop

Conversation

@williamchong
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces Zod-based request validation for LikeNFT book store write endpoints, replacing bespoke validation helpers and adding a reusable Express validation middleware.

Changes:

  • Added Zod schemas for NFT book store write request bodies (prices, listing settings, image upload).
  • Added validateBody/validateQuery/validateParams middleware to enforce schemas and return structured validation errors.
  • Removed legacy validatePrice / validatePrices helpers and wired routes to schema validation.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/util/api/likernft/book/schemas.ts New Zod schemas for bookstore write endpoints (prices/listing/settings/image upload).
src/util/api/likernft/book/index.ts Removes legacy manual price validation helpers.
src/routes/likernft/book/store.ts Applies validateBody(...) to write endpoints and adjusts logic accordingly.
src/middleware/validate.ts New generic Zod validation middleware producing ValidationError('INVALID_INPUT') with issue details.
package.json Adds zod dependency.
package-lock.json Locks zod dependency.

Comment thread src/util/api/likernft/book/schemas.ts Outdated
hideAudio: z.boolean().optional(),
hideUpsell: z.boolean().optional(),
enableCustomMessagePage: z.boolean().optional(),
tableOfContents: z.unknown().optional(),
Comment on lines +15 to +19
function makeValidator(target: Target) {
return <T>(schema: ZodSchema<T>): RequestHandler => (req, _res, next) => {
const result = schema.safeParse(req[target]);
if (!result.success) {
next(new ValidationError('INVALID_INPUT', 400, {
Comment thread src/util/api/likernft/book/schemas.ts Outdated
Comment on lines +41 to +45
const ConnectedWalletsSchema = z.record(z.string(), z.number());

export const ListingSettingsBodySchema = z.object({
moderatorWallets: z.array(z.string()).optional(),
connectedWallets: ConnectedWalletsSchema.optional(),
Adds validateBody/validateQuery/validateParams middleware that bridges
zod parse errors into the existing ValidationError contract, and wires
it into every /likernft/book/store write endpoint that book-press calls
(new listing, settings update, price create/update/reorder, image
upload). validatePrice and validatePrices in util/api/likernft/book now
delegate to the new schemas, keeping the helper signatures intact.

Failures from migrated endpoints emit a generic INVALID_INPUT code with
a structured payload { target, issues: [{ path, code, message }] }
instead of the previous per-field codes (INVALID_PRICE,
INVALID_PRICE_STOCK, INVALID_PRICE_NAME, PRICES_ARE_EMPTY, etc.).
Clients should read error payload.issues for the failing field path.
@williamchong williamchong marked this pull request as ready for review May 20, 2026 08:36
@nwingt nwingt requested a review from Copilot May 20, 2026 08:37
@williamchong williamchong merged commit 88a362d into likecoin:master May 20, 2026
1 check passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +15 to +23
function makeValidator(target: Target) {
return <T>(schema: ZodSchema<T>): RequestHandler => (req, _res, next) => {
const result = schema.safeParse(req[target]);
if (!result.success) {
next(new ValidationError('INVALID_INPUT', 400, {
target,
issues: formatIssues(result.error.issues),
}));
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants