2019-05-13 20:14:39 +08:00

59 lines
1.3 KiB
JavaScript

'use strict';
import mongoose from 'mongoose';
import dbUtil from '../../utils/db.util';
/**
* 竞猜题库
*/
const Puzzle = new mongoose.Schema({
// 类型, 1: 图片, 2: 音频, 3: 视频, 0: 纯文本
attachtype: {type: Number},
// 图片或者音频的url地址
attach: {type: String},
// 问题
question: {type: String},
// 答案扩展字符
option: {type: String},
// 答案
answer: {type: String},
// 扩展信息, 在猜菜名中, 该字段为菜系
extra: {type: String},
// 提示信息
tip: {type: String},
// 题目分类, food: 菜
type: {type: String},
// 备注
comment: {type: String},
createdBy: {type: String},
deleted: {type: Boolean, default: false},
deletedBy: {type: String},
delete_time: {type: Date},
}, {
collection: 'puzzle',
timestamps: true,
});
const conn = dbUtil.getConnSnoopy();
const PuzzleModel = conn.model('Puzzle', Puzzle);
PuzzleModel.parseReq = (req, record) => {
if (!record) {
record = new PuzzleModel({
createdBy: req.user.id,
});
}
const body = req.body;
record.attachtype = body.attachtype;
record.attach = body.attach;
record.option = body.option;
record.question = body.question;
record.answer = body.answer;
record.extra = body.extra;
record.tip = body.tip;
record.type = body.type;
return record.save();
};
export default PuzzleModel;