@@ -6,6 +6,7 @@ import {
 | 
			
		||||
  IsOptional
 | 
			
		||||
} from "class-validator";
 | 
			
		||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
 | 
			
		||||
import { RunnerCardIdOutOfRangeError } from '../../errors/RunnerCardErrors';
 | 
			
		||||
import { ResponseRunnerCard } from '../responses/ResponseRunnerCard';
 | 
			
		||||
import { Runner } from "./Runner";
 | 
			
		||||
import { TrackScan } from "./TrackScan";
 | 
			
		||||
@@ -51,8 +52,27 @@ export class RunnerCard {
 | 
			
		||||
   * Generates a ean-13 compliant string for barcode generation.
 | 
			
		||||
   */
 | 
			
		||||
  public get code(): string {
 | 
			
		||||
    //TODO: Implement the real deal
 | 
			
		||||
    return '0000000000000'
 | 
			
		||||
    const multiply = [1, 3];
 | 
			
		||||
    let total = 0;
 | 
			
		||||
    this.paddedId.split('').forEach((letter, index) => {
 | 
			
		||||
      total += parseInt(letter, 10) * multiply[index % 2];
 | 
			
		||||
    });
 | 
			
		||||
    const checkSum = (Math.ceil(total / 10) * 10) - total;
 | 
			
		||||
    return this.paddedId + checkSum.toString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns this card's id as a string padded to the length of 12 characters with leading zeros.
 | 
			
		||||
   */
 | 
			
		||||
  private get paddedId(): string {
 | 
			
		||||
    let id: string = this.id.toString();
 | 
			
		||||
 | 
			
		||||
    if (id.length > 12) {
 | 
			
		||||
      throw new RunnerCardIdOutOfRangeError();
 | 
			
		||||
    }
 | 
			
		||||
    while (id.length < 12) { id = '0' + id; }
 | 
			
		||||
 | 
			
		||||
    return id;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user