@@ -20,7 +20,9 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
20
20
21
21
/**
22
22
* Constructor for Projects API client.
23
+ * @param {SqlApiClient } sqlClient - SQL API client to send all SQL query requests.
23
24
* @param {Axios } client - Axios instance to send all HTTP requests.
25
+ * @param {HttpAuthenticator } authenticator - Authenticator to use for reauthenticate if needed.
24
26
*/
25
27
constructor (
26
28
sqlClient : SqlApiClient ,
@@ -42,6 +44,7 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
42
44
43
45
/**
44
46
* Gets all MindsDB projects for the current user.
47
+ *
45
48
* @returns {Promise<Array<Project>> } - All projects.
46
49
* @throws {MindsDbError } - Something went wrong fetching projects.
47
50
*/
@@ -56,15 +59,42 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
56
59
if ( ! projectsResponse . data ) {
57
60
return [ ] ;
58
61
}
59
- return projectsResponse . data ;
62
+
63
+ const projects = projectsResponse . data . map ( ( project : any ) => {
64
+ return new Project ( this , project . name ) ;
65
+ } ) ;
66
+
67
+ return projects ;
60
68
} catch ( error ) {
61
69
throw MindsDbError . fromHttpError ( error , projectsUrl ) ;
62
70
}
63
71
}
64
72
65
73
/**
74
+ * Gets a MindsDB project by name.
66
75
*
67
- * @param name - Name of the project to create.
76
+ * @param {string } name - Name of the project to get.
77
+ * @returns {Promise<Project> } - The project.
78
+ */
79
+ override async getProject ( name : string ) : Promise < Project > {
80
+ const projectsUrl = this . getProjectsUrl ( ) + `/${ name } ` ;
81
+ const { authenticator, client } = this ;
82
+
83
+ const projectResponse = await client . get (
84
+ projectsUrl ,
85
+ getBaseRequestConfig ( authenticator )
86
+ ) ;
87
+ if ( ! projectResponse . data ) {
88
+ throw new MindsDbError ( 'Project not found' ) ;
89
+ }
90
+
91
+ return new Project ( this , projectResponse . data . name ) ;
92
+ }
93
+
94
+ /**
95
+ * Creates a new MindsDB project.
96
+ *
97
+ * @param {string } name - Name of the project to create.
68
98
* @returns {Promise<Project> } - The created project.
69
99
*/
70
100
override async createProject ( name : string ) : Promise < Project > {
@@ -79,6 +109,7 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
79
109
}
80
110
81
111
/**
112
+ * Delete a MindsDB project by name.
82
113
*
83
114
* @param {string } name - Name of the project to delete.
84
115
*/
@@ -90,5 +121,4 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
90
121
throw new MindsDbError ( sqlQueryResult . error_message ) ;
91
122
}
92
123
}
93
-
94
124
}
0 commit comments