total_1ère
This commit is contained in:
97
controllers/concert_annuel/maj_gs_concertController.js
Normal file
97
controllers/concert_annuel/maj_gs_concertController.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/////////////////////////////////////////////////
|
||||
// LOGGING
|
||||
/////////////////////////////////////////////////
|
||||
const logger = require("../../public/js/app/logger_concert");
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// APPELS DES MODULES
|
||||
/////////////////////////////////////////////////
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
// CALCUL DE DATE
|
||||
const moment = require('moment');
|
||||
// ENVOIE MAIL GOOGLE MAIL
|
||||
const nodemailer = require('nodemailer');
|
||||
// CONNECTION BASE DE DONNÉES
|
||||
const mysql = require('mysql2');
|
||||
const mysql_promise = require('mysql2/promise');
|
||||
|
||||
// ADOBE PDF
|
||||
const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// APPELS DES FONCTIONS
|
||||
/////////////////////////////////////////////////
|
||||
const sleep = require("./../../modules/sleep");
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// FILE NAME
|
||||
////////////////////////////////////////////////////
|
||||
const filename = path.parse(__filename).base;
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// CONNECTION DB
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// GOOGLE SHEET PARAMETERS
|
||||
/////////////////////////////////////////////////
|
||||
const { GoogleSpreadsheet } = require('google-spreadsheet');
|
||||
const GS_creds = require('../../inscriptionsafps-53b60452f63d.json');
|
||||
const { error } = require("console");
|
||||
// Fichier Google Sheet "afps_concert_annuel" (Mon Drive/inscriptions/base_donees)
|
||||
// doc ID is the long id in the sheets URL
|
||||
const GS_concert = new GoogleSpreadsheet(process.env.gsheet_concertannuel);
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// ENVOIE DES INFOS DANS LA GOOGLESHEET
|
||||
/////////////////////////////////////////////////
|
||||
const recup_gs = async function(req, res) {
|
||||
logger.info("======================================", { label: filename });
|
||||
logger.info("======== FUNCTION recup_gs ==========", { label: filename });
|
||||
logger.info("======================================", { label: filename });
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// CONNEXION GSHEET
|
||||
|
||||
try {
|
||||
await GS_concert.useServiceAccountAuth(GS_creds);
|
||||
await GS_concert.loadInfo();
|
||||
const GS_concert_adherent = GS_concert.sheetsByTitle['adherents'];
|
||||
|
||||
const ajout_gs_adherent = await GS_concert_adherent.addRows(
|
||||
[
|
||||
{
|
||||
saison: "tutu"
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
await sleep.wait(5000);
|
||||
|
||||
req.session.message = "fonction terminée";
|
||||
res.redirect('/concert/maj_googlesheet');
|
||||
|
||||
} catch (error) {
|
||||
// Echec de connection à la GOOGLE SHEET
|
||||
logger.error("Il y a un problème avec la connection à Google sheet : " + error, { numsession: req.session.id });
|
||||
req.session.message = "Il y a un problème système avec la Google Sheet, veuillez recommencer.";
|
||||
|
||||
res.redirect('/concert/maj_googlesheet');
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// EXPORT DES MODULES POUR QU'ILS PUISSENT LUS PAR LES AUTRES FICHIERS JS
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
module.exports = {
|
||||
recup_gs
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user