lib/core/src/items/questions/question.class.ts
Properties |
Methods |
|
Accessors |
constructor(idOrConfig: string | QuestionConfig)
|
||||||
Parameters :
|
Public id |
Type : string
|
Inherited from
Item
|
Defined in
Item:50
|
Public max |
Type : number
|
Public meaning |
Type : string
|
Public min |
Type : number
|
Public options |
Type : QuestionOptionConfig[]
|
Public tags |
Type : string[]
|
Public translations |
Type : TranslationList
|
Public type |
Type : string
|
Public unit |
Type : string
|
Private Optional _config |
Type : C
|
Inherited from
Item
|
Defined in
Item:54
|
Public Optional update$ |
Type : Observable<string>
|
Inherited from
Item
|
Defined in
Item:52
|
Protected Optional updateSubject |
Type : Subject<string>
|
Inherited from
Item
|
Defined in
Item:51
|
Static acceptsAsConfig | ||||
acceptsAsConfig(x)
|
||||
Inherited from
Item
|
||||
Defined in
Item:61
|
||||
Parameters :
Returns :
QuestionConfig
|
Public Async validateAnswer | ||||
validateAnswer(value)
|
||||
Parameters :
Returns :
Promise<void>
|
Static assertData | ||||
assertData(data)
|
||||
Inherited from
Item
|
||||
Defined in
Item:40
|
||||
Parameters :
Returns :
never
|
Static findConfigs | ||||
findConfigs(data)
|
||||
Inherited from
Item
|
||||
Defined in
Item:32
|
||||
Type parameters :
|
||||
Parameters :
Returns :
U[]
|
Public matches | ||||
matches(query)
|
||||
Inherited from
Item
|
||||
Defined in
Item:80
|
||||
TODO: Is this useful or needed anywhere?
Parameters :
Returns :
boolean
|
Public toJSON |
toJSON()
|
Inherited from
Item
|
Defined in
Item:75
|
Returns :
string
|
config | ||||||
getconfig()
|
||||||
setconfig(config: QuestionConfig)
|
||||||
Parameters :
Returns :
void
|
import { Item } from "../item.class"
import {
QuestionConfig,
QuestionOptionConfig,
TranslationList,
isQuestionConfig
} from "./questions.commons"
import {
QuestionValidator
} from './question-validator'
import {
assert
} from '../../utils'
export const QuestionProperties = [
'id',
'type',
'meaning',
'translations',
'options',
'min',
'max',
'tags',
'unit',
]
export function unknownConfig(id: string): QuestionConfig {
return {
id: id,
translations: {en: 'Unknown question: #'+id}, //todo use translationService
type: 'unknown',
meaning: 'Missing config for question: #'+id
}
}
export class Question extends Item<QuestionConfig> {
//INSTANCE
declare public id : string
public type : string
public meaning : string
public translations : TranslationList
public options : QuestionOptionConfig[]
public min : number
public max : number
public tags : string[]
public unit : string
public static override acceptsAsConfig(x:unknown): x is QuestionConfig {
return isQuestionConfig(x)
}
constructor(id:string)
constructor(config:QuestionConfig)
constructor(idOrConfig: string | QuestionConfig)
constructor(idOrConfig: string | QuestionConfig){
const config = typeof idOrConfig == 'string'
? unknownConfig(idOrConfig)
: idOrConfig
super(config)
}
override set config(config: QuestionConfig){
assert(Question.acceptsAsConfig(config), "Invalid Question config: "+JSON.stringify(config))
QuestionProperties.forEach( (key:string) => (this as any)[key] = (config as any)[key] )
}
override get config(): QuestionConfig {
const c: any = {}
QuestionProperties.forEach( (key:string) => c[key] = (this as any)[key] )
return (c as QuestionConfig)
}
public async validateAnswer(value:unknown):Promise<void>{
return QuestionValidator.validateAnswer(value, this.config)
}
}