This commit is contained in:
2026-06-25 18:40:57 -07:00
parent 5585d497c9
commit ba9e888955
7 changed files with 25 additions and 22 deletions
@@ -5,9 +5,8 @@ export async function up(knex: Knex): Promise<void> {
table.increments("id").notNullable().primary()
table.integer("flashcard_deck_id").notNullable()
table.integer("creator_id").notNullable()
table.string("card_type", 255).notNullable()
table.text("front").notNullable()
table.text("back").nullable()
table.text("back").notNullable()
table
.specificType("created_at", "TIMESTAMP WITH TIME ZONE")
+2 -5
View File
@@ -35,16 +35,13 @@ export class Flashcard extends BaseModel<
@NotNull
declare creatorId: number
@Attribute(DataTypes.STRING(255))
@NotNull
declare cardType: string
@Attribute(DataTypes.TEXT)
@NotNull
declare front: string
@Attribute(DataTypes.TEXT)
declare back: string | null
@NotNull
declare back: string
@Attribute(DataTypes.DATE(0))
@NotNull
@@ -5,7 +5,7 @@ import BaseSerializer from "@/serializers/base-serializer"
export type FlashcardIndexView = Pick<
Flashcard,
"id" | "flashcardDeckId" | "creatorId" | "cardType" | "front" | "back" | "createdAt" | "updatedAt"
"id" | "flashcardDeckId" | "creatorId" | "front" | "back" | "createdAt" | "updatedAt"
>
export class IndexSerializer extends BaseSerializer<Flashcard> {
@@ -14,7 +14,6 @@ export class IndexSerializer extends BaseSerializer<Flashcard> {
"id",
"flashcardDeckId",
"creatorId",
"cardType",
"front",
"back",
"createdAt",
@@ -5,7 +5,7 @@ import BaseSerializer from "@/serializers/base-serializer"
export type FlashcardShowView = Pick<
Flashcard,
"id" | "flashcardDeckId" | "creatorId" | "cardType" | "front" | "back" | "createdAt" | "updatedAt"
"id" | "flashcardDeckId" | "creatorId" | "front" | "back" | "createdAt" | "updatedAt"
>
export class ShowSerializer extends BaseSerializer<Flashcard> {
@@ -14,7 +14,6 @@ export class ShowSerializer extends BaseSerializer<Flashcard> {
"id",
"flashcardDeckId",
"creatorId",
"cardType",
"front",
"back",
"createdAt",
@@ -12,7 +12,7 @@ export class CreateService extends BaseService {
}
async perform(): Promise<Flashcard> {
const { flashcardDeckId, creatorId, cardType, front, ...optionalAttributes } = this.attributes
const { flashcardDeckId, creatorId, front, back, ...optionalAttributes } = this.attributes
if (isNil(flashcardDeckId)) {
throw new Error("Flashcard deck is required")
@@ -22,20 +22,20 @@ export class CreateService extends BaseService {
throw new Error("Creator is required")
}
if (isNil(cardType)) {
throw new Error("Card type is required")
}
if (isNil(front)) {
throw new Error("Front is required")
}
if (isNil(back)) {
throw new Error("Back is required")
}
return Flashcard.create({
...optionalAttributes,
flashcardDeckId,
creatorId,
cardType,
front,
back,
})
}
}
+6 -1
View File
@@ -1,5 +1,10 @@
import http from "@/api/http-client"
import { type FiltersOptions, type ModelOrder, type Policy, type WhereOptions } from "@/api/base-api"
import {
type FiltersOptions,
type ModelOrder,
type Policy,
type WhereOptions,
} from "@/api/base-api"
export type FlashcardDeck = {
id: number
+8 -4
View File
@@ -1,18 +1,22 @@
import http from "@/api/http-client"
import { type FiltersOptions, type ModelOrder, type Policy, type WhereOptions } from "@/api/base-api"
import {
type FiltersOptions,
type ModelOrder,
type Policy,
type WhereOptions,
} from "@/api/base-api"
export type Flashcard = {
id: number
flashcardDeckId: number
creatorId: number
cardType: string
front: string
back: string | null
back: string
createdAt: string
updatedAt: string
}
export type FlashcardWhereOptions = WhereOptions<Flashcard, "flashcardDeckId" | "creatorId" | "cardType">
export type FlashcardWhereOptions = WhereOptions<Flashcard, "flashcardDeckId" | "creatorId">
export type FlashcardFiltersOptions = FiltersOptions<{
search: string | string[]