import { IsEnum , IsNotEmpty , IsNotEmptyObject , IsObject , IsString , } from 'class-validator' ; import { firestore } from 'firebase' ; export enum QuestionnaireType { pin = 'pin' , cav = 'cav' , org = 'org' , team = 'team' } export interface IQuestionnaire extends firebase . firestore . DocumentData { parentRef : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > ; data : { [ key ] : any ; } ; type : QuestionnaireType ; version : string ; createdAt ? : firebase . firestore . Timestamp ; } export class Questionnaire implements IQuestionnaire { constructor ( parentRef , data , type , version , createdAt = firestore . Timestamp . now ( ) ) { this . _parentRef = parentRef ; this . _data = data ; this . _type = type ; this . _version = version ; this . _createdAt = createdAt ; } @ IsNotEmptyObject ( ) private _parentRef : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > ; get parentRef ( ) : firebase . firestore . DocumentReference < firebase . firestore . DocumentData > { return this . _parentRef ; } set parentRef ( value ) { this . _parentRef = value ; } @ IsNotEmptyObject ( ) private _data : { [ p ] : any ; } ; get data ( ) : { [ p ] : any ; } { return this . _data ; } set data ( value ) { this . _data = value ; } @ IsEnum ( QuestionnaireType ) private _type : QuestionnaireType ; get type ( ) : QuestionnaireType { return this . _type ; } set type ( value ) { this . _type = value ; } @ IsString ( ) @ IsNotEmpty ( ) private _version : string ; get version ( ) : string { return this . _version ; } set version ( value ) { this . _version = value ; } @ IsObject ( ) @ IsNotEmptyObject ( ) private _createdAt : firebase . firestore . Timestamp ; get createdAt ( ) : firebase . firestore . Timestamp { return this . _createdAt ; } set createdAt ( value ) { this . _createdAt = value ; } static factory = ( data ) : Questionnaire => new Questionnaire ( data . parentRef , data . data , data . type , data . version , data . createdAt ) ; toObject ( ) { return { parentRef : this . parentRef , data : this . data , type : this . type , version : this . version , createdAt : this . createdAt . toDate ( ) , } ; } } export const QuestionnaireFirestoreConverter = { fromFirestore : ( data ) : Questionnaire => Questionnaire . factory ( data . data ( ) ) , toFirestore : ( modelObject ) : firebase . firestore . DocumentData => ( { parentRef : modelObject . parentRef , data : modelObject . data , type : modelObject . type , createdAt : modelObject . createdAt , version : modelObject . version , } ) , } ;