Commit 0c11f675 authored by Gilles Mouchard's avatar Gilles Mouchard
Browse files

Added abbreviated output for GET endpoints returning projects (in this mode...

Added abbreviated output for GET endpoints returning projects (in this mode only name and members are returned).
parent a31123c1
Pipeline #19519 passed with stages
in 9 minutes and 57 seconds
......@@ -17691,6 +17691,12 @@ paths:
required: true
schema:
type: string
- name: abbrev
description: toggle abbreviated response (with only project name and members)/full response, useful for lowering response footprint
in: query
schema:
type: boolean
default: false
- $ref: '#/components/parameters/keyParam'
responses:
200:
......@@ -17757,6 +17763,12 @@ paths:
required: true
schema:
type: string
- name: abbrev
description: toggle abbreviated response (with only project name and members)/full response, useful for lowering response footprint
in: query
schema:
type: boolean
default: false
- $ref: '#/components/parameters/keyParam'
responses:
200:
......@@ -18099,6 +18111,12 @@ paths:
operationId: getProjects
description: Get all projects
parameters:
- name: abbrev
description: toggle abbreviated response (with only project name and members)/full response, useful for lowering response footprint
in: query
schema:
type: boolean
default: false
- $ref: '#/components/parameters/keyParam'
responses:
200:
......@@ -18173,6 +18191,12 @@ paths:
required: true
schema:
type: string
- name: abbrev
description: toggle abbreviated response (with only project name and members)/full response, useful for lowering response footprint
in: query
schema:
type: boolean
default: false
- $ref: '#/components/parameters/keyParam'
responses:
200:
......
......@@ -16,16 +16,22 @@
* along with PKM. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetProjectOptions
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get a project
*
* @memberof PKM
* @instance
* @param {string} project_name - project name
* @param {GetProjectOptions} [options] - options
*
* @return {Promise.<PkmProject>} a promise
*/
function get_project(project_name)
function get_project(project_name, options = {})
{
return new Promise(function(resolve, reject)
{
......@@ -39,7 +45,7 @@ function get_project(project_name)
this.get_documents(this.config.pkm_db, 'Projects', { name : project_name }).then(() =>
{
// retrieve project informations
this.get_documents(project_name, 'Project').then((documents) =>
(options.abbrev ? Promise.resolve([ { name : project_name } ]) : this.get_documents(project_name, 'Project')).then((documents) =>
{
if(documents.length)
{
......@@ -86,35 +92,38 @@ function get_project(project_name)
{
let promises = [];
// get some project metadata from collections
let project_metadata = Object.keys(this.config.project);
project_metadata.forEach((metadata) =>
if(!options.abbrev)
{
const get = this.config.project[metadata].get;
if((typeof get === 'string') && (typeof this[get] === 'function'))
// get some project metadata from collections
let project_metadata = Object.keys(this.config.project);
project_metadata.forEach((metadata) =>
{
promises.push(new Promise((resolve, reject) =>
const get = this.config.project[metadata].get;
if((typeof get === 'string') && (typeof this[get] === 'function'))
{
this[get](project.name).then((metadata_value) =>
{
// add metadata to the project
project[metadata] = metadata_value;
resolve();
}).catch((err) =>
promises.push(new Promise((resolve, reject) =>
{
const error = require('./error');
if(err instanceof error.PKM_NotFound)
this[get](project.name).then((metadata_value) =>
{
// add metadata to the project
project[metadata] = metadata_value;
resolve();
}
else
}).catch((err) =>
{
reject(this.Error(err));
}
});
}));
}
});
const error = require('./error');
if(err instanceof error.PKM_NotFound)
{
resolve();
}
else
{
reject(this.Error(err));
}
});
}));
}
});
}
return Promise.all(promises);
}).then(() =>
......
......@@ -16,15 +16,22 @@
* along with PKM. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetProjectsOptions
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get projects
*
* @memberof PKM
* @instance
*
* @param {GetProjectsOptions} [options] - options
*
* @return {Promise.<Array.<PkmProject>>} a promise
*/
function get_projects()
function get_projects(options = {})
{
return new Promise(function(resolve, reject)
{
......@@ -47,7 +54,7 @@ function get_projects()
if(user.has_role(project_name) || user.is_admin())
{
// user has a role in the project or it is an administrator: retrieve the project information
this.get_project(project_name).then((project) =>
this.get_project(project_name, options).then((project) =>
{
resolve(project);
}).catch((err) =>
......
......@@ -16,23 +16,29 @@
* along with PKM. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetUserProjectsOptions
* @property {string} [project_name] - project name
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get user's projects
*
* @memberof PKM
* @instance
* @param {PkmUser} user - a user
* @param {string} [project_name] - project name
* @param {GetUserProjectsOptions} [options] - options
*
* @return {Promise.<Array.<PkmProject>>} a promise
*/
function get_user_projects(user, project_name)
function get_user_projects(user, options = {})
{
return new Promise(function(resolve, reject)
{
const debug = this.debug;
if(project_name === undefined)
if(options.project_name === undefined)
{
// get all user's projects
......@@ -52,10 +58,10 @@ function get_user_projects(user, project_name)
}
else
{
if(user.has_role(project_name))
if(user.has_role(options.project_name))
{
// get project
this.get_project(project_name).then((project) =>
this.get_project(options.project_name).then((project) =>
{
resolve([ project ]);
}).catch((err) =>
......
......@@ -23904,7 +23904,7 @@
 
<h4 class="name" id="get_project"><span class="type-signature"></span>get_project<span class="signature">(project_name)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="global.html#PkmProject">PkmProject</a>>}</span></h4>
<h4 class="name" id="get_project"><span class="type-signature"></span>get_project<span class="signature">(project_name, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="global.html#PkmProject">PkmProject</a>>}</span></h4>
 
......@@ -23936,6 +23936,8 @@
<th>Type</th>
 
<th>Attributes</th>
 
 
......@@ -23961,6 +23963,14 @@
</td>
 
<td class="attributes">
</td>
 
 
......@@ -23968,6 +23978,39 @@
</tr>
 
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type"><a href="global.html#GetProjectOptions">GetProjectOptions</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">options</td>
</tr>
</tbody>
</table>
 
......@@ -24005,7 +24048,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_get_project.js.html">core/get_project.js</a>, <a href="core_get_project.js.html#line28">line 28</a>
<a href="core_get_project.js.html">core/get_project.js</a>, <a href="core_get_project.js.html#line34">line 34</a>
</li></ul></dd>
 
......@@ -24063,7 +24106,7 @@
 
<h4 class="name" id="get_projects"><span class="type-signature"></span>get_projects<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#PkmProject">PkmProject</a>>>}</span></h4>
<h4 class="name" id="get_projects"><span class="type-signature"></span>get_projects<span class="signature">(options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#PkmProject">PkmProject</a>>>}</span></h4>
 
......@@ -24082,6 +24125,67 @@
 
 
 
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type"><a href="global.html#GetProjectsOptions">GetProjectsOptions</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">options</td>
</tr>
</tbody>
</table>
 
 
 
......@@ -24115,7 +24219,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_get_projects.js.html">core/get_projects.js</a>, <a href="core_get_projects.js.html#line27">line 27</a>
<a href="core_get_projects.js.html">core/get_projects.js</a>, <a href="core_get_projects.js.html#line34">line 34</a>
</li></ul></dd>
 
......@@ -27568,7 +27672,7 @@
 
<h4 class="name" id="get_user_projects"><span class="type-signature"></span>get_user_projects<span class="signature">(user, project_name<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#PkmProject">PkmProject</a>>>}</span></h4>
<h4 class="name" id="get_user_projects"><span class="type-signature"></span>get_user_projects<span class="signature">(user, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;Array.&lt;<a href="global.html#PkmProject">PkmProject</a>>>}</span></h4>
 
......@@ -27645,13 +27749,13 @@
 
<tr>
<td class="name"><code>project_name</code></td>
<td class="name"><code>options</code></td>
 
<td class="type">
<span class="param-type">string</span>
<span class="param-type"><a href="global.html#GetUserProjectsOptions">GetUserProjectsOptions</a></span>
 
 
......@@ -27671,7 +27775,7 @@
 
 
<td class="description last">project name</td>
<td class="description last">options</td>
</tr>
 
......@@ -27712,7 +27816,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_get_user_projects.js.html">core/get_user_projects.js</a>, <a href="core_get_user_projects.js.html#line29">line 29</a>
<a href="core_get_user_projects.js.html">core/get_user_projects.js</a>, <a href="core_get_user_projects.js.html#line35">line 35</a>
</li></ul></dd>
 
......
......@@ -44,16 +44,22 @@
* along with PKM. If not, see &lt;https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetProjectOptions
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get a project
*
* @memberof PKM
* @instance
* @param {string} project_name - project name
* @param {GetProjectOptions} [options] - options
*
* @return {Promise.&lt;PkmProject>} a promise
*/
function get_project(project_name)
function get_project(project_name, options = {})
{
return new Promise(function(resolve, reject)
{
......@@ -67,7 +73,7 @@ function get_project(project_name)
this.get_documents(this.config.pkm_db, 'Projects', { name : project_name }).then(() =>
{
// retrieve project informations
this.get_documents(project_name, 'Project').then((documents) =>
(options.abbrev ? Promise.resolve([ { name : project_name } ]) : this.get_documents(project_name, 'Project')).then((documents) =>
{
if(documents.length)
{
......@@ -114,35 +120,38 @@ function get_project(project_name)
{
let promises = [];
// get some project metadata from collections
let project_metadata = Object.keys(this.config.project);
project_metadata.forEach((metadata) =>
if(!options.abbrev)
{
const get = this.config.project[metadata].get;
if((typeof get === 'string') &amp;&amp; (typeof this[get] === 'function'))
// get some project metadata from collections
let project_metadata = Object.keys(this.config.project);
project_metadata.forEach((metadata) =>
{
promises.push(new Promise((resolve, reject) =>
const get = this.config.project[metadata].get;
if((typeof get === 'string') &amp;&amp; (typeof this[get] === 'function'))
{
this[get](project.name).then((metadata_value) =>
{
// add metadata to the project
project[metadata] = metadata_value;
resolve();
}).catch((err) =>
promises.push(new Promise((resolve, reject) =>
{
const error = require('./error');
if(err instanceof error.PKM_NotFound)
this[get](project.name).then((metadata_value) =>
{
// add metadata to the project
project[metadata] = metadata_value;
resolve();
}
else
}).catch((err) =>
{
reject(this.Error(err));
}
});
}));
}
});
const error = require('./error');
if(err instanceof error.PKM_NotFound)
{
resolve();
}
else
{
reject(this.Error(err));
}
});
}));
}
});
}
return Promise.all(promises);
}).then(() =>
......
......@@ -44,15 +44,22 @@
* along with PKM. If not, see &lt;https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetProjectsOptions
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get projects
*
* @memberof PKM
* @instance
*
* @param {GetProjectsOptions} [options] - options
*
* @return {Promise.&lt;Array.&lt;PkmProject>>} a promise
*/
function get_projects()
function get_projects(options = {})
{
return new Promise(function(resolve, reject)
{
......@@ -75,7 +82,7 @@ function get_projects()
if(user.has_role(project_name) || user.is_admin())
{
// user has a role in the project or it is an administrator: retrieve the project information
this.get_project(project_name).then((project) =>
this.get_project(project_name, options).then((project) =>
{
resolve(project);
}).catch((err) =>
......
......@@ -44,23 +44,29 @@
* along with PKM. If not, see &lt;https://www.gnu.org/licenses/>.
*/
/**
* @typedef {Object} GetUserProjectsOptions
* @property {string} [project_name] - project name
* @property {boolean} [abbrev] - enable/disable project metadata
*/
/**
* Get user's projects
*
* @memberof PKM
* @instance
* @param {PkmUser} user - a user
* @param {string} [project_name] - project name
* @param {GetUserProjectsOptions} [options] - options
*
* @return {Promise.&lt;Array.&lt;PkmProject>>} a promise
*/
function get_user_projects(user, project_name)
function get_user_projects(user, options = {})
{
return new Promise(function(resolve, reject)
{
const debug = this.debug;
if(project_name === undefined)
if(options.project_name === undefined)
{
// get all user's projects
......@@ -80,10 +86,10 @@ function get_user_projects(user, project_name)
}
else
{
if(user.has_role(project_name))
if(user.has_role(options.project_name))
{
// get project
this.get_project(project_name).then((project) =>
this.get_project(options.project_name).then((project) =>
{
resolve([ project ]);
}).catch((err) =>
......
......@@ -11862,6 +11862,427 @@
<h4 class="name" id="GetProjectOptions">GetProjectOptions</h4>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h5 class="subsection-title">Properties:</h5>