forked from wangtunan/vue-mooc
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnotice.js
38 lines (36 loc) · 779 Bytes
/
notice.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
import mongoose from 'mongoose'
import noticeData from '../initData/notice.js'
import { getGuid } from '../../src/utils/utils.js'
const Schema = mongoose.Schema
const NoticeSchema = new Schema({
id: {
type: String,
required: true,
unique: true,
index: true
},
code: {
type: Number,
enum: [1, 2],
required: true
},
time: {
type: String,
required: true
},
title: {
type: String,
required: true
}
})
const noticeModel = mongoose.model('notice', NoticeSchema)
// 判断有无数据,没有则初始化
noticeModel.find((err, data) => {
if (!data || data.length === 0) {
noticeData.forEach((item, index) => {
item.id = getGuid() + index
noticeModel.create(item)
})
}
})
export default noticeModel