-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.js
52 lines (46 loc) · 996 Bytes
/
schedule.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
43
44
45
46
47
48
49
50
51
52
const {DATABASE_URL, PORT} = require('./config')
const {Users, Entry} = require('./models')
const {addDays, nowDate} = require('./resources/date-module')
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
function deleteExpired(){
let currentDate = nowDate()
Entry
.find({expiry: {$lte: currentDate}})
.exec()
.then(entries => {
entries.forEach(entry => {
let id = entry.id
Entry
.findByIdAndRemove(id)
.exec()
.then(() => {
console.log(`${entry.title} deleted`)
})
})
})
.then(() => {
console.log('All expired entries have been deleted')
})
}
function removeDemo(){
Users
.find({status: 'demo'})
.exec()
.then(demos => {
demos.forEach(demo => {
let id = demo.id
Users
.findByIdAndRemove(id)
.exec()
.then(() => {
console.log('demo profile deleted')
})
})
})
.then(() => {
console.log('All demo profiles have been deleted')
})
}
deleteExpired()
removeDemo()