bplmaps / lane-mead-portal

Lane-Mead portal for collections and research on Boston's maritime industrial history
GNU General Public License v3.0
2 stars 0 forks source link

reschematize featured items, build custom zod validator #13

Closed ericrobskyhuntley closed 1 year ago

ericrobskyhuntley commented 1 year ago

New schema for collections (boolean featured removed from items:

{
    "title": "Shipping and Containerization",
    "description": "Here are a few paragraphs about shipping and containerization. Hi ho hum. He ho hum hee.",
    "items": [
        "commonwealth:3r077j844",
        "commonwealth:9s161h27h"
    ],
    "featured": "commonwealth:9s161h27h" // <- must be present in items
}

Custom validator that checks whether featured item is present in items:

  schema: z.object({
    title: z.string(),
    description: z.string(),
    items: z.array(reference('item')),
    featured: reference('item')
  }).superRefine(
    ({items, featured}, ctx) => {
      if (!items.map((d) => d.id).includes(featured.id)) {
        ctx.addIssue({
          code: "custom",
          message: "`featured` must be included in `items`",
          path: ["featured"]
        })
      }
  }),
netlify[bot] commented 1 year ago

Deploy Preview for lane-mead-portal-dev ready!

Name Link
Latest commit 7e75123d68762e4df57feaa30f0150c4de896e05
Latest deploy log https://app.netlify.com/sites/lane-mead-portal-dev/deploys/64cbd5d57ebb110008466020
Deploy Preview https://deploy-preview-13--lane-mead-portal-dev.netlify.app/
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.