mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-29 07:54:19 +00:00
✨ Create a ES6 Condition class for easier Condition creation
This commit is contained in:
parent
e7471a29f4
commit
c167e9c889
1 changed files with 40 additions and 0 deletions
40
code/frontend/src/utils/Condition.js
Normal file
40
code/frontend/src/utils/Condition.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue