import { IsArray , IsNotEmpty , IsObject , IsString } from 'class-validator' ; import { firestore } from 'firebase' ; import { OrganizationType } from './index' ; export interface ITeam extends firebase . firestore . DocumentData { name : string ; types : OrganizationType [ ] ; createdAt ? : firebase . firestore . Timestamp ; } export class Team implements ITeam { constructor ( name , types , createdAt = firestore . Timestamp . now ( ) ) { this . _name = name ; this . _types = types ; this . _createdAt = createdAt ; } @ IsString ( ) @ IsNotEmpty ( ) private _name : string ; get name ( ) : string { return this . _name ; } set name ( value ) { this . _name = value ; } @ IsArray ( ) private _types : OrganizationType [ ] ; get types ( ) : OrganizationType [ ] { return this . _types ; } set types ( value ) { this . _types = value ; } @ IsObject ( ) private _createdAt : firebase . firestore . Timestamp ; get createdAt ( ) : firebase . firestore . Timestamp { return this . _createdAt ; } set createdAt ( value ) { this . _createdAt = value ; } static factory = ( data ) : Team => new Team ( data . name , data . types , data . createdAt ) ; toObject ( ) { return { name : this . name , types : this . types , createdAt : this . createdAt . toDate ( ) , } ; } } export const TeamFirestoreConverter = { fromFirestore : ( data ) : Team => Team . factory ( data . data ( ) ) , toFirestore : ( modelObject ) : firebase . firestore . DocumentData => ( { name : modelObject . name , types : modelObject . types , createdAt : modelObject . createdAt , } ) , } ;