src/modules/tag/tag.model.ts
Properties |
|
Optional article_count |
Type : number
|
Defined in src/modules/tag/tag.model.ts:58
|
Optional created_at |
Type : Date
|
Decorators :
@prop({default: undefined, immutable: true})
|
Defined in src/modules/tag/tag.model.ts:47
|
description |
Type : string
|
Decorators :
@IsString()
|
Defined in src/modules/tag/tag.model.ts:44
|
extends |
Type : KeyValueModel[]
|
Decorators :
@IsArray()
|
Defined in src/modules/tag/tag.model.ts:55
|
id |
Type : number
|
Decorators :
@prop({unique: true})
|
Defined in src/modules/tag/tag.model.ts:28
|
name |
Type : string
|
Decorators :
@IsNotEmpty()
|
Defined in src/modules/tag/tag.model.ts:33
|
slug |
Type : string
|
Decorators :
@Matches(/^[a-zA-Z0-9-_]+$/)
|
Defined in src/modules/tag/tag.model.ts:40
|
Optional updated_at |
Type : Date
|
Decorators :
@prop({default: undefined})
|
Defined in src/modules/tag/tag.model.ts:50
|
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 Tag {
@prop({ unique: true })
id: number
@IsNotEmpty()
@IsString()
@prop({ required: true, validate: /\S+/ })
name: string
@Matches(/^[a-zA-Z0-9-_]+$/)
@IsNotEmpty()
@IsString()
@MaxLength(30)
@prop({ required: true, validate: /^[a-zA-Z0-9-_]+$/, unique: true })
slug: string
@IsString()
@prop({ default: '' })
description: string
@prop({ default: Date.now, immutable: true })
created_at?: Date
@prop({ default: Date.now })
updated_at?: Date
@IsArray()
@ArrayUnique()
@prop({ _id: false, default: [], type: () => [KeyValueModel] })
extends: KeyValueModel[]
// for article aggregate
article_count?: number
}
export const TagProvider = getProviderByTypegooseClass(Tag)