-
Notifications
You must be signed in to change notification settings - Fork 1
/
getSheetData.js
49 lines (39 loc) · 2.92 KB
/
getSheetData.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
// https://docs.google.com/spreadsheets/d/1fWgSQuMgG0dLg3_Nbp7QHCpu1yrzFhlunGaz0g8t4VU/edit?usp=sharing
const { GoogleSpreadsheet } = require('google-spreadsheet')
require('dotenv').config()
// const config = require('../qna-prodi-d7b8ab0dd396.json')
async function getSheetData(req,res) {
const payload = req.body
console.log(payload);
// const doc = new GoogleSpreadsheet('1SaXnuRt-1KXyDGS18KqU7cus4_IWNxpGhiVy0J1vz-U')
try {
const doc = new GoogleSpreadsheet(payload.id_spreadsheet)
const config = {
client_email: payload.email,
private_key: "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDoj7DNZYOGUa0j\nxlkIu2Y8StDEYplGyezy3qh2fKKNjdVeX+CMCoyGPgzhc1p5Nx8YwDg2/A+p2LW1\nT7VrrzBDZPrRU/TZlEQGkIJshkO+QTdDJyvze/gQX5UvSWLAV0KOUjkFMHAq2jkI\nW43p65TnM/SE4XwuQSB1/bDfZTD0w2OQVR8SR1Vn2enybD5MUWlCaHwiMDIxBoLn\nJEH6HLa/k37QAQH1361vsuc7GdBoE9VT++pkvb4pPTzqVKMnwYUnG+Ge2Ywj7UxY\nNDhtmM/Qb24/4V2Tm4nEPPwfQ1JKWpdwK4fzx/sOYn9URES27h6+f7ISxxPijXZb\ndrT2WDk/AgMBAAECggEAB3x7UYaqCYyJiUmc8MYE5X33DctVaczy6WKM2RDsCVMp\nLNo4l+l4WpNBcOR4uMbdzmXUVBjLHEmTQoc9V35n4ajXgMjgweb0RaMolPvBeddk\nQwTOH7lm491f0l+HY++rKc+wcYqnTF8tT306/+5geGIuGzTy/WjaoFG5UY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l8CsldOKKy6M9pLqmq\n-----END PRIVATE KEY-----\n",
}
await doc.useServiceAccountAuth(config)
await doc.loadInfo()
// const sheet = doc.sheetsByTitle["web"]
const sheet = doc.sheetsByTitle[payload.sheet_title]
console.log(sheet);
const rows = await sheet.getRows()
const dataFinal = rows.map((data,idx)=> {
return {
nama: data.nama,
linkedin: data.linkedin,
instagram: data.instagram,
angkatan_telu: data.angkatan_telu,
angkatan_ai: data.angkatan_ai,
foto_id: data.foto_id
}
})
res.status(200).json({data: dataFinal})
} catch (error) {
console.log(error);
}
// return rows
}
module.exports = {
getSheetData
}