Back to ean13 based codes
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Nicolai Ort 2023-04-15 18:09:24 +02:00
parent 27e74e824c
commit a8fc755840
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
2 changed files with 4 additions and 10 deletions

View File

@ -57,7 +57,7 @@ export class CreateTrackScan {
* @returns The runnerCard whom's id you provided.
*/
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"] });
if (!runnerCard) {
throw new RunnerCardNotFoundError();

View File

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