src/modules/category/category.model.ts
Properties |
|
Optional article_count |
Type : number
|
Defined in src/modules/category/category.model.ts:62
|
Optional created_at |
Type : Date
|
Decorators :
@prop({default: undefined, immutable: true})
|
Defined in src/modules/category/category.model.ts:51
|
description |
Type : string
|
Decorators :
@IsString()
|
Defined in src/modules/category/category.model.ts:45
|
extends |
Type : KeyValueModel[]
|
Decorators :
@ArrayUnique()
|
Defined in src/modules/category/category.model.ts:59
|
id |
Type : number
|
Decorators :
@prop({unique: true})
|
Defined in src/modules/category/category.model.ts:29
|
name |
Type : string
|
Decorators :
@IsString()
|
Defined in src/modules/category/category.model.ts:34
|
pid |
Type : Types.ObjectId
|
Decorators :
@prop({ref: Category, default: undefined})
|
Defined in src/modules/category/category.model.ts:48
|
slug |
Type : string
|
Decorators :
@Matches(/^[a-zA-Z0-9-_]+$/)
|
Defined in src/modules/category/category.model.ts:41
|
Optional updated_at |
Type : Date
|
Decorators :
@prop({default: undefined})
|
Defined in src/modules/category/category.model.ts:54
|
import { Types } from 'mongoose'
import { AutoIncrementID } from '@typegoose/auto-increment'
import { prop, plugin, modelOptions } from '@typegoose/typegoose'
import { IsString, MaxLength, Matches, IsNotEmpty, IsArray, ArrayUnique } from 'class-validator'
import { GENERAL_AUTO_INCREMENT_ID_CONFIG } from '@app/constants/increment.constant'
import { getProviderByTypegooseClass } from '@app/transformers/model.transformer'
import { mongoosePaginate } from '@app/utils/paginate'
import { KeyValueModel } from '@app/models/key-value.model'
@plugin(mongoosePaginate)
@plugin(AutoIncrementID, GENERAL_AUTO_INCREMENT_ID_CONFIG)
@modelOptions({
schemaOptions: {
versionKey: false,
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
}
}
})
export class Category {
@prop({ unique: true })
id: number
@IsString()
@IsNotEmpty()
@prop({ required: true, validate: /\S+/ })
name: string
@Matches(/^[a-zA-Z0-9-_]+$/)
@MaxLength(30)
@IsString()
@IsNotEmpty({ message: 'slug?' })
@prop({ required: true, validate: /^[a-zA-Z0-9-_]+$/, unique: true })
slug: string
@IsString()
@prop({ default: '' })
description: string
@prop({ ref: Category, default: null })
pid: Types.ObjectId
@prop({ default: Date.now, immutable: true })
created_at?: Date
@prop({ default: Date.now })
updated_at?: Date
@ArrayUnique()
@IsArray()
@prop({ _id: false, default: [], type: () => [KeyValueModel] })
extends: KeyValueModel[]
// for article aggregate
article_count?: number
}
export const CategoryProvider = getProviderByTypegooseClass(Category)