File

lib/core/src/items/entries/entry.class.ts

Extends

Item

Index

Properties
Methods
Accessors

Properties

Public answer
Type : string | number | boolean
Public date
Type : string
Public note
Type : string
Public questionId
Type : string
Public targetDay
Type : string
Private Optional _config
Type : C
Inherited from Item
Defined in Item:54
Public Optional id
Type : string
Inherited from Item
Defined in Item:50
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

Methods

Static acceptsAsConfig
acceptsAsConfig(config)
Inherited from Item
Defined in Item:41
Parameters :
Name Optional
config No
Returns : EntryConfig
Static assertData
assertData(data)
Inherited from Item
Defined in Item:40
Parameters :
Name Optional
data No
Returns : never
Static findConfigs
findConfigs(data)
Inherited from Item
Defined in Item:32
Type parameters :
  • U
Parameters :
Name Optional
data No
Returns : U[]
Public matches
matches(query)
Inherited from Item
Defined in Item:80

TODO: Is this useful or needed anywhere?

Parameters :
Name Optional
query No
Returns : boolean
Public toJSON
toJSON()
Inherited from Item
Defined in Item:75
Returns : string

Accessors

config
getconfig()
setconfig(config: EntryConfig)
Parameters :
Name Type Optional
config EntryConfig No
Returns : void
import	{	Item				}	from '../item.class'

import	{
			assert,
			isErrorFree
		}							from '../../utils'

export type EntryConfig = [
	string,					//Question id
	string|number|boolean,	//Answer 
	string,					//DateTimeString WITH Timezone ISO8601, RFC3339. Log date.
	string?,				//note
	string?,				//Date string. YYYY-MM-DD, TargetDay
]

export function assertEntryConfig(x:unknown) : asserts x is EntryConfig {

	assert(	Array.isArray(x), 												"isEntryConfig() config must be an array.")
	assert(	typeof x[0] == 'string',										"isEntryConfig() [0] must be a string.")
	assert( typeof x[2] == 'string',										"isEntryConfig() [2] must be a string.")
	assert( ['string', 'number', 'boolean'].includes(typeof x[1]),			"isEntryConfig() [1] must be a string|number|boolean.")
	assert( ['string', 'undefined'].includes(typeof x[3]) || x[3] == null,	"isEntryConfig() [3] must be a string|null|undefined.")
	assert( ['string', 'undefined'].includes(typeof x[4]) || x[4] == null,	"isEntryConfig() [4] must be a string|null|undefined.")

}

export function isEntryConfig(x:unknown, throw_errors = false): x is EntryConfig {
	return isErrorFree( () => isEntryConfig(x, true) )
}



export class Entry extends Item<EntryConfig> {

	public 	questionId	: string
	public	answer		: string|number|boolean
	public	date		: string
	public	note		: string
	public 	targetDay	: string //YYYY-MM-DD

	public static acceptsAsConfig(config: unknown): config is EntryConfig {
		return isEntryConfig(config) 
	}

	set config(config: EntryConfig){

		assert( isEntryConfig(config), "Invalid Entry config.")

		this.questionId = config[0]
		this.answer		= config[1]
		this.date		= config[2]
		this.note		= config[3]
		this.targetDay	= config[4]
	}

	get config(): EntryConfig{
		return [this.questionId, this.answer, this.date, this.note, this.targetDay]
	}
}

results matching ""

    No results matching ""