Back to ean13 based codes
This commit is contained in:
parent
27e74e824c
commit
a8fc755840
@ -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();
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user