-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean.ts
39 lines (34 loc) · 956 Bytes
/
clean.ts
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
require('dotenv-safe').config();
import initMongo from './config/mongo';
import { CallbackError, Model } from 'mongoose';
import city from './app/models/city';
import user from './app/models/user';
import forgotPassword from './app/models/forgotPassword';
import userAccess from './app/models/userAccess';
initMongo();
const models: Model<any>[] = [city, user, forgotPassword, userAccess];
const deleteModelFromDB = (model: Model<any>): Promise<void> => {
return new Promise((resolve, reject) => {
model.deleteMany((err: CallbackError) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
};
const clean = async () => {
try {
const promiseArray = models.map(
async (model) => await deleteModelFromDB(model)
);
await Promise.all(promiseArray);
console.log('Cleanup complete!');
process.exit(0);
} catch (err) {
console.log(err);
process.exit(0);
}
};
clean();