All files / src/domain/legal legal-acceptance.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                  10x 10x 10x 10x 10x       5x                   5x      
export type LegalDocumentId = 'privacy' | 'terms';
 
export interface LegalAcceptanceProps {
  id: string;
  userId: string;
  documentId: LegalDocumentId;
  version: string;
  acceptedAt: Date;
}
 
export interface RecordLegalAcceptanceProps {
  id: string;
  userId: string;
  documentId: LegalDocumentId;
  version: string;
  acceptedAt?: Date;
}
 
/**
 * That a user accepted one version of one legal document, and when.
 *
 * The version is part of the identity of the acceptance, not an attribute of it. Consent to a text
 * that has since been rewritten is not consent to the current one, so raising a document's version
 * is what makes everyone accept again — and what keeps this from being a boolean nobody can date.
 */
export class LegalAcceptance {
  readonly id: string;
  readonly userId: string;
  readonly documentId: LegalDocumentId;
  readonly version: string;
  readonly acceptedAt: Date;
 
  private constructor(props: LegalAcceptanceProps) {
    this.id = props.id;
    this.userId = props.userId;
    this.documentId = props.documentId;
    this.version = props.version;
    this.acceptedAt = props.acceptedAt;
  }
 
  static record(props: RecordLegalAcceptanceProps): LegalAcceptance {
    return new LegalAcceptance({
      id: props.id,
      userId: props.userId,
      documentId: props.documentId,
      version: props.version,
      acceptedAt: props.acceptedAt ?? new Date(),
    });
  }
 
  static restore(props: LegalAcceptanceProps): LegalAcceptance {
    return new LegalAcceptance(props);
  }
}