generated from alphane/template
Adding in flashcard's and decks
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user