mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Improvements to barcodes signature and generation (removed overhead)
This commit is contained in:
40
src/pass.ts
40
src/pass.ts
@@ -292,8 +292,8 @@ export class Pass {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
beacons(resetFlag: null): this;
|
beacons(resetFlag: null): this;
|
||||||
beacons(...data: schema.Beacon[]): this
|
beacons(...data: schema.Beacon[]): this
|
||||||
beacons(...data: (schema.Beacon|null)[]){
|
beacons(...data: (schema.Beacon|null)[]): this {
|
||||||
if (data[0] === null) {
|
if (data[0] === null) {
|
||||||
delete this[passProps]["beacons"];
|
delete this[passProps]["beacons"];
|
||||||
return this;
|
return this;
|
||||||
@@ -314,9 +314,9 @@ export class Pass {
|
|||||||
* @returns {Pass}
|
* @returns {Pass}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
locations(resetFlag : null) : this;
|
locations(resetFlag: null): this;
|
||||||
locations(...data: schema.Location[]): this;
|
locations(...data: schema.Location[]): this;
|
||||||
locations(...data: (schema.Location|null)[]) : this {
|
locations(...data: (schema.Location|null)[]): this {
|
||||||
if (data[0] === null) {
|
if (data[0] === null) {
|
||||||
delete this[passProps]["locations"];
|
delete this[passProps]["locations"];
|
||||||
return this;
|
return this;
|
||||||
@@ -363,27 +363,17 @@ export class Pass {
|
|||||||
* @return {this} Improved this with length property and other methods
|
* @return {this} Improved this with length property and other methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
barcodes(first: null | string | schema.Barcode, ...data: schema.Barcode[]): this {
|
barcodes(resetFlag: null): this;
|
||||||
if (first === null) {
|
barcodes(message: string): this;
|
||||||
|
barcodes(...data: schema.Barcode[]): this;
|
||||||
|
barcodes(...data: (schema.Barcode|null|string)[]): this {
|
||||||
|
if (data[0] === null) {
|
||||||
delete this[passProps]["barcodes"];
|
delete this[passProps]["barcodes"];
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isFirstParameterValid = (
|
if (typeof data[0] === "string") {
|
||||||
first && (
|
const autogen = barcodesFromUncompleteData(data[0]);
|
||||||
typeof first === "string" || (
|
|
||||||
typeof first === "object" &&
|
|
||||||
first.hasOwnProperty("message")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isFirstParameterValid) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof first === "string") {
|
|
||||||
const autogen = barcodesFromUncompleteData(first);
|
|
||||||
|
|
||||||
if (!autogen.length) {
|
if (!autogen.length) {
|
||||||
barcodeDebug(formatMessage("BRC_AUTC_MISSING_DATA"));
|
barcodeDebug(formatMessage("BRC_AUTC_MISSING_DATA"));
|
||||||
@@ -394,15 +384,13 @@ export class Pass {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
const barcodes = [first, ...(data || [])];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stripping from the array not-object elements
|
* Stripping from the array not-object elements
|
||||||
* and the ones that does not pass validation.
|
* and the ones that does not pass validation.
|
||||||
* Validation assign default value to missing parameters (if any).
|
* Validation assign default value to missing parameters (if any).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const valid = barcodes.reduce<schema.Barcode[]>((acc, current) => {
|
const validBarcodes = data.reduce<schema.Barcode[]>((acc, current) => {
|
||||||
if (!(current && current instanceof Object)) {
|
if (!(current && current instanceof Object)) {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
@@ -416,8 +404,8 @@ export class Pass {
|
|||||||
return [...acc, validated] as schema.Barcode[];
|
return [...acc, validated] as schema.Barcode[];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (valid.length) {
|
if (validBarcodes.length) {
|
||||||
this[passProps]["barcodes"] = valid;
|
this[passProps]["barcodes"] = validBarcodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user