{"size": 1937, "ext": "js", "max_stars_repo_path": "helpers/csv-writer.js", "max_stars_repo_name": "pruthvi145/eventomatic-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "helpers/csv-writer.js", "max_issues_repo_name": "pruthvi145/eventomatic-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "helpers/csv-writer.js", "max_forks_repo_name": "pruthvi145/eventomatic-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.9824561404, "max_line_length": 90, "alphanum_fraction": 0.4697986577}
const csv = require('csv-parser');
const fs = require('fs');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
var newLine = "\r\n";
var methods = {};

methods.CreateCSV = async function (data, filename) {
    let today = new Date();
    let date = today.getDate() + '-' + (today.getMonth() + 1) + '-' + today.getFullYear();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date + ' ' + time;
    let path = `./data/${date}_${filename}.csv`;
    const records = [
        {
            event: data['payment']['link_title'],
            payment_id: data['payment']['payment_id'],
            name: data['payment']['buyer_name'],
            email: data['payment']['buyer_email'],
            check_in: dateTime,
        },
    ];
    if (!fs.existsSync(path)) {
        const csvWriter = createCsvWriter({
            path: path,
            header: [
                {id: 'event', title: 'EVENT'},
                {id: 'payment_id', title: 'PAYMENT ID'},
                {id: 'name', title: 'NAME'},
                {id: 'email', title: 'EMAIL'},
                {id: 'check_in', title: 'DATE TIME'}
            ]
        });

        csvWriter.writeRecords(records)       // returns a promise
            .then(() => {
                console.log('...Done');
            });
    } else {
        const csvWriter = createCsvWriter({
            path: path,
            append: true,
            header: [
                {id: 'event', title: 'EVENT'},
                {id: 'payment_id', title: 'PAYMENT ID'},
                {id: 'name', title: 'NAME'},
                {id: 'email', title: 'EMAIL'},
                {id: 'check_in', title: 'CHECK IN'}
            ]
        });
        csvWriter.writeRecords(records)       // returns a promise
            .then(() => {
                console.log('...Done');
            });
    }
};

exports.data = methods;