-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankSeeder.js
57 lines (49 loc) · 1.52 KB
/
bankSeeder.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
53
54
55
56
57
import fs from 'fs';
import { parse } from 'csv-parse';
import dotenv from 'dotenv';
import Bank from "./models/Bank.js";
import connectDB from "./config/db.js";
dotenv.config();
connectDB();
const filePath = 'data/IFSC.csv';
await Bank.deleteMany();
fs.readFile(filePath, 'utf8', async (err, data) => {
if (err) {
console.error(err);
return;
}
try {
const records = await new Promise((resolve, reject) => {
parse(data, { columns: true }, (err, records) => {
if (err) {
reject(err);
} else {
resolve(records);
}
});
});
// print only first 5 records
records.forEach((record) => {
Bank.create({
name: record.BANK,
ifsc: record.IFSC,
branch: record.BRANCH,
centre: record.CENTRE,
district: record.DISTRICT,
city: record.CITY,
state: record.STATE,
address: record.ADDRESS,
contact: record.CONTACT,
upi: record.UPI === 'true' ? true : false,
rtgs: record.RTGS ? true : false,
neft: record.NEFT ? true : false,
}).then((record) => {
// console.log(record);
}).catch((err) => {
console.error('failed to create record', err);
});
});
} catch (err) {
console.error(err);
}
});