File

src/modules/category/category.model.ts

Index

Properties

Properties

Optional article_count
Type : number
Optional created_at
Type : Date
Decorators :
@prop({default: undefined, immutable: true})
description
Type : string
Decorators :
@IsString()
@prop({default: ''})
extends
Type : KeyValueModel[]
Decorators :
@ArrayUnique()
@IsArray()
@prop({_id: false, default: undefined, type: () => })
id
Type : number
Decorators :
@prop({unique: true})
name
Type : string
Decorators :
@IsString()
@IsNotEmpty()
@prop({required: true, validate: /\S+/})
pid
Type : Types.ObjectId
Decorators :
@prop({ref: Category, default: undefined})
slug
Type : string
Decorators :
@Matches(/^[a-zA-Z0-9-_]+$/)
@MaxLength(30)
@IsString()
@IsNotEmpty({message: 'slug?'})
@prop({required: true, validate: /^[a-zA-Z0-9-_]+$/, unique: true})
Optional updated_at
Type : Date
Decorators :
@prop({default: undefined})
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)

results matching ""

    No results matching ""