-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoSelectGroup.js
More file actions
120 lines (107 loc) · 2.82 KB
/
mongoSelectGroup.js
File metadata and controls
120 lines (107 loc) · 2.82 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
let _ = require('lodash')
let Joi = require('joi')
const moment = require('moment-timezone')
const mongo = require('@nurigo/mongo')
const keygen = require('keygenerator')
const { Group, Message } = require('./models')
async function funA() {
const groupId = createGroupId()
let id = createMessageId()
let messages = [
{
"_id": id,
"messageId": id,
accountId: '214727',
groupId,
"to": "01090683469",
"from": "029302266",
"text": "test",
"type": "LMS",
"schuledDate": "2018-09-20 13:40:13",
"subject": "TEST",
"kakaoOptions": {
"senderKey": "test",
"templateCode": "test",
"buttonName": "test",
"buttonUrl": "test",
"disableSms": "true"
},
"statusCode": "4000"
}
]
let groups = [
{
"_id": groupId,
groupId,
apiVersion: '4',
accountId: '214727',
status: "SENDING"
}
]
for (let i = 0; i < 50; i++) {
let id = createMessageId()
let groupId = createGroupId()
messages.push(Object.assign({}, messages[0], { "_id": id, "messageId": id, groupId, replacement: true }))
groups.push(Object.assign({}, groups[0], { "_id": groupId, groupId }))
}
for (let i = 0; i < 20; i++) {
let id = createMessageId()
let groupId = createGroupId()
messages.push(Object.assign({}, messages[0], { "_id": id, "messageId": id, groupId}))
groups.push(Object.assign({}, groups[0], { "_id": groupId, groupId, isRefunded: true }))
}
/*
// let groupList = await Group.find({status: 'SENDING'})
groups.forEach((value) => {
let id = createMessageId()
messages.push(Object.assign({}, messages[0], { "groupId": groups[0].groupId, "_id": id, "messageId": id }))
})
*/
try {
await Group.insertMany(groups)
await Message.insertMany(messages)
} catch(err) {
console.log('check err', err)
}
}
const createMessageId = () => {
// M = MessageID, 4 = Value of Version, V = Version
return 'M4V' +
moment.tz('Asia/Seoul').format('YYYYMMDDHHmmss') +
keygen._({
length: 15,
forceUppercase: true
})
}
const createGroupId = () => {
// M = MessageID, 4 = Value of Version, V = Version
return 'G4V' +
moment.tz('Asia/Seoul').format('YYYYMMDDHHmmss') +
keygen._({
length: 15,
forceUppercase: true
})
}
async function A() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('SETTIMEOUT')
return resolve()
}, 3000)
})
}
async function funB() {
try {
await mongo.init({'host':'localhost', "database": "msgv4"})
console.log('Start')
await Group.remove()
await Message.remove()
await funA()
console.log('Success')
mongo.mongoose.connection.close()
} catch (ERR) {
console.log('check ERR', ERR)
mongo.mongoose.connection.close()
}
}
funB()