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 { 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
|
||||
Reference in New Issue
Block a user