generated from alphane/template
Adding a ton of stuff
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { type CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, sql } from "@sequelize/core"
|
||||
import { Attribute, AutoIncrement, Default, Index, NotNull, PrimaryKey } from "@sequelize/core/decorators-legacy"
|
||||
import { isNil } from "lodash"
|
||||
|
||||
import BaseModel from "@/models/base-model"
|
||||
|
||||
export class BlogPost extends BaseModel<InferAttributes<BlogPost>, InferCreationAttributes<BlogPost>> {
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
declare id: CreationOptional<number>
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@NotNull
|
||||
declare creatorId: number
|
||||
|
||||
@Attribute(DataTypes.STRING(255))
|
||||
@NotNull
|
||||
declare title: string
|
||||
|
||||
@Attribute(DataTypes.STRING(255))
|
||||
@NotNull
|
||||
@Index({ unique: true })
|
||||
declare slug: string
|
||||
|
||||
@Attribute(DataTypes.TEXT)
|
||||
@NotNull
|
||||
declare content: string
|
||||
|
||||
@Attribute({
|
||||
type: DataTypes.STRING(1024),
|
||||
get() {
|
||||
const tags = this.getDataValue("tags")
|
||||
if (isNil(tags) || tags === "") {
|
||||
return []
|
||||
}
|
||||
return tags.split(",")
|
||||
},
|
||||
set(value: string[]) {
|
||||
this.setDataValue("tags", value.join(","))
|
||||
},
|
||||
})
|
||||
@NotNull
|
||||
@Default("")
|
||||
declare tags: CreationOptional<string[]>
|
||||
|
||||
@Attribute(DataTypes.DATE(0))
|
||||
declare publishedAt: Date | null
|
||||
|
||||
@Attribute(DataTypes.DATE(0))
|
||||
@NotNull
|
||||
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||
declare createdAt: CreationOptional<Date>
|
||||
|
||||
@Attribute(DataTypes.DATE(0))
|
||||
@NotNull
|
||||
@Default(sql.literal("CURRENT_TIMESTAMP"))
|
||||
declare updatedAt: CreationOptional<Date>
|
||||
|
||||
@Attribute(DataTypes.DATE(0))
|
||||
declare deletedAt: Date | null
|
||||
|
||||
// Scopes
|
||||
static establishScopes(): void {
|
||||
this.addSearchScope(["title", "content"])
|
||||
}
|
||||
}
|
||||
|
||||
export default BlogPost
|
||||
Reference in New Issue
Block a user