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
@@ -0,0 +1,41 @@
import { Attributes, FindOptions } from "@sequelize/core"
import { FlashcardDeck, User } from "@/models"
import { ALL_RECORDS_SCOPE, PolicyFactory } from "@/policies/base-policy"
import { Path } from "@/utils/deep-pick"
export class FlashcardDecksPolicy extends PolicyFactory(FlashcardDeck) {
show(): boolean {
return true
}
create(): boolean {
return true
}
update(): boolean {
return this.user.id === this.record.creatorId
}
destroy(): boolean {
return this.user.id === this.record.creatorId
}
permittedAttributes(): Path[] {
return ["name", "parentDeckId"] as (keyof Attributes<FlashcardDeck>)[]
}
permittedAttributesForCreate(): Path[] {
return [...this.permittedAttributes()]
}
permittedAttributesForUpdate(): Path[] {
return [...this.permittedAttributes()]
}
static policyScope(_user: User): FindOptions<Attributes<FlashcardDeck>> {
return ALL_RECORDS_SCOPE
}
}
export default FlashcardDecksPolicy
+41
View File
@@ -0,0 +1,41 @@
import { Attributes, FindOptions } from "@sequelize/core"
import { Flashcard, User } from "@/models"
import { ALL_RECORDS_SCOPE, PolicyFactory } from "@/policies/base-policy"
import { Path } from "@/utils/deep-pick"
export class FlashcardsPolicy extends PolicyFactory(Flashcard) {
show(): boolean {
return true
}
create(): boolean {
return true
}
update(): boolean {
return this.user.id === this.record.creatorId
}
destroy(): boolean {
return this.user.id === this.record.creatorId
}
permittedAttributes(): Path[] {
return ["flashcardDeckId", "cardType", "front", "back"] as (keyof Attributes<Flashcard>)[]
}
permittedAttributesForCreate(): Path[] {
return [...this.permittedAttributes()]
}
permittedAttributesForUpdate(): Path[] {
return [...this.permittedAttributes()]
}
static policyScope(_user: User): FindOptions<Attributes<Flashcard>> {
return ALL_RECORDS_SCOPE
}
}
export default FlashcardsPolicy
+2
View File
@@ -1,3 +1,5 @@
// Policy Bundles
export { type BaseScopeOptions } from "./base-policy"
export { FlashcardDecksPolicy } from "./flashcard-decks-policy"
export { FlashcardsPolicy } from "./flashcards-policy"
export { UsersPolicy } from "./users-policy"