1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

Create a ES6 Condition class for easier Condition creation

This commit is contained in:
Stefano Pigozzi 2021-05-07 03:46:15 +02:00
parent e7471a29f4
commit c167e9c889
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01

View file

@ -0,0 +1,40 @@
import isString from "is-string"
const typeEnums = {
"HASHTAG": 0,
"TIME": 2,
"COORDINATES": 3,
"PLACE": 4,
"USER": 5,
}
/**
* A search/filtering Condition.
*
* See https://gitlab.steffo.eu/nest/g2-progetto/-/wikis/Specifica-delle-Conditions .
*/
export default class Condition {
/**
* Create a new Condition.
*
* @param type - The type of Condition to create.
* It can be a number or one of the following strings:
* `"hashtag"`, `"time"`, `"coordinates"`, `"place"`.
* @param content - The content of the Condition.
* @param id - The id of the Condition on the backend, or null if the Condition hasn't been committed yet.
*/
constructor({type, content, id = null}) {
if(isString(type)) {
this.type = typeEnums[type.toUpperCase()]
}
else {
this.type = type
}
this.content = content
this.id = id
}
}