728x90
반응형
- 2024-09-24 : First posting.
.env
파일 설정을 다음과 같이 하자.
User
```[.scrollable]
model User {
id String @id @default(uuid()) // * Can be used by salt in encryption.
email String @unique
nickname String
password String
pwdIter Int @default(10000)
ssnIter Int @default(1000)
articles Article[]
articleComments ArticleComment[]
productComments ProductComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
Product
```[.scrollable]
model Product {
id String @id @default(uuid())
name String
description String
price Float
tags String[]
images String[]
favoriteCount Int
productComments ProductComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
Article
```[.scrollable]
model Article {
id String @id @default(uuid())
title String
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Restrict)
content String
articleComments ArticleComment[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
ProductComment
```[.scrollable]
model ProductComment {
id String @id @default(uuid())
content String
productId String
product Product @relation(fields: [productId], references: [id], onDelete: Restrict)
commenterId String
commenter User @relation(fields: [commenterId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
ArticleComment
```[.scrollable]
model ArticleComment {
id String @id @default(uuid())
content String
articleId String
article Article @relation(fields: [articleId], references: [id])
commenterId String
commenter User @relation(fields: [commenterId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
```/
struct-Product
```[.scrollable]
import * as s from 'superstruct';
import isUuid from 'is-uuid';
const Uuid = s.define('Uuid', (value) => isUuid.v4(value));
export const CreateProduct = s.object({
name: s.size(s.string(), 1, 10),
description: s.size(s.string(), 10, 100),
price: s.min(s.number(), 0),
tags: s.array(s.string()),
images: s.array(s.string()),
favoriteCount: s.min(s.integer(), 0),
});
export const PatchProduct = s.object({
id: Uuid,
...s.partial(CreateProduct),
});
```/
s.set(s.string())
은 어떻게 데이터를 보내는지 모르겠어서 못썼음. 그냥 array 방식으로 묶으면 될줄 알았는데... =ㅇ=;; ["가", "나", "다"]
는 Set 가 아니라고 함.
define
은
```[.scrollable]
import * as s from 'superstruct';
import isEmail from 'is-email';
import isUuid from 'is-uuid';
const Uuid = s.define('Uuid', (value) => isUuid.v4(value));
const email = s.define('email', (value) => isEmail(value));
```/
struct-User
```[.scrollable]
export const CreateUser = s.object({
email: email,
nickname: s.size(s.string(), 1, 20),
password: s.string()
});
export const PatchUser = s.partial(CreateUser);
// * User id 는 따로 받아야 함.
```/
struct-Product
```[.scrollable]
export const CreateProduct = s.object({
name: s.size(s.string(), 1, 10),
description: s.size(s.string(), 10, 100),
price: s.min(s.number(), 0),
tags: s.size(s.array(s.string()), 0, 15),
images: s.size(s.array(s.string()), 1, 2),
favoriteCount: s.min(s.integer(), 0),
});
export const PatchProduct = s.partial(CreateProduct);
// * Product id 는 따로 받아야 함.
```/
struct-Article
```[.scrollable]
export const CreateArticle = s.object({
title: s.size(s.string(), 1, 20),
authorId: Uuid,
content: s.size(s.string(), 10, 500),
});
export const PatchArticle = s.partial(CreateArticle);
// * Article id 는 따로 받아야 함.
```/
struct-ProductComment
```[.scrollable]
export const CreateProductComment = s.object({
productId: Uuid,
commenterId: Uuid,
content: s.size(s.string(), 1, 255),
});
// * Patch 는 위 데이터에 id 추가.
```/
struct-ArticleComment
```[.scrollable]
export const CreateArticleComment = s.object({
articleId: Uuid,
commenterId: Uuid,
content: s.size(s.string(), 1, 255),
});
// * Patch 는 위 데이터에 id 추가.
```/
728x90
반응형