Files
calebburke.dev/api/src/policies/flashcards-policy.ts
T

42 lines
978 B
TypeScript

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