Adding in flashcard's and decks

This commit is contained in:
2026-06-25 02:39:16 -07:00
parent 78da882bda
commit 535c4c4943
34 changed files with 1248 additions and 1 deletions
+68
View File
@@ -0,0 +1,68 @@
import {
type CreationOptional,
DataTypes,
InferAttributes,
InferCreationAttributes,
type NonAttribute,
sql,
} from "@sequelize/core"
import {
Attribute,
AutoIncrement,
BelongsTo,
Default,
NotNull,
PrimaryKey,
} from "@sequelize/core/decorators-legacy"
import BaseModel from "@/models/base-model"
export class FlashcardDeck extends BaseModel<
InferAttributes<FlashcardDeck>,
InferCreationAttributes<FlashcardDeck>
> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>
@Attribute(DataTypes.INTEGER)
declare parentDeckId: number | null
@Attribute(DataTypes.INTEGER)
@NotNull
declare creatorId: number
@Attribute(DataTypes.STRING(255))
@NotNull
declare name: string
@Attribute(DataTypes.DATE(0))
@NotNull
@Default(sql.literal("CURRENT_TIMESTAMP"))
declare createdAt: CreationOptional<Date>
@Attribute(DataTypes.DATE(0))
@NotNull
@Default(sql.literal("CURRENT_TIMESTAMP"))
declare updatedAt: CreationOptional<Date>
@Attribute(DataTypes.DATE(0))
declare deletedAt: Date | null
// Associations
@BelongsTo(() => FlashcardDeck, {
foreignKey: {
name: "parentDeckId",
allowNull: true,
},
})
declare parentDeck?: NonAttribute<FlashcardDeck>
// Scopes
static establishScopes(): void {
this.addSearchScope(["name"])
}
}
export default FlashcardDeck
+81
View File
@@ -0,0 +1,81 @@
import {
type CreationOptional,
DataTypes,
InferAttributes,
InferCreationAttributes,
type NonAttribute,
sql,
} from "@sequelize/core"
import {
Attribute,
AutoIncrement,
BelongsTo,
Default,
NotNull,
PrimaryKey,
} from "@sequelize/core/decorators-legacy"
import BaseModel from "@/models/base-model"
import FlashcardDeck from "@/models/flashcard-deck"
export class Flashcard extends BaseModel<
InferAttributes<Flashcard>,
InferCreationAttributes<Flashcard>
> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>
@Attribute(DataTypes.INTEGER)
@NotNull
declare flashcardDeckId: number
@Attribute(DataTypes.INTEGER)
@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
@Attribute(DataTypes.DATE(0))
@NotNull
@Default(sql.literal("CURRENT_TIMESTAMP"))
declare createdAt: CreationOptional<Date>
@Attribute(DataTypes.DATE(0))
@NotNull
@Default(sql.literal("CURRENT_TIMESTAMP"))
declare updatedAt: CreationOptional<Date>
@Attribute(DataTypes.DATE(0))
declare deletedAt: Date | null
// Associations
@BelongsTo(() => FlashcardDeck, {
foreignKey: {
name: "flashcardDeckId",
allowNull: false,
},
inverse: {
as: "flashcards",
type: "hasMany",
},
})
declare flashcardDeck?: NonAttribute<FlashcardDeck>
// Scopes
static establishScopes(): void {
this.addSearchScope(["front", "back"])
}
}
export default Flashcard
+8
View File
@@ -1,16 +1,24 @@
import db from "@/db/db-client"
// Models
import Flashcard from "@/models/flashcard"
import FlashcardDeck from "@/models/flashcard-deck"
import User, { UserRoles } from "@/models/user"
db.addModels([
Flashcard,
FlashcardDeck,
User,
])
// Lazy load scopes
Flashcard.establishScopes()
FlashcardDeck.establishScopes()
User.establishScopes()
export {
Flashcard,
FlashcardDeck,
User,
UserRoles,
}