|
1 | 1 | import { Injectable } from "@angular/core";
|
2 | 2 | import { environment } from "environments/environment";
|
| 3 | +import { v4 as uuidv4 } from 'uuid'; |
3 | 4 | @Injectable()
|
4 | 5 | export class HarperDbService {
|
5 |
| - |
| 6 | + private REST_API = 'https://api.flashcoll.com'; |
6 | 7 | private harpedAPI = environment.HARPERDB_API;
|
7 | 8 | myHeaders = new Headers();
|
8 | 9 | userData: any;
|
@@ -40,11 +41,12 @@ export class HarperDbService {
|
40 | 41 |
|
41 | 42 | async generateUserSubprofileIfNotExist(userId: string) {
|
42 | 43 | let userdata: any;
|
43 |
| - await fetch(`https://flashcoll-backend.glitch.me/clerk/user/${userId}`) |
| 44 | + await fetch(`${this.REST_API}/clerk/user/${userId}`) |
44 | 45 | .then(data => {
|
45 | 46 | return userdata = data.json();
|
46 | 47 | }).then(userData => {
|
47 |
| - fetch(`https://flashcoll-backend.glitch.me/github/user/${userData.external_accounts[0].provider_user_id}`) |
| 48 | + console.log(userData); |
| 49 | + fetch(`${this.REST_API}/github/user/${userData.external_accounts[0].provider_user_id}`) |
48 | 50 | .then(response => {
|
49 | 51 | let json = response.json();
|
50 | 52 | json.then(result => {
|
@@ -86,11 +88,24 @@ export class HarperDbService {
|
86 | 88 | return await this.runSQLOnHarperDB(sqlQuery);
|
87 | 89 | }
|
88 | 90 |
|
89 |
| - async createNewProject(userData: any) { |
| 91 | + async createNewProject(userData: any, projectData: any) { |
90 | 92 | const sqlQuery = `INSERT INTO flashcoll.project
|
91 |
| - (id, userProfileID, githubRepoURL) |
92 |
| - VALUE ("${''}")`; |
| 93 | + (id, userProfileID, githubRepoURL, projectTitle, projectShortDescription) |
| 94 | + VALUE ("${uuidv4()}", "${userData.id}", "${projectData.githubRepoURL}", "${projectData.projectTitle}", "${projectData.shortDescription}")`; |
| 95 | + return await this.runSQLOnHarperDB(sqlQuery); |
93 | 96 | }
|
| 97 | + |
| 98 | + async getAllUserProjects(userId: string) { |
| 99 | + const sqlQuery = `SELECT * FROM flashcoll.project where userProfileID = "${userId}"`; |
| 100 | + return await this.runSQLOnHarperDB(sqlQuery); |
| 101 | + } |
| 102 | + |
| 103 | + async getProjectDetails(projectId: string) { |
| 104 | + const sqlQuery = `SELECT * FROM flashcoll.project where id = "${projectId}"`; |
| 105 | + return await this.runSQLOnHarperDB(sqlQuery); |
| 106 | + } |
| 107 | + |
| 108 | + |
94 | 109 | //#endregion
|
95 | 110 |
|
96 | 111 | }
|
0 commit comments