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
+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