forked from wangtunan/vue-mooc
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlog.js
42 lines (41 loc) · 849 Bytes
/
log.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
42
import mongoose from 'mongoose'
import logsData from '../initData/log.js'
import { getGuid } from '../../src/utils/utils.js'
const Schema = mongoose.Schema
const LogSchema = new Schema({
id: {
type: String,
required: true,
unique: true,
index: true
},
userid: {
type: String,
required: true
},
type: {
text: String,
code: Number
},
time: {
type: String,
required: true
},
ip: String,
device: String,
city: String
})
const logModel = mongoose.model('log', LogSchema)
// 判断有无数据,没有则初始化
export function initUserLogs (userid) {
logModel.find((err, data) => {
if (!data || data.length === 0) {
logsData.forEach(item => {
item.id = getGuid()
item.userid = userid
logModel.create(item)
})
}
})
}
export default logModel