-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(types): rework all types (#7)
- Loading branch information
1 parent
9f00e02
commit e180573
Showing
4 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
/** | ||
* Defines the structure of a validation error | ||
* | ||
* @typeParam Expected - The expected value type | ||
* @typeParam Received - The received value type | ||
*/ | ||
export type ValidationError<Expected = string, Received = unknown> = { | ||
/** | ||
* The expected type | ||
*/ | ||
expected: Expected | ||
/** | ||
* The error message | ||
*/ | ||
message: string | ||
/** | ||
* The received value | ||
*/ | ||
received: Received | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
export type Category = | ||
| "Art" | ||
| "Fashion" | ||
| "Funny" | ||
| "Inspirational" | ||
| "Leadership" | ||
| "Life" | ||
| "Love" | ||
| "Motivational" | ||
| "Music" | ||
| "People" | ||
| "Sports" | ||
| "Success" | ||
| "Wisdom" | ||
| "Work" | ||
import type { Quote as PrismaQuote } from "@prisma/client" | ||
|
||
export type Quote = { | ||
/** | ||
* Defines the structure of a quote before it is added to the database | ||
*/ | ||
export type QuoteCreation = { | ||
/** | ||
* The author of the quote | ||
*/ | ||
author?: string | ||
categories: Category[] | ||
/** | ||
* The categories the quote belongs in | ||
*/ | ||
categories: string[] | ||
/** | ||
* The submitter of the quote | ||
*/ | ||
submitter: string | ||
/** | ||
* The text of the quote | ||
*/ | ||
text: string | ||
/** | ||
* Whether the quote is verified or not | ||
*/ | ||
verified: boolean | ||
} | ||
|
||
export type QuoteWithStringCategories = Omit<Quote, "categories"> & { categories: string } | ||
/** | ||
* Defines the structure of a quote after it is added to the database | ||
*/ | ||
export type DatabaseQuote = Omit<QuoteCreation, "categories"> & { | ||
/** | ||
* The categories the quote belongs in | ||
*/ | ||
categories: PrismaQuote["categories"] | ||
/** | ||
* The date the quote was submitted | ||
*/ | ||
createdAt: PrismaQuote["createdAt"] | ||
/** | ||
* The Id of the quote | ||
*/ | ||
id: PrismaQuote["id"] | ||
/** | ||
* The date the quote was last updated | ||
*/ | ||
updatedAt: PrismaQuote["updatedAt"] | ||
} | ||
|
||
/** | ||
* Defines the structure of a quote with categories as an array | ||
*/ | ||
export type QuoteWithCategoriesArray = Omit<DatabaseQuote, "categories"> & Pick<QuoteCreation, "categories"> | ||
|
||
export type QuoteUnion = Quote | QuoteWithStringCategories | ||
/** | ||
* Defined a union of a quote before and after it is added to the database | ||
*/ | ||
export type QuoteUnion = DatabaseQuote | QuoteCreation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters