mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-21 17:15:17 +00:00
Can refresh conversation messages
This commit is contained in:
@ -103,9 +103,10 @@ export class RequestHandler {
|
||||
* Get a list of integeres included in the request
|
||||
*
|
||||
* @param name The name of the post field
|
||||
* @param minEntries Specify the minimum number of entries required
|
||||
*/
|
||||
public postNumbersList(name: string) : Array<number> {
|
||||
const param = this.postString(name);
|
||||
public postNumbersList(name: string, minEntries : number = 1) : Array<number> {
|
||||
const param = this.postString(name, minEntries < 1 ? 0 : minEntries, minEntries > 0);
|
||||
let list = [];
|
||||
for (const el of param.split(",")) {
|
||||
|
||||
@ -119,6 +120,9 @@ export class RequestHandler {
|
||||
|
||||
}
|
||||
|
||||
if(list.length < minEntries)
|
||||
this.error(400, "Not enough entries in '" + name + "'!")
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -126,9 +130,29 @@ export class RequestHandler {
|
||||
* Turn a list of string into a Set object
|
||||
*
|
||||
* @param name Name of POST field
|
||||
* @param minEntries Minimum number of entries to specify
|
||||
*/
|
||||
public postNumbersSet(name : string) : Set<number> {
|
||||
return new Set(this.postNumbersList(name));
|
||||
public postNumbersSet(name : string, minEntries : number = 1) : Set<number> {
|
||||
return new Set(this.postNumbersList(name, minEntries));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to decode JSON included in a POST request
|
||||
*
|
||||
* @param name Name of POST field
|
||||
*/
|
||||
public postJSON(name: string) : any {
|
||||
const src = this.getPostParam(name);
|
||||
|
||||
if(src == undefined)
|
||||
this.error(400, "Missing JSON '" + name + "' in the request!");
|
||||
|
||||
try {
|
||||
const response = JSON.parse(src);
|
||||
return response;
|
||||
} catch(e) {
|
||||
this.error(500, "'" + name + "' is not a valid JSON !");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user