import { Attributes, FindOptions } from "@sequelize/core" import { BlogPost, User } from "@/models" import { ALL_RECORDS_SCOPE, PolicyFactory } from "@/policies/base-policy" import { Path } from "@/utils/deep-pick" export class BlogPostsPolicy extends PolicyFactory(BlogPost) { show(): boolean { if (this.user.isSystemAdmin) { return true } return false } create(): boolean { if (this.user.isSystemAdmin) { return true } return false } update(): boolean { if (this.user.isSystemAdmin) { return true } return false } destroy(): boolean { if (this.user.isSystemAdmin) { return true } return false } permittedAttributes(): Path[] { return ["title", "slug", "content", "tags", "publishedAt"] as (keyof Attributes)[] } permittedAttributesForCreate(): Path[] { return [...this.permittedAttributes()] } permittedAttributesForUpdate(): Path[] { return [...this.permittedAttributes()] } static policyScope(_user: User): FindOptions> { return ALL_RECORDS_SCOPE } } export default BlogPostsPolicy