78 lines
1.7 KiB
TypeScript
78 lines
1.7 KiB
TypeScript
import { dbconn } from '../../decorators/dbconn'
|
|
import {
|
|
getModelForClass,
|
|
modelOptions,
|
|
prop,
|
|
ReturnModelType
|
|
} from '@typegoose/typegoose'
|
|
import { BaseModule } from '../Base'
|
|
import { noJson } from '../../decorators/nojson'
|
|
|
|
@dbconn('second')
|
|
@modelOptions({ schemaOptions: { collection: 'question' } })
|
|
class PuzzleClass extends BaseModule {
|
|
@prop()
|
|
public question: string
|
|
|
|
@prop()
|
|
public a1: string
|
|
@prop()
|
|
public a2: string
|
|
@prop()
|
|
public a3: string
|
|
@prop()
|
|
public a4: string
|
|
|
|
@prop()
|
|
public quality: number
|
|
|
|
/**
|
|
* 是否删除
|
|
* @type {boolean}
|
|
*/
|
|
@noJson()
|
|
@prop({default: 0})
|
|
public deleted: number
|
|
|
|
@noJson()
|
|
@prop()
|
|
public is_hide: number
|
|
/**
|
|
* 这个是tag
|
|
* @type {string}
|
|
*/
|
|
|
|
@prop({ type: () => [String] })
|
|
public groups: string[]
|
|
|
|
@prop()
|
|
public tag: string
|
|
|
|
@prop()
|
|
public subtag: string
|
|
|
|
public static parseQueryParam(params) {
|
|
let {key, timeBegin, timeEnd } = params
|
|
let opt: any = {deleted: 0, is_hide: 0}
|
|
if (key) {
|
|
opt.question = {$regex: key, $options: 'i'}
|
|
}
|
|
if (timeBegin && !timeEnd) {
|
|
opt.createtime = {$gte: timeBegin};
|
|
} else if (timeBegin && timeEnd) {
|
|
opt['$and'] = [{createtime: {$gte: timeBegin}}, {createtime: {$lte: timeEnd}}];
|
|
} else if (!timeBegin && timeEnd) {
|
|
opt.createtime = {$lte: timeEnd};
|
|
}
|
|
|
|
let sort = {_id: 1}
|
|
return { opt, sort }
|
|
}
|
|
|
|
public static async nextQuestion(this: ReturnModelType<typeof PuzzleClass>, id: string) {
|
|
return this.findOne({deleted: 0, is_hide: 0, _id: {$gt: id }}).exec()
|
|
}
|
|
}
|
|
|
|
export const Puzzle = getModelForClass(PuzzleClass, { existingConnection: PuzzleClass.db })
|