Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cms): Add Product API to CMS #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat(cms): Add Product API to CMS #159

wants to merge 1 commit into from

Conversation

mrzzy
Copy link
Contributor

@mrzzy mrzzy commented Jun 2, 2024

Motivation

See card

Contents

⚠️ Needs #158

Implements Product API in CMS with the following product schema:

  • Some schema deviations from the original Product schema in package/types/lib/merch.ts due to Payload limitations.
{
  "id": "665c24f355ede133318452da",
  "name": "Product",
  "colors": [
    "black",
    "blue"
  ],
  "sizes": [
    "s",
    "xl"
  ],
  "images": [
    {
      "url": "https://github.com/ntuscse/website/pull/158",
      "id": "665c24c7a1786092419c4a90"
    },
    {
      "url": "https://github.com/ntuscse/website/pull/158",
      "id": "665c24cda1786092419c4a91"
    }
  ],
  "price": 0.2,
  "category": "hat",
  "size_chart": "https://github.com/ntuscse/website/pull/158",
  "stock": [
    {
      "color": "white",
      "quantity": 5,
      "id": "665c24e1a1786092419c4a92"
    }
  ],
  "createdAt": "2024-06-02T07:53:23.679Z",
  "updatedAt": "2024-06-02T07:53:23.679Z"
}

Demo: Download & import Postman API collection

@mrzzy mrzzy added the enhancement New feature or request label Jun 2, 2024
@mrzzy mrzzy requested a review from Iyzyman June 2, 2024 08:18
@mrzzy mrzzy self-assigned this Jun 2, 2024
Copy link

vercel bot commented Jun 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
website-ui-storybook ✅ Ready (Inspect) Visit Preview Aug 24, 2024 11:48pm

Copy link
Member

@chanbakjsd chanbakjsd left a comment

Choose a reason for hiding this comment

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

We might want to consider how the business team/users will be using this website in our schemas. LGTM otherwise!

Comment on lines +17 to +34
name: "colors",
type: "select",
hasMany: true,
options: [
{
label: "Black",
value: "black",
},
{
label: "White",
value: "white",
},
{
label: "Blue",
value: "blue",
},
],
},
Copy link
Member

Choose a reason for hiding this comment

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

It might make more sense for the type to be "text" with hasMany so we allow the business team to add colours as necessary. The same applies to sizes, category and stock.

Copy link
Contributor Author

@mrzzy mrzzy Aug 24, 2024

Choose a reason for hiding this comment

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

We are on Payload CMS 1.8.3, which does not have hasMany on the text.

Three options:

  1. Upgrade Payload CMS to >2.0, potentially having to stomach breaking changes / large rewrites in the port.
  2. Add a colors, sizes, category & stock collections which can be amended dynamically by the business team and then use the relationship type from the product collection to link to color, sizes etc. However, this normalises the data model which is contradicts the purpose of using a document data model in MongoDB in the first place: colocating data accessed together. Normalisation is more suitable to the generic SQL relational DBs like PostgreSQL.
  3. Do nothing, consider this a premature optimization: one can quickly add options if necessary.

Copy link

Deployment preview link: https://website-l2aesxpo1-cse-it.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants