iT邦幫忙

2024 iThome 鐵人賽

DAY 13
0
佛心分享-SideProject30

NUXT3xVUE3xPINIA: 從零開始寫電商系列 第 13

[Day 13] Models - 建立資料模型的type

  • 分享至 

  • xImage
  •  

商品功能的API使用dummyData-Products的APIs,就沒有自己寫了。會員功能則搭配firebase。把他們的資料模型列出來,然後依序創建他們的type。

目錄

  • DataModel
  • ViewModel
  • 碎碎念

DataModel

export type Product_ReviewModel = {
    rating: number,
    comment: string,
    date: string,
    reviewerName: string,
    reviewerEmail: string
}
export type Product_MetaModel = {
    createdAt: string,
    updatedAt: string,
    barcode: string,
    qrCode: string
}
export type ProductDetailModel = {
    id: number,
    title: string,
    description: string,
    category: string,
    price: number,
    discountPercentage: number,
    rating: number,
    stock: number,
    tags: Array<string>,
    brand: string,
    sku: string,
    weight: number,
    dimensions: {
        width: number,
        height: number,
        depth: number
    },
    warrantyInformation: string,
    shippingInformation: string,
    availabilityStatus: string,
    reviews: Array<Product_ReviewModel>,
    returnPolicy: string,
    minimumOrderQuantity: number,
    meta: Product_MetaModel,
    thumbnail: string,
    images: Array<string>
}

export type ProductListModel = {
    products: Array<ProductDetailModel>,
    total: number,
    skip: number,
    limit: number
}

export type CategoryItemModel = {
    slug: string,
    name: string,
    url: string
}

export type CategoryNameListModel = Array<string>;

ViewModel

ViewModel的部分就依照當時設計的草稿,基於apiModel整理出需要的欄位:

export type RegistrationModel = {
    email: string;
    password: string;
    confirmPassword: string;
}

export type LoginModel =  {
    email: string;
    password: string;
}

export type userModel = {
    UID: string;
    name: string;
    phone: string;
    address: string;
    email: string;
}

export type purchaseOrder = {
    userUID: string;
    purchaseID: string;
    purchaseDate: string;
}

export type item = {
    purchaseID: string;
    productId: string;
}

export type purchaseOrderItem = {
    purchaseID: string;
    purchaseItems: Array<item>;
}

碎碎念

我覺得view model應該後來會改內容XDDDDD


上一篇
[Day 12] 資料控制中心: Store via Pinia
下一篇
[Day 14] 設定i18n
系列文
NUXT3xVUE3xPINIA: 從零開始寫電商17
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言