Skip to content

Commit

Permalink
feat: add .env to get api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
huythai855 committed Aug 8, 2023
1 parent e7b9e7e commit 68891e8
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 427 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .env
PROJECT_ID=
CLIENT_EMAIL=
PRIVATE_KEY=
103 changes: 0 additions & 103 deletions rec_from_one.js

This file was deleted.

63 changes: 0 additions & 63 deletions rec_from_one.py

This file was deleted.

80 changes: 0 additions & 80 deletions rec_from_some.js

This file was deleted.

45 changes: 0 additions & 45 deletions rec_from_some.py

This file was deleted.

13 changes: 9 additions & 4 deletions server/big_query_client.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const dotenv = require('dotenv');
const { BigQuery } = require('@google-cloud/bigquery');

// Load environment variables from .env file
dotenv.config();

// Credentials to connect to BigQuery.
const credentials = require('../api_keys/sciplay-5a03294800fe.json');
// const credentials = require('../api_keys/sciplay-5a03294800fe.json');

// Create a BigQuery client
const bigqueryClient = new BigQuery({
projectId: credentials.project_id,
projectId: process.env.PROJECT_ID,
credentials: {
client_email: credentials.client_email,
private_key: credentials.private_key,
client_email: process.env.CLIENT_EMAIL,
private_key: process.env.PRIVATE_KEY,
},
});


module.exports.bigqueryClient = bigqueryClient;
10 changes: 1 addition & 9 deletions server/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ const { getDataFromBigQuery } = require('./big_query/query.js');
const { insertDataToBigQuery } = require('./big_query/insert.js');
const { updateDataInBigQuery } = require('./big_query/update.js');
const { bigqueryClient } = require('./big_query_client.js');
// const { get } = require('mongoose');

// Student informations

async function getStudent(user_id) {
const [rows] = await getDataFromBigQuery(bigqueryClient, {
datasetId: 'sciplay_dataset',
Expand All @@ -13,10 +12,8 @@ async function getStudent(user_id) {
conditions: [`student_id = ${user_id}`],
limit: 1,
});
// console.log(rows);

let name = rows.fullname.split(/\s+/);
console.log(name);
const nameArray = name.slice(-2).join(' ');
name = nameArray
const year = rows.date_of_birth.value.split('-');
Expand Down Expand Up @@ -66,7 +63,6 @@ async function getStudentCourses(user_id) {
conditions: [`student_id=${user_id}`],
limit: 4,
});
// console.log(rows);

for (let i = 0; i < rows.length; i++) {
const { course_id } = rows[i];
Expand All @@ -85,7 +81,6 @@ async function getFinishedCourses(user_id) {
limit: 5,
});

// console.log(rows);
for (let i = 0; i < rows.length; i++) {
const { course_id } = rows[i];
rows[i] = await getCourse(course_id);
Expand Down Expand Up @@ -138,7 +133,6 @@ async function getStudentLessons(user_id) {
conditions: [`student_id=${user_id}`],
limit: 3,
});
// console.log(rows);

// rows = [{lesson_id : '1'}, {lesson_id : '2'}, {lesson_id : '3'}, {lesson_id : '4'}]
for (let i = 0; i < rows.length; i++) {
Expand All @@ -147,7 +141,6 @@ async function getStudentLessons(user_id) {
rows[i] = lesson;
}

// console.log(rows);
return rows;
}
// Lesson inside a topic
Expand Down Expand Up @@ -207,7 +200,6 @@ async function getThread(thread_id){
conditions: [`thread_id = ${thread_id}`],
limit: 1,
});
console.log(row.date_time.value.toString().slice('T'));
const [date, time] = row.date_time.value.slice('-');
row.time = time;
row.date = date;
Expand Down
Loading

0 comments on commit 68891e8

Please sign in to comment.