merge dev to main #208

Merged
philipp merged 79 commits from dev into main 2023-11-06 17:18:50 +00:00
2 changed files with 4 additions and 10 deletions
Showing only changes of commit a8fc755840 - Show all commits

View File

@ -57,7 +57,7 @@ export class CreateTrackScan {
* @returns The runnerCard whom's id you provided. * @returns The runnerCard whom's id you provided.
*/ */
public async getCard(): Promise<RunnerCard> { public async getCard(): Promise<RunnerCard> {
const id = this.card % 2000000; const id = this.card % 200000000000;
const runnerCard = await getConnection().getRepository(RunnerCard).findOne({ id: id }, { relations: ["runner"] }); const runnerCard = await getConnection().getRepository(RunnerCard).findOne({ id: id }, { relations: ["runner"] });
if (!runnerCard) { if (!runnerCard) {
throw new RunnerCardNotFoundError(); throw new RunnerCardNotFoundError();

View File

@ -52,13 +52,7 @@ export class RunnerCard {
* Generates a ean-13 compliant string for barcode generation. * Generates a ean-13 compliant string for barcode generation.
*/ */
public get code(): string { public get code(): string {
const multiply = [1, 3]; return this.paddedId
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();
} }
/** /**
@ -67,10 +61,10 @@ export class RunnerCard {
private get paddedId(): string { private get paddedId(): string {
let id: string = this.id.toString(); let id: string = this.id.toString();
if (id.length > 6) { if (id.length > 11) {
throw new RunnerCardIdOutOfRangeError(); throw new RunnerCardIdOutOfRangeError();
} }
while (id.length < 6) { id = '0' + id; } while (id.length < 11) { id = '0' + id; }
id = '2' + id; id = '2' + id;
return id; return id;