forked from wangtunan/vue-mooc
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathintegral.js
41 lines (39 loc) · 815 Bytes
/
integral.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import mongoose from 'mongoose'
import integralData from '../initData/integral.js'
import { getGuid } from '../../src/utils/utils.js'
const Schema = mongoose.Schema
const IntegralSchema = new Schema({
id: {
type: String,
required: true,
unique: true,
index: true
},
img: {
type: String,
required: true
},
title: {
type: String,
required: true,
},
integral: {
type: Number,
default: 0
},
type: {
type: String,
required: true
}
})
const integralModel = mongoose.model('integral', IntegralSchema)
// 判断有无数据,没有则初始化
integralModel.find((err, data) => {
if(!data || data.length === 0) {
integralData.forEach(item => {
item.id = getGuid()
integralModel.create(item)
})
}
})
export default integralModel