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.increments("id").notNullable().primary()
table.integer("flashcard_deck_id").notNullable() table.integer("flashcard_deck_id").notNullable()
table.integer("creator_id").notNullable() table.integer("creator_id").notNullable()
table.string("card_type", 255).notNullable()
table.text("front").notNullable() table.text("front").notNullable()
table.text("back").nullable() table.text("back").notNullable()
table table
.specificType("created_at", "TIMESTAMP WITH TIME ZONE") .specificType("created_at", "TIMESTAMP WITH TIME ZONE")
+2 -5
View File
@@ -35,16 +35,13 @@ export class Flashcard extends BaseModel<
@NotNull @NotNull
declare creatorId: number declare creatorId: number
@Attribute(DataTypes.STRING(255))
@NotNull
declare cardType: string
@Attribute(DataTypes.TEXT) @Attribute(DataTypes.TEXT)
@NotNull @NotNull
declare front: string declare front: string
@Attribute(DataTypes.TEXT) @Attribute(DataTypes.TEXT)
declare back: string | null @NotNull
declare back: string
@Attribute(DataTypes.DATE(0)) @Attribute(DataTypes.DATE(0))
@NotNull @NotNull
@@ -5,7 +5,7 @@ import BaseSerializer from "@/serializers/base-serializer"
export type FlashcardIndexView = Pick< export type FlashcardIndexView = Pick<
Flashcard, Flashcard,
"id" | "flashcardDeckId" | "creatorId" | "cardType" | "front" | "back" | "createdAt" | "updatedAt" "id" | "flashcardDeckId" | "creatorId" | "front" | "back" | "createdAt" | "updatedAt"
> >
export class IndexSerializer extends BaseSerializer<Flashcard> { export class IndexSerializer extends BaseSerializer<Flashcard> {
@@ -14,7 +14,6 @@ export class IndexSerializer extends BaseSerializer<Flashcard> {
"id", "id",
"flashcardDeckId", "flashcardDeckId",
"creatorId", "creatorId",
"cardType",
"front", "front",
"back", "back",
"createdAt", "createdAt",
@@ -5,7 +5,7 @@ import BaseSerializer from "@/serializers/base-serializer"
export type FlashcardShowView = Pick< export type FlashcardShowView = Pick<
Flashcard, Flashcard,
"id" | "flashcardDeckId" | "creatorId" | "cardType" | "front" | "back" | "createdAt" | "updatedAt" "id" | "flashcardDeckId" | "creatorId" | "front" | "back" | "createdAt" | "updatedAt"
> >
export class ShowSerializer extends BaseSerializer<Flashcard> { export class ShowSerializer extends BaseSerializer<Flashcard> {
@@ -14,7 +14,6 @@ export class ShowSerializer extends BaseSerializer<Flashcard> {
"id", "id",
"flashcardDeckId", "flashcardDeckId",
"creatorId", "creatorId",
"cardType",
"front", "front",
"back", "back",
"createdAt", "createdAt",
@@ -12,7 +12,7 @@ export class CreateService extends BaseService {
} }
async perform(): Promise<Flashcard> { async perform(): Promise<Flashcard> {
const { flashcardDeckId, creatorId, cardType, front, ...optionalAttributes } = this.attributes const { flashcardDeckId, creatorId, front, back, ...optionalAttributes } = this.attributes
if (isNil(flashcardDeckId)) { if (isNil(flashcardDeckId)) {
throw new Error("Flashcard deck is required") throw new Error("Flashcard deck is required")
@@ -22,20 +22,20 @@ export class CreateService extends BaseService {
throw new Error("Creator is required") throw new Error("Creator is required")
} }
if (isNil(cardType)) {
throw new Error("Card type is required")
}
if (isNil(front)) { if (isNil(front)) {
throw new Error("Front is required") throw new Error("Front is required")
} }
if (isNil(back)) {
throw new Error("Back is required")
}
return Flashcard.create({ return Flashcard.create({
...optionalAttributes, ...optionalAttributes,
flashcardDeckId, flashcardDeckId,
creatorId, creatorId,
cardType,
front, front,
back,
}) })
} }
} }
+6 -1
View File
@@ -1,5 +1,10 @@
import http from "@/api/http-client" 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 = { export type FlashcardDeck = {
id: number id: number
+8 -4
View File
@@ -1,18 +1,22 @@
import http from "@/api/http-client" 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 = { export type Flashcard = {
id: number id: number
flashcardDeckId: number flashcardDeckId: number
creatorId: number creatorId: number
cardType: string
front: string front: string
back: string | null back: string
createdAt: string createdAt: string
updatedAt: string updatedAt: string
} }
export type FlashcardWhereOptions = WhereOptions<Flashcard, "flashcardDeckId" | "creatorId" | "cardType"> export type FlashcardWhereOptions = WhereOptions<Flashcard, "flashcardDeckId" | "creatorId">
export type FlashcardFiltersOptions = FiltersOptions<{ export type FlashcardFiltersOptions = FiltersOptions<{
search: string | string[] search: string | string[]