-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdesigners.js
51 lines (45 loc) · 1.43 KB
/
designers.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
import { google } from "googleapis";
export default async (req, res) => {
try {
const auth = new google.auth.GoogleAuth({
credentials: {
client_email: process.env.GOOGLE_CLIENT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY,
},
scopes: [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/spreadsheets",
],
});
const sheets = google.sheets({
auth,
version: "v4",
});
// Replace the spreadsheetId with your spreadsheet ID.
// Replace the range with the tab name.
// Issues with permissions look at this guide: https://leerob.io/snippets/google-sheets
const response = await sheets.spreadsheets.values.get({
spreadsheetId: "12LLA-NoHin0zQfmpEblgMjd260bmriLMowBAH1QDOhI",
range: "Designers", // sheet name
});
//TODO: Map the collum to object name automatically.
const rows = response.data.values;
const db = rows.map((row) => ({
name: row[0],
location: row[1],
expertise: row[2],
link: row[3],
approved: row[4],
featured: row[5],
}));
let sanitizeResult = db.filter(
(item) => item.name != "" && item.approved == "Yes"
);
res.statusCode = 200;
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(sanitizeResult));
} catch (err) {
console.log(err);
}
};