store-scrapper-js-common 1.0.71 → 1.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import { AbstractBase } from './abstract-base';
2
+ import { CATEGORY_ENUM } from './keyword';
3
+ export declare class CategoryEntity extends AbstractBase {
4
+ category: CATEGORY_ENUM;
5
+ displayName?: {
6
+ es?: string;
7
+ en?: string;
8
+ br?: string;
9
+ };
10
+ enabled: boolean;
11
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CategoryEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const class_validator_1 = require("class-validator");
15
+ const abstract_base_1 = require("./abstract-base");
16
+ const keyword_1 = require("./keyword");
17
+ let CategoryEntity = class CategoryEntity extends abstract_base_1.AbstractBase {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.enabled = true;
21
+ }
22
+ };
23
+ __decorate([
24
+ typeorm_1.Index(),
25
+ typeorm_1.Column(),
26
+ class_validator_1.IsEnum(keyword_1.CATEGORY_ENUM),
27
+ __metadata("design:type", String)
28
+ ], CategoryEntity.prototype, "category", void 0);
29
+ __decorate([
30
+ typeorm_1.Column(),
31
+ __metadata("design:type", Object)
32
+ ], CategoryEntity.prototype, "displayName", void 0);
33
+ __decorate([
34
+ typeorm_1.Column({ default: true, type: 'boolean' }),
35
+ __metadata("design:type", Object)
36
+ ], CategoryEntity.prototype, "enabled", void 0);
37
+ CategoryEntity = __decorate([
38
+ typeorm_1.Entity({ name: 'categories' })
39
+ ], CategoryEntity);
40
+ exports.CategoryEntity = CategoryEntity;
41
+ //# sourceMappingURL=category-entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category-entity.js","sourceRoot":"/","sources":["entities/category-entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgD;AAChD,qDAAyC;AACzC,mDAA+C;AAC/C,uCAA0C;AAG1C,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,4BAAY;IAAhD;;QAcE,YAAO,GAAG,IAAI,CAAC;IACjB,CAAC;CAAA,CAAA;AAXC;IAHC,eAAK,EAAE;IACP,gBAAM,EAAE;IACR,wBAAM,CAAC,uBAAa,CAAC;;gDACE;AAGxB;IADC,gBAAM,EAAE;;mDAKR;AAGD;IADC,gBAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAC5B;AAdJ,cAAc;IAD1B,gBAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;GAClB,cAAc,CAe1B;AAfY,wCAAc","sourcesContent":["import { Column, Entity, Index } from 'typeorm';\nimport { IsEnum } from 'class-validator';\nimport { AbstractBase } from './abstract-base';\nimport { CATEGORY_ENUM } from './keyword';\n\n@Entity({ name: 'categories' })\nexport class CategoryEntity extends AbstractBase {\n @Index()\n @Column()\n @IsEnum(CATEGORY_ENUM)\n category: CATEGORY_ENUM;\n\n @Column()\n displayName?: {\n es?: string;\n en?: string;\n br?: string;\n }\n\n @Column({ default: true, type: 'boolean' })\n enabled = true;\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import { AbstractBase } from './abstract-base';
2
2
  import { ObjectLiteral } from '../classes';
3
3
  import { Product } from './product';
4
+ import { CATEGORY_ENUM } from './keyword';
4
5
  export declare class Category extends AbstractBase {
6
+ category?: CATEGORY_ENUM;
5
7
  name?: string;
6
8
  path?: string;
7
9
  url: string;
@@ -12,7 +12,7 @@ const abstract_base_1 = require("./abstract-base");
12
12
  let Category = class Category extends abstract_base_1.AbstractBase {
13
13
  };
14
14
  Category = __decorate([
15
- typeorm_1.Entity({ name: 'categories' })
15
+ typeorm_1.Entity({ name: 'categoryMenus' })
16
16
  ], Category);
17
17
  exports.Category = Category;
18
18
  //# sourceMappingURL=category.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"category.js","sourceRoot":"/","sources":["entities/category.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qCAAiC;AACjC,mDAA+C;AAK/C,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,4BAAY;CAYzC,CAAA;AAZY,QAAQ;IADpB,gBAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;GAClB,QAAQ,CAYpB;AAZY,4BAAQ","sourcesContent":["import { Entity } from 'typeorm';\nimport { AbstractBase } from './abstract-base';\nimport { ObjectLiteral } from '../classes';\nimport { Product } from './product';\n\n@Entity({ name: 'categories' })\nexport class Category extends AbstractBase {\n name?: string;\n\n path?: string;\n\n url: string;\n\n sourceUrl?: string;\n\n metadata?: ObjectLiteral;\n\n products?: Product[];\n}\n"]}
1
+ {"version":3,"file":"category.js","sourceRoot":"/","sources":["entities/category.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qCAAiC;AACjC,mDAA+C;AAO/C,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,4BAAY;CAczC,CAAA;AAdY,QAAQ;IADpB,gBAAM,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;GACrB,QAAQ,CAcpB;AAdY,4BAAQ","sourcesContent":["import { Entity } from 'typeorm';\nimport { AbstractBase } from './abstract-base';\nimport { ObjectLiteral } from '../classes';\nimport { Product } from './product';\nimport { CATEGORY_ENUM } from './keyword';\n\n// Mucho webeo cambiarle el nombre a todas las clases..\n@Entity({ name: 'categoryMenus' })\nexport class Category extends AbstractBase {\n category?: CATEGORY_ENUM;\n\n name?: string;\n\n path?: string;\n\n url: string;\n\n sourceUrl?: string;\n\n metadata?: ObjectLiteral;\n\n products?: Product[];\n}\n"]}
@@ -1,10 +1,12 @@
1
1
  import { StoreQueueConfig, Store, CountryEnum, PriorityEnum } from './store';
2
2
  import { Product, UpdateReasonEnum, CurrencyEnum, ProductAttributes, ConditionalPrice } from './product';
3
- import { Price } from './price';
3
+ import { Price, MeasurementUnitEnum } from './price';
4
4
  import { Category } from './category';
5
5
  import { AbstractBase } from './abstract-base';
6
6
  import { Keyword, CATEGORY_ENUM, CONDITION_ENUM, CONDITION_FIELD_ENUM } from './keyword';
7
7
  import { User } from './user';
8
8
  import { AlertConditions } from './alert-conditions';
9
+ import { PricesStats } from './prices-stats';
10
+ import { CategoryEntity } from './category-entity';
9
11
  export declare const Entities: (typeof Price | typeof Keyword | typeof Product | typeof Store | typeof User)[];
10
- export { Store, Product, Price, Category, AbstractBase, Keyword, CONDITION_FIELD_ENUM, CONDITION_ENUM, CATEGORY_ENUM, User, AlertConditions, StoreQueueConfig, CountryEnum, PriorityEnum, CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes, };
12
+ export { Store, Product, Price, Category, CategoryEntity, AbstractBase, Keyword, CONDITION_FIELD_ENUM, CONDITION_ENUM, CATEGORY_ENUM, User, AlertConditions, StoreQueueConfig, CountryEnum, PriorityEnum, CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes, MeasurementUnitEnum, PricesStats, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UpdateReasonEnum = exports.CurrencyEnum = exports.PriorityEnum = exports.CountryEnum = exports.AlertConditions = exports.User = exports.CATEGORY_ENUM = exports.CONDITION_ENUM = exports.CONDITION_FIELD_ENUM = exports.Keyword = exports.AbstractBase = exports.Category = exports.Price = exports.Product = exports.Store = exports.Entities = void 0;
3
+ exports.PricesStats = exports.MeasurementUnitEnum = exports.UpdateReasonEnum = exports.CurrencyEnum = exports.PriorityEnum = exports.CountryEnum = exports.AlertConditions = exports.User = exports.CATEGORY_ENUM = exports.CONDITION_ENUM = exports.CONDITION_FIELD_ENUM = exports.Keyword = exports.AbstractBase = exports.CategoryEntity = exports.Category = exports.Price = exports.Product = exports.Store = exports.Entities = void 0;
4
4
  const store_1 = require("./store");
5
5
  Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return store_1.Store; } });
6
6
  Object.defineProperty(exports, "CountryEnum", { enumerable: true, get: function () { return store_1.CountryEnum; } });
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "UpdateReasonEnum", { enumerable: true, get: func
11
11
  Object.defineProperty(exports, "CurrencyEnum", { enumerable: true, get: function () { return product_1.CurrencyEnum; } });
12
12
  const price_1 = require("./price");
13
13
  Object.defineProperty(exports, "Price", { enumerable: true, get: function () { return price_1.Price; } });
14
+ Object.defineProperty(exports, "MeasurementUnitEnum", { enumerable: true, get: function () { return price_1.MeasurementUnitEnum; } });
14
15
  const category_1 = require("./category");
15
16
  Object.defineProperty(exports, "Category", { enumerable: true, get: function () { return category_1.Category; } });
16
17
  const abstract_base_1 = require("./abstract-base");
@@ -24,6 +25,10 @@ const user_1 = require("./user");
24
25
  Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_1.User; } });
25
26
  const alert_conditions_1 = require("./alert-conditions");
26
27
  Object.defineProperty(exports, "AlertConditions", { enumerable: true, get: function () { return alert_conditions_1.AlertConditions; } });
28
+ const prices_stats_1 = require("./prices-stats");
29
+ Object.defineProperty(exports, "PricesStats", { enumerable: true, get: function () { return prices_stats_1.PricesStats; } });
30
+ const category_entity_1 = require("./category-entity");
31
+ Object.defineProperty(exports, "CategoryEntity", { enumerable: true, get: function () { return category_entity_1.CategoryEntity; } });
27
32
  exports.Entities = [
28
33
  store_1.Store, product_1.Product, price_1.Price, keyword_1.Keyword, user_1.User,
29
34
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["entities/index.ts"],"names":[],"mappings":";;;AAAA,mCAEiB;AAkBf,sFAnBkB,aAAK,OAmBlB;AACmE,4FApB/C,mBAAW,OAoB+C;AAAE,6FApB/C,oBAAY,OAoB+C;AAlBnG,uCAEmB;AAeV,wFAhBP,iBAAO,OAgBO;AAEA,iGAlBL,0BAAgB,OAkBK;AAA9B,6FAlB2B,sBAAY,OAkB3B;AAhBd,mCAAgC;AAcd,sFAdT,aAAK,OAcS;AAbvB,yCAAsC;AAab,yFAbhB,mBAAQ,OAagB;AAZjC,mDAA+C;AAYZ,6FAZ1B,4BAAY,OAY0B;AAX/C,uCAEmB;AAS8B,wFAV/C,iBAAO,OAU+C;AACtC,8FAXP,uBAAa,OAWO;AAA7B,+FAXwB,wBAAc,OAWxB;AAD0C,qGAVhB,8BAAoB,OAUgB;AAR9E,iCAA8B;AASG,qFATxB,WAAI,OASwB;AARrC,yDAAqD;AAQd,gGAR9B,kCAAe,OAQ8B;AANzC,QAAA,QAAQ,GAAG;IACtB,aAAK,EAAE,iBAAO,EAAE,aAAK,EAAE,iBAAO,EAAE,WAAI;CACrC,CAAC","sourcesContent":["import {\n StoreQueueConfig, Store, CountryEnum, PriorityEnum,\n} from './store';\nimport {\n Product, UpdateReasonEnum, CurrencyEnum, ProductAttributes, ConditionalPrice,\n} from './product';\nimport { Price } from './price';\nimport { Category } from './category';\nimport { AbstractBase } from './abstract-base';\nimport {\n Keyword, CATEGORY_ENUM, CONDITION_ENUM, CONDITION_FIELD_ENUM,\n} from './keyword';\nimport { User } from './user';\nimport { AlertConditions } from './alert-conditions';\n\nexport const Entities = [\n Store, Product, Price, Keyword, User,\n];\n\nexport {\n Store, Product, Price, Category, AbstractBase, Keyword, CONDITION_FIELD_ENUM,\n CONDITION_ENUM, CATEGORY_ENUM, User, AlertConditions, StoreQueueConfig, CountryEnum, PriorityEnum,\n CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes,\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["entities/index.ts"],"names":[],"mappings":";;;AAAA,mCAEiB;AAoBf,sFArBkB,aAAK,OAqBlB;AACmE,4FAtB/C,mBAAW,OAsB+C;AAAE,6FAtB/C,oBAAY,OAsB+C;AApBnG,uCAEmB;AAiBV,wFAlBP,iBAAO,OAkBO;AAEA,iGApBL,0BAAgB,OAoBK;AAA9B,6FApB2B,sBAAY,OAoB3B;AAlBd,mCAAqD;AAgBnC,sFAhBT,aAAK,OAgBS;AAEgD,oGAlBvD,2BAAmB,OAkBuD;AAjB1F,yCAAsC;AAeb,yFAfhB,mBAAQ,OAegB;AAdjC,mDAA+C;AAcI,6FAd1C,4BAAY,OAc0C;AAb/D,uCAEmB;AAW8C,wFAZ/D,iBAAO,OAY+D;AACtD,8FAbP,uBAAa,OAaO;AAA7B,+FAbwB,wBAAc,OAaxB;AAD0D,qGAZhC,8BAAoB,OAYgC;AAV9F,iCAA8B;AAWG,qFAXxB,WAAI,OAWwB;AAVrC,yDAAqD;AAUd,gGAV9B,kCAAe,OAU8B;AATtD,iDAA6C;AAU+C,4FAVnF,0BAAW,OAUmF;AATvG,uDAAmD;AAOhB,+FAP1B,gCAAc,OAO0B;AALpC,QAAA,QAAQ,GAAG;IACtB,aAAK,EAAE,iBAAO,EAAE,aAAK,EAAE,iBAAO,EAAE,WAAI;CACrC,CAAC","sourcesContent":["import {\n StoreQueueConfig, Store, CountryEnum, PriorityEnum,\n} from './store';\nimport {\n Product, UpdateReasonEnum, CurrencyEnum, ProductAttributes, ConditionalPrice,\n} from './product';\nimport { Price, MeasurementUnitEnum } from './price';\nimport { Category } from './category';\nimport { AbstractBase } from './abstract-base';\nimport {\n Keyword, CATEGORY_ENUM, CONDITION_ENUM, CONDITION_FIELD_ENUM,\n} from './keyword';\nimport { User } from './user';\nimport { AlertConditions } from './alert-conditions';\nimport { PricesStats } from './prices-stats';\nimport { CategoryEntity } from './category-entity';\n\nexport const Entities = [\n Store, Product, Price, Keyword, User,\n];\n\nexport {\n Store, Product, Price, Category, CategoryEntity, AbstractBase, Keyword, CONDITION_FIELD_ENUM,\n CONDITION_ENUM, CATEGORY_ENUM, User, AlertConditions, StoreQueueConfig, CountryEnum, PriorityEnum,\n CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes, MeasurementUnitEnum, PricesStats,\n};\n"]}
@@ -1,9 +1,18 @@
1
1
  import { AbstractBase } from './abstract-base';
2
+ export declare enum MeasurementUnitEnum {
3
+ KG = "kg",
4
+ G = "g",
5
+ L = "l",
6
+ ML = "ml",
7
+ UNIT = "unit"
8
+ }
2
9
  export declare class Price extends AbstractBase {
3
10
  productRef: string;
4
11
  normalPrice?: number;
5
12
  offerPrice?: number;
6
13
  cardPrice?: number;
7
14
  sourceUrl?: string;
15
+ unitMultiplier?: number;
16
+ measurementUnit?: MeasurementUnitEnum;
8
17
  createdAt?: Date;
9
18
  }
@@ -9,10 +9,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Price = void 0;
12
+ exports.Price = exports.MeasurementUnitEnum = void 0;
13
13
  const typeorm_1 = require("typeorm");
14
14
  const class_validator_1 = require("class-validator");
15
15
  const abstract_base_1 = require("./abstract-base");
16
+ var MeasurementUnitEnum;
17
+ (function (MeasurementUnitEnum) {
18
+ MeasurementUnitEnum["KG"] = "kg";
19
+ MeasurementUnitEnum["G"] = "g";
20
+ MeasurementUnitEnum["L"] = "l";
21
+ MeasurementUnitEnum["ML"] = "ml";
22
+ MeasurementUnitEnum["UNIT"] = "unit";
23
+ })(MeasurementUnitEnum = exports.MeasurementUnitEnum || (exports.MeasurementUnitEnum = {}));
16
24
  let Price = class Price extends abstract_base_1.AbstractBase {
17
25
  };
18
26
  __decorate([
@@ -44,6 +52,16 @@ __decorate([
44
52
  class_validator_1.IsOptional(),
45
53
  __metadata("design:type", String)
46
54
  ], Price.prototype, "sourceUrl", void 0);
55
+ __decorate([
56
+ typeorm_1.Column(),
57
+ class_validator_1.IsOptional(),
58
+ __metadata("design:type", Number)
59
+ ], Price.prototype, "unitMultiplier", void 0);
60
+ __decorate([
61
+ typeorm_1.Column(),
62
+ class_validator_1.IsOptional(),
63
+ __metadata("design:type", String)
64
+ ], Price.prototype, "measurementUnit", void 0);
47
65
  __decorate([
48
66
  typeorm_1.CreateDateColumn(),
49
67
  typeorm_1.Index(),
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"/","sources":["entities/price.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAEiB;AACjB,qDAAmE;AACnE,mDAA+C;AAG/C,IAAa,KAAK,GAAlB,MAAa,KAAM,SAAQ,4BAAY;CA4BtC,CAAA;AAxBG;IAHC,gBAAM,EAAE;IACR,4BAAU,EAAE;IACZ,eAAK,EAAE;;yCACW;AAKnB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;0CACQ;AAKrB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;yCACO;AAKpB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;wCACM;AAInB;IAFC,gBAAM,EAAE;IACR,4BAAU,EAAE;;wCACM;AAInB;IAFC,0BAAgB,EAAE;IAClB,eAAK,EAAE;8BACI,IAAI;wCAAC;AA3BR,KAAK;IADjB,gBAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;GACd,KAAK,CA4BjB;AA5BY,sBAAK","sourcesContent":["import {\n Column, CreateDateColumn, Entity, Index,\n} from 'typeorm';\nimport { IsNotEmpty, IsNumber, IsOptional } from 'class-validator';\nimport { AbstractBase } from './abstract-base';\n\n@Entity({ name: 'prices' })\nexport class Price extends AbstractBase {\n @Column()\n @IsNotEmpty()\n @Index()\n productRef: string;\n\n @Column()\n @IsNumber()\n @IsOptional()\n normalPrice?: number;\n\n @Column()\n @IsNumber()\n @IsOptional()\n offerPrice?: number;\n\n @Column()\n @IsNumber()\n @IsOptional()\n cardPrice?: number;\n\n @Column()\n @IsOptional()\n sourceUrl?: string;\n\n @CreateDateColumn()\n @Index()\n createdAt?: Date;\n}\n"]}
1
+ {"version":3,"file":"price.js","sourceRoot":"/","sources":["entities/price.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAEiB;AACjB,qDAAmE;AACnE,mDAA+C;AAE/C,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC3B,gCAAS,CAAA;IACT,8BAAO,CAAA;IACP,8BAAO,CAAA;IACP,gCAAS,CAAA;IACT,oCAAa,CAAA;AACjB,CAAC,EANW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAM9B;AAGD,IAAa,KAAK,GAAlB,MAAa,KAAM,SAAQ,4BAAY;CAoCtC,CAAA;AAhCG;IAHC,gBAAM,EAAE;IACR,4BAAU,EAAE;IACZ,eAAK,EAAE;;yCACW;AAKnB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;0CACQ;AAKrB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;yCACO;AAKpB;IAHC,gBAAM,EAAE;IACR,0BAAQ,EAAE;IACV,4BAAU,EAAE;;wCACM;AAInB;IAFC,gBAAM,EAAE;IACR,4BAAU,EAAE;;wCACM;AAInB;IAFC,gBAAM,EAAE;IACR,4BAAU,EAAE;;6CACW;AAIxB;IAFC,gBAAM,EAAE;IACR,4BAAU,EAAE;;8CACyB;AAItC;IAFC,0BAAgB,EAAE;IAClB,eAAK,EAAE;8BACI,IAAI;wCAAC;AAnCR,KAAK;IADjB,gBAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;GACd,KAAK,CAoCjB;AApCY,sBAAK","sourcesContent":["import {\n Column, CreateDateColumn, Entity, Index,\n} from 'typeorm';\nimport { IsNotEmpty, IsNumber, IsOptional } from 'class-validator';\nimport { AbstractBase } from './abstract-base';\n\nexport enum MeasurementUnitEnum {\n KG = 'kg',\n G = 'g',\n L = 'l',\n ML = 'ml',\n UNIT = 'unit'\n}\n\n@Entity({ name: 'prices' })\nexport class Price extends AbstractBase {\n @Column()\n @IsNotEmpty()\n @Index()\n productRef: string;\n\n @Column()\n @IsNumber()\n @IsOptional()\n normalPrice?: number;\n\n @Column()\n @IsNumber()\n @IsOptional()\n offerPrice?: number;\n\n @Column()\n @IsNumber()\n @IsOptional()\n cardPrice?: number;\n\n @Column()\n @IsOptional()\n sourceUrl?: string;\n\n @Column()\n @IsOptional()\n unitMultiplier?: number;\n\n @Column()\n @IsOptional()\n measurementUnit?: MeasurementUnitEnum;\n\n @CreateDateColumn()\n @Index()\n createdAt?: Date;\n}\n"]}
@@ -7,6 +7,7 @@ export declare enum CurrencyEnum {
7
7
  CMR_PTS = "cmr_pts",
8
8
  PARIS_PTS = "paris_pts",
9
9
  RIPLEY_PTS = "ripley_pts",
10
+ GENERAL_POINTS = "general_pts",
10
11
  BRL = "brl",
11
12
  PEN = "PEN",
12
13
  ARS = "ars",
@@ -15,6 +16,7 @@ export declare enum CurrencyEnum {
15
16
  export declare enum UpdateReasonEnum {
16
17
  TIME = "time",
17
18
  NEW_PRICE = "new_price",
19
+ NEW_CONDITIONAL_PRICE = "new_conditional_price",
18
20
  NEW_NAME = "new_name",
19
21
  NEW_LISTING = "new_listing",
20
22
  MISSING_DATA = "missing_data",
@@ -30,6 +32,7 @@ export interface ConditionalPrice {
30
32
  minAmount?: number;
31
33
  price?: number;
32
34
  cardRequired?: boolean;
35
+ createdAt?: Date;
33
36
  }
34
37
  export declare class Product extends AbstractBase {
35
38
  name: string;
@@ -21,6 +21,7 @@ var CurrencyEnum;
21
21
  CurrencyEnum["CMR_PTS"] = "cmr_pts";
22
22
  CurrencyEnum["PARIS_PTS"] = "paris_pts";
23
23
  CurrencyEnum["RIPLEY_PTS"] = "ripley_pts";
24
+ CurrencyEnum["GENERAL_POINTS"] = "general_pts";
24
25
  CurrencyEnum["BRL"] = "brl";
25
26
  CurrencyEnum["PEN"] = "PEN";
26
27
  CurrencyEnum["ARS"] = "ars";
@@ -30,6 +31,7 @@ var UpdateReasonEnum;
30
31
  (function (UpdateReasonEnum) {
31
32
  UpdateReasonEnum["TIME"] = "time";
32
33
  UpdateReasonEnum["NEW_PRICE"] = "new_price";
34
+ UpdateReasonEnum["NEW_CONDITIONAL_PRICE"] = "new_conditional_price";
33
35
  UpdateReasonEnum["NEW_NAME"] = "new_name";
34
36
  UpdateReasonEnum["NEW_LISTING"] = "new_listing";
35
37
  UpdateReasonEnum["MISSING_DATA"] = "missing_data";
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"/","sources":["entities/product.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAGiB;AACjB,qDAA6C;AAC7C,mDAA+C;AAC/C,mCAAgC;AAChC,iDAA6C;AAG7C,IAAY,YASX;AATD,WAAY,YAAY;IACpB,2BAAW,CAAA;IACX,mCAAmB,CAAA;IACnB,uCAAuB,CAAA;IACvB,yCAAyB,CAAA;IACzB,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,2BAAW,CAAA;AACf,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB;AAED,IAAY,gBAOX;AAPD,WAAY,gBAAgB;IACxB,iCAAa,CAAA;IACb,2CAAuB,CAAA;IACvB,yCAAqB,CAAA;IACrB,+CAA2B,CAAA;IAC3B,iDAA6B,CAAA;IAC7B,yCAAqB,CAAA;AACzB,CAAC,EAPW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAO3B;AAsBD,IAAa,OAAO,GAApB,MAAa,OAAQ,SAAQ,4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6CACuB;AAGhC;IADC,gBAAM,EAAE;;4CAIL;AAGJ;IADC,gBAAM,EAAE;;mDACmB;AAG5B;IADC,gBAAM,EAAE;;oDACoB;AA9GpB,OAAO;IAFnB,gBAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC5B,gBAAM,CAAC,eAAe,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;GAChC,OAAO,CA+GnB;AA/GY,0BAAO","sourcesContent":["import {\n Column,\n Entity, Index, Unique,\n} from 'typeorm';\nimport { IsNotEmpty } from 'class-validator';\nimport { AbstractBase } from './abstract-base';\nimport { Price } from './price';\nimport { PricesStats } from './prices-stats';\nimport { Keyword } from './keyword';\n\nexport enum CurrencyEnum {\n CLP = 'clp',\n CMR_PTS = 'cmr_pts',\n PARIS_PTS = 'paris_pts',\n RIPLEY_PTS = 'ripley_pts',\n BRL = 'brl',\n PEN = 'PEN',\n ARS = 'ars',\n EUR = 'eur'\n}\n\nexport enum UpdateReasonEnum {\n TIME = 'time',\n NEW_PRICE = 'new_price',\n NEW_NAME = 'new_name',\n NEW_LISTING = 'new_listing',\n MISSING_DATA = 'missing_data',\n FIX_DATA = 'fix_data',\n}\n\nexport interface ProductAttributes {\n stock?: number;\n\n // TODO: Add enum\n color?: string;\n\n // TODO: Add enum\n size?: string;\n\n [key: string]: any;\n}\n\nexport interface ConditionalPrice {\n minAmount?: number;\n price?: number;\n cardRequired?: boolean;\n}\n\n@Entity({ name: 'products' })\n@Unique('store_ref_sku', ['storeRef', 'sku'])\nexport class Product extends AbstractBase {\n @Column()\n name: string;\n\n @Column()\n brandName?: string;\n\n @Column()\n modelName?: string;\n\n @Column()\n @IsNotEmpty()\n @Index()\n sku: string;\n\n @Column()\n internalId?: string;\n\n @Column()\n @IsNotEmpty()\n url: string;\n\n @Column()\n @IsNotEmpty()\n @Index()\n storeRef: string;\n\n @Column()\n storeName?: string;\n\n @Column()\n sellerName?: string;\n\n @Column()\n @IsNotEmpty()\n price?: Price;\n\n @Column()\n conditionalPrice?: ConditionalPrice;\n\n @Column()\n previousPrice?: Price;\n\n @Column()\n bestPrice?: Price;\n\n @Column()\n priceStats?: PricesStats;\n\n @Column()\n priceHistory?: Price[];\n\n @Column()\n rank?: number;\n\n @Column()\n image?: string;\n\n @Column()\n category?: string;\n\n @Column()\n categoryPath?: string;\n\n @Column()\n attributes?: ProductAttributes;\n\n @Column()\n homeDeliveryShipping?: boolean;\n\n @Column()\n pickUpFromStoreShipping?: boolean;\n\n @Column()\n enabled?: boolean;\n\n @Column()\n sourceUrl?: string;\n\n @Column()\n @Index()\n updatedAt?: Date;\n\n @Column()\n @Index()\n categoryKeywordNames?: string[];\n\n @Column()\n categoryKeywords?: Keyword[];\n\n @Column()\n @Index()\n processedPricesAt?: Date;\n\n @Column()\n currency?: CurrencyEnum;\n\n @Column()\n updateReason?: UpdateReasonEnum;\n\n @Column()\n nameHistory?: {\n name: string,\n updatedAt: string,\n }[];\n\n @Column()\n parentProductIdRef?: string;\n\n @Column()\n parentProductSkuRef?: string;\n}\n"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"/","sources":["entities/product.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAGiB;AACjB,qDAA6C;AAC7C,mDAA+C;AAC/C,mCAAgC;AAChC,iDAA6C;AAG7C,IAAY,YAUX;AAVD,WAAY,YAAY;IACpB,2BAAW,CAAA;IACX,mCAAmB,CAAA;IACnB,uCAAuB,CAAA;IACvB,yCAAyB,CAAA;IACzB,8CAA8B,CAAA;IAC9B,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,2BAAW,CAAA;IACX,2BAAW,CAAA;AACf,CAAC,EAVW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAUvB;AAED,IAAY,gBAQX;AARD,WAAY,gBAAgB;IACxB,iCAAa,CAAA;IACb,2CAAuB,CAAA;IACvB,mEAA+C,CAAA;IAC/C,yCAAqB,CAAA;IACrB,+CAA2B,CAAA;IAC3B,iDAA6B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AAM,EAAE;;iDACoB;AAI7B;IAFC,gBAAM,EAAE;IACR,eAAK,EAAE;8BACY,IAAI;kDAAC;AAGzB;IADC,gBAAM,EAAE;;yCACe;AAGxB;IADC,gBAAM,EAAE;;6CACuB;AAGhC;IADC,gBAAM,EAAE;;4CAIL;AAGJ;IADC,gBAAM,EAAE;;mDACmB;AAG5B;IADC,gBAAM,EAAE;;oDACoB;AA9GpB,OAAO;IAFnB,gBAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IAC5B,gBAAM,CAAC,eAAe,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;GAChC,OAAO,CA+GnB;AA/GY,0BAAO","sourcesContent":["import {\n Column,\n Entity, Index, Unique,\n} from 'typeorm';\nimport { IsNotEmpty } from 'class-validator';\nimport { AbstractBase } from './abstract-base';\nimport { Price } from './price';\nimport { PricesStats } from './prices-stats';\nimport { Keyword } from './keyword';\n\nexport enum CurrencyEnum {\n CLP = 'clp',\n CMR_PTS = 'cmr_pts',\n PARIS_PTS = 'paris_pts',\n RIPLEY_PTS = 'ripley_pts',\n GENERAL_POINTS = 'general_pts',\n BRL = 'brl',\n PEN = 'PEN',\n ARS = 'ars',\n EUR = 'eur'\n}\n\nexport enum UpdateReasonEnum {\n TIME = 'time',\n NEW_PRICE = 'new_price',\n NEW_CONDITIONAL_PRICE = 'new_conditional_price',\n NEW_NAME = 'new_name',\n NEW_LISTING = 'new_listing',\n MISSING_DATA = 'missing_data',\n FIX_DATA = 'fix_data',\n}\n\nexport interface ProductAttributes {\n stock?: number;\n\n // TODO: Add enum\n color?: string;\n\n // TODO: Add enum\n size?: string;\n\n [key: string]: any;\n}\n\nexport interface ConditionalPrice {\n minAmount?: number;\n price?:number;\n cardRequired?: boolean;\n createdAt?: Date;\n}\n\n@Entity({ name: 'products' })\n@Unique('store_ref_sku', ['storeRef', 'sku'])\nexport class Product extends AbstractBase {\n @Column()\n name: string;\n\n @Column()\n brandName?: string;\n\n @Column()\n modelName?: string;\n\n @Column()\n @IsNotEmpty()\n @Index()\n sku: string;\n\n @Column()\n internalId?: string;\n\n @Column()\n @IsNotEmpty()\n url: string;\n\n @Column()\n @IsNotEmpty()\n @Index()\n storeRef: string;\n\n @Column()\n storeName?: string;\n\n @Column()\n sellerName?: string;\n\n @Column()\n @IsNotEmpty()\n price?: Price;\n\n @Column()\n conditionalPrice?: ConditionalPrice;\n\n @Column()\n previousPrice?: Price;\n\n @Column()\n bestPrice?: Price;\n\n @Column()\n priceStats?: PricesStats;\n\n @Column()\n priceHistory?: Price[];\n\n @Column()\n rank?: number;\n\n @Column()\n image?: string;\n\n @Column()\n category?: string;\n\n @Column()\n categoryPath?: string;\n\n @Column()\n attributes?: ProductAttributes;\n\n @Column()\n homeDeliveryShipping?: boolean;\n\n @Column()\n pickUpFromStoreShipping?: boolean;\n\n @Column()\n enabled?: boolean;\n\n @Column()\n sourceUrl?: string;\n\n @Column()\n @Index()\n updatedAt?: Date;\n\n @Column()\n @Index()\n categoryKeywordNames?: string[];\n\n @Column()\n categoryKeywords?: Keyword[];\n\n @Column()\n @Index()\n processedPricesAt?: Date;\n\n @Column()\n currency?: CurrencyEnum;\n\n @Column()\n updateReason?: UpdateReasonEnum;\n\n @Column()\n nameHistory?: {\n name: string,\n updatedAt: string,\n }[];\n\n @Column()\n parentProductIdRef?: string;\n\n @Column()\n parentProductSkuRef?: string;\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { checkIfSamePrices, isCheaper, getMinPrice, isValidPrice, getAvgPrice, getMaxPrice, getPriceOperation, removeZeroPrices } from './price-utils';
1
+ import { checkIfSamePrices, isCheaper, getMinPrice, isValidPrice, getAvgPrice, getMaxPrice, getPriceOperation, removeZeroPrices, hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier } from './price-utils';
2
2
  import { findLastQuery } from './entity-queries-utils';
3
3
  import { reverseString, removeNewLines, includesStringArray, getLastAfter, replaceMultipleSpacesByOne, removeIfEndsWith } from './string-utils';
4
4
  import { isUrl, getHostname, getParam, getPathname } from './url-utils';
5
5
  import { calculateAverage, roundNumber } from './number-utils';
6
- export { checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne, removeIfEndsWith, getLastAfter, includesStringArray, removeNewLines, reverseString, getParam, getPathname, getHostname, isUrl, isValidPrice, getMinPrice, isCheaper, getMaxPrice, getPriceOperation, getAvgPrice, calculateAverage, roundNumber, removeZeroPrices, };
6
+ export { checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne, hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier, removeIfEndsWith, getLastAfter, includesStringArray, removeNewLines, reverseString, getParam, getPathname, getHostname, isUrl, isValidPrice, getMinPrice, isCheaper, getMaxPrice, getPriceOperation, getAvgPrice, calculateAverage, roundNumber, removeZeroPrices, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeZeroPrices = exports.roundNumber = exports.calculateAverage = exports.getAvgPrice = exports.getPriceOperation = exports.getMaxPrice = exports.isCheaper = exports.getMinPrice = exports.isValidPrice = exports.isUrl = exports.getHostname = exports.getPathname = exports.getParam = exports.reverseString = exports.removeNewLines = exports.includesStringArray = exports.getLastAfter = exports.removeIfEndsWith = exports.replaceMultipleSpacesByOne = exports.findLastQuery = exports.checkIfSamePrices = void 0;
3
+ exports.removeZeroPrices = exports.roundNumber = exports.calculateAverage = exports.getAvgPrice = exports.getPriceOperation = exports.getMaxPrice = exports.isCheaper = exports.getMinPrice = exports.isValidPrice = exports.isUrl = exports.getHostname = exports.getPathname = exports.getParam = exports.reverseString = exports.removeNewLines = exports.includesStringArray = exports.getLastAfter = exports.removeIfEndsWith = exports.getPriceByMeasurementUnitMultiplier = exports.hasMeasurementUnitMultiplier = exports.replaceMultipleSpacesByOne = exports.findLastQuery = exports.checkIfSamePrices = void 0;
4
4
  const price_utils_1 = require("./price-utils");
5
5
  Object.defineProperty(exports, "checkIfSamePrices", { enumerable: true, get: function () { return price_utils_1.checkIfSamePrices; } });
6
6
  Object.defineProperty(exports, "isCheaper", { enumerable: true, get: function () { return price_utils_1.isCheaper; } });
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "getAvgPrice", { enumerable: true, get: function
10
10
  Object.defineProperty(exports, "getMaxPrice", { enumerable: true, get: function () { return price_utils_1.getMaxPrice; } });
11
11
  Object.defineProperty(exports, "getPriceOperation", { enumerable: true, get: function () { return price_utils_1.getPriceOperation; } });
12
12
  Object.defineProperty(exports, "removeZeroPrices", { enumerable: true, get: function () { return price_utils_1.removeZeroPrices; } });
13
+ Object.defineProperty(exports, "hasMeasurementUnitMultiplier", { enumerable: true, get: function () { return price_utils_1.hasMeasurementUnitMultiplier; } });
14
+ Object.defineProperty(exports, "getPriceByMeasurementUnitMultiplier", { enumerable: true, get: function () { return price_utils_1.getPriceByMeasurementUnitMultiplier; } });
13
15
  const entity_queries_utils_1 = require("./entity-queries-utils");
14
16
  Object.defineProperty(exports, "findLastQuery", { enumerable: true, get: function () { return entity_queries_utils_1.findLastQuery; } });
15
17
  const string_utils_1 = require("./string-utils");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,+CAEuB;AAcrB,kGAfA,+BAAiB,OAeA;AAE8B,0FAjB5B,uBAAS,OAiB4B;AAAtB,4FAjBJ,yBAAW,OAiBI;AAAzB,6FAjBuB,0BAAY,OAiBvB;AAA0D,4FAjBjC,yBAAW,OAiBiC;AAA3C,4FAjBY,yBAAW,OAiBZ;AAAE,kGAjBY,+BAAiB,OAiBZ;AAC3E,iGAlByF,8BAAgB,OAkBzF;AAhB/B,iEAAuD;AAalC,8FAbZ,oCAAa,OAaY;AAZlC,iDAGwB;AAU+C,8FAZrE,4BAAa,OAYqE;AAA7B,+FAZtC,6BAAc,OAYsC;AAAnC,oGAZD,kCAAmB,OAYC;AAAjC,6FAZkC,2BAAY,OAYlC;AADI,2GAXgC,yCAA0B,OAWhC;AAC5D,iGAZ8F,+BAAgB,OAY9F;AATlB,2CAEqB;AAQN,sFATb,iBAAK,OASa;AAAlB,4FATO,uBAAW,OASP;AADyE,yFARhE,oBAAQ,OAQgE;AAAE,4FARhE,uBAAW,OAQgE;AAN3G,iDAEwB;AAKiF,iGANvG,+BAAgB,OAMuG;AACvH,4FAPkB,0BAAW,OAOlB","sourcesContent":["import {\n checkIfSamePrices, isCheaper, getMinPrice, isValidPrice, getAvgPrice, getMaxPrice, getPriceOperation, removeZeroPrices,\n} from './price-utils';\nimport { findLastQuery } from './entity-queries-utils';\nimport {\n reverseString, removeNewLines, includesStringArray, getLastAfter, replaceMultipleSpacesByOne, removeIfEndsWith,\n}\n from './string-utils';\nimport {\n isUrl, getHostname, getParam, getPathname,\n} from './url-utils';\nimport {\n calculateAverage, roundNumber,\n} from './number-utils';\n\nexport {\n checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne,\n removeIfEndsWith, getLastAfter, includesStringArray, removeNewLines, reverseString, getParam, getPathname,\n getHostname, isUrl, isValidPrice, getMinPrice, isCheaper, getMaxPrice, getPriceOperation, getAvgPrice, calculateAverage,\n roundNumber, removeZeroPrices,\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,+CAGuB;AAcrB,kGAhBA,+BAAiB,OAgBA;AAE8B,0FAlB5B,uBAAS,OAkB4B;AAAtB,4FAlBJ,yBAAW,OAkBI;AAAzB,6FAlBuB,0BAAY,OAkBvB;AAA0D,4FAlBjC,yBAAW,OAkBiC;AAA3C,4FAlBY,yBAAW,OAkBZ;AAAE,kGAlBY,+BAAiB,OAkBZ;AAC3E,iGAnByF,8BAAgB,OAmBzF;AAHiC,6GAf9D,0CAA4B,OAe8D;AAAE,oHAf9D,iDAAmC,OAe8D;AAbjI,iEAAuD;AAalC,8FAbZ,oCAAa,OAaY;AAZlC,iDAGwB;AAU+C,8FAZrE,4BAAa,OAYqE;AAA7B,+FAZtC,6BAAc,OAYsC;AAAnC,oGAZD,kCAAmB,OAYC;AAAjC,6FAZkC,2BAAY,OAYlC;AADI,2GAXgC,yCAA0B,OAWhC;AAC5D,iGAZ8F,+BAAgB,OAY9F;AATlB,2CAEqB;AAQN,sFATb,iBAAK,OASa;AAAlB,4FATO,uBAAW,OASP;AADyE,yFARhE,oBAAQ,OAQgE;AAAE,4FARhE,uBAAW,OAQgE;AAN3G,iDAEwB;AAKiF,iGANvG,+BAAgB,OAMuG;AACvH,4FAPkB,0BAAW,OAOlB","sourcesContent":["import {\n checkIfSamePrices, isCheaper, getMinPrice, isValidPrice, getAvgPrice, getMaxPrice, getPriceOperation, removeZeroPrices,\n hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier,\n} from './price-utils';\nimport { findLastQuery } from './entity-queries-utils';\nimport {\n reverseString, removeNewLines, includesStringArray, getLastAfter, replaceMultipleSpacesByOne, removeIfEndsWith,\n}\n from './string-utils';\nimport {\n isUrl, getHostname, getParam, getPathname,\n} from './url-utils';\nimport {\n calculateAverage, roundNumber,\n} from './number-utils';\n\nexport {\n checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne, hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier,\n removeIfEndsWith, getLastAfter, includesStringArray, removeNewLines, reverseString, getParam, getPathname,\n getHostname, isUrl, isValidPrice, getMinPrice, isCheaper, getMaxPrice, getPriceOperation, getAvgPrice, calculateAverage,\n roundNumber, removeZeroPrices,\n};\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Price } from '../entities';
2
+ export declare const hasMeasurementUnitMultiplier: (price: Price) => boolean;
2
3
  export declare const checkIfSamePrices: (_price: Price, _price2: Price) => boolean;
3
4
  export declare const isValidPrice: (price: Price) => boolean;
4
5
  export declare const removeZeroPrices: (price: Price) => Price;
@@ -6,4 +7,5 @@ export declare const getPriceOperation: (price: Price, fn: (...p: any[]) => numb
6
7
  export declare const getMinPrice: (price: Price) => number;
7
8
  export declare const getMaxPrice: (price: Price) => number;
8
9
  export declare const getAvgPrice: (price: Price) => number;
10
+ export declare const getPriceByMeasurementUnitMultiplier: (price: Price, minUnit?: number) => number;
9
11
  export declare const isCheaper: (price: Price, comparePrice: Price) => boolean | null;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCheaper = exports.getAvgPrice = exports.getMaxPrice = exports.getMinPrice = exports.getPriceOperation = exports.removeZeroPrices = exports.isValidPrice = exports.checkIfSamePrices = void 0;
3
+ exports.isCheaper = exports.getPriceByMeasurementUnitMultiplier = exports.getAvgPrice = exports.getMaxPrice = exports.getMinPrice = exports.getPriceOperation = exports.removeZeroPrices = exports.isValidPrice = exports.checkIfSamePrices = exports.hasMeasurementUnitMultiplier = void 0;
4
4
  const lodash_1 = require("lodash");
5
+ const entities_1 = require("../entities");
6
+ exports.hasMeasurementUnitMultiplier = (price) => !!price && !!price.unitMultiplier && !!price.measurementUnit;
5
7
  exports.checkIfSamePrices = (_price, _price2) => _price && _price2 && lodash_1.isEqual(lodash_1.pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, lodash_1.identity), lodash_1.pickBy({ normalPrice: _price2.normalPrice, offerPrice: _price2.offerPrice, cardPrice: _price2.cardPrice }, lodash_1.identity));
6
8
  exports.isValidPrice = (price) => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));
7
9
  exports.removeZeroPrices = (price) => {
@@ -36,12 +38,38 @@ exports.getAvgPrice = (price) => {
36
38
  };
37
39
  return exports.getPriceOperation(price, fn);
38
40
  };
41
+ exports.getPriceByMeasurementUnitMultiplier = (price, minUnit = 100) => {
42
+ if (!exports.hasMeasurementUnitMultiplier(price)) {
43
+ return null;
44
+ }
45
+ const { measurementUnit, unitMultiplier } = price;
46
+ const minPrice = exports.getMinPrice(price);
47
+ let value;
48
+ if ([entities_1.MeasurementUnitEnum.KG, entities_1.MeasurementUnitEnum.L].includes(measurementUnit)) {
49
+ const grams = unitMultiplier * 1000;
50
+ value = (minPrice / grams) * minUnit;
51
+ }
52
+ else if ([entities_1.MeasurementUnitEnum.G, entities_1.MeasurementUnitEnum.ML].includes(measurementUnit)) {
53
+ value = (minPrice / unitMultiplier) * minUnit;
54
+ }
55
+ else {
56
+ value = minPrice * unitMultiplier;
57
+ }
58
+ return value ? Math.round(value) : null;
59
+ };
39
60
  exports.isCheaper = (price, comparePrice) => {
40
61
  if (!exports.isValidPrice(price) || !exports.isValidPrice(comparePrice)) {
41
62
  return null;
42
63
  }
43
64
  const minPrice = exports.getMinPrice(price);
44
65
  const minComparePrice = exports.getMinPrice(comparePrice);
66
+ if (exports.hasMeasurementUnitMultiplier(price) && exports.hasMeasurementUnitMultiplier(comparePrice)) {
67
+ const minPriceWithMeasurementUnit = exports.getPriceByMeasurementUnitMultiplier(price);
68
+ const comparePriceWithMeasurementUnit = exports.getPriceByMeasurementUnitMultiplier(comparePrice);
69
+ if (minPriceWithMeasurementUnit && comparePriceWithMeasurementUnit) {
70
+ return minPriceWithMeasurementUnit < comparePriceWithMeasurementUnit;
71
+ }
72
+ }
45
73
  return minPrice < minComparePrice;
46
74
  };
47
75
  //# sourceMappingURL=price-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"price-utils.js","sourceRoot":"/","sources":["utils/price-utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmD;AAGtC,QAAA,iBAAiB,GAAG,CAAC,MAAa,EAAE,OAAc,EAAW,EAAE,CAAC,MAAM,IAAI,OAAO,IAAI,gBAAO,CACvG,eAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,EAAE,iBAAQ,CAAC,EACjH,eAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,O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CAAC,yBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;AAE3E,QAAA,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IAClD,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,EAAE;QACpB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC;QAExF,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,yBAAiB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC;AAEW,QAAA,SAAS,GAAG,CAAC,KAAY,EAAE,YAAmB,EAAkB,EAAE;IAC7E,IAAI,CAAC,oBAAY,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAY,CAAC,YAAY,CAAC,EAAE;QACvD,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAG,mBAAW,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,eAAe,GAAG,mBAAW,CAAC,YAAY,CAAC,CAAC;IAElD,OAAO,QAAQ,GAAG,eAAe,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import { identity, isEqual, pickBy } from 'lodash';\nimport { Price } from '../entities';\n\nexport const checkIfSamePrices = (_price: Price, _price2: Price): boolean => _price && _price2 && isEqual(\n pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, identity),\n pickBy({ normalPrice: _price2.normalPrice, offerPrice: _price2.offerPrice, cardPrice: _price2.cardPrice }, identity),\n);\n\nexport const isValidPrice = (price: Price): boolean => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));\n\nexport const removeZeroPrices = (price:Price): Price => {\n const removedZeroesPrice = price;\n\n if (!price.cardPrice) {\n delete removedZeroesPrice.cardPrice;\n }\n\n if (!price.normalPrice) {\n delete removedZeroesPrice.normalPrice;\n }\n\n if (!price.offerPrice) {\n delete removedZeroesPrice.offerPrice;\n }\n\n return removedZeroesPrice;\n};\n\nexport const getPriceOperation = (price: Price, fn: (...p) => number): number => {\n if (!price) {\n return null;\n }\n\n const arr = [price.normalPrice, price.offerPrice, price.cardPrice].filter((v) => v);\n if (arr.length === 0) {\n return null;\n }\n\n return fn(...arr);\n};\n\nexport const getMinPrice = (price: Price): number => getPriceOperation(price, Math.min);\n\nexport const getMaxPrice = (price: Price): number => getPriceOperation(price, Math.max);\n\nexport const getAvgPrice = (price: Price): number => {\n const fn = (...arr) => {\n const sum = arr.reduce(((previousValue, currentValue) => previousValue + currentValue));\n\n return (sum / arr.length);\n };\n\n return getPriceOperation(price, fn);\n};\n\nexport const isCheaper = (price: Price, comparePrice: Price): boolean | null => {\n if (!isValidPrice(price) || !isValidPrice(comparePrice)) {\n return null;\n }\n\n const minPrice = getMinPrice(price);\n const minComparePrice = getMinPrice(comparePrice);\n\n return minPrice < minComparePrice;\n};\n"]}
1
+ {"version":3,"file":"price-utils.js","sourceRoot":"/","sources":["utils/price-utils.ts"],"names":[],"mappings":";;;AAAA,mCAAmD;AACnD,0CAAyD;AAE5C,QAAA,4BAA4B,GAAG,CAAC,KAAY,EAAW,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC,cAAc,IAAI,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;AAEvH,QAAA,iBAAiB,GAAG,CAAC,MAAa,EAAE,OAAc,EAAW,EAAE,CAAC,MAAM,IAAI,OAAO,IAAI,gBAAO,CACvG,eAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,EAAE,iBAAQ,CAAC,EACjH,eAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,OAA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Ac,CAAC;KACnC;IAED,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1C,CAAC,CAAC;AAEW,QAAA,SAAS,GAAG,CAAC,KAAY,EAAE,YAAmB,EAAkB,EAAE;IAC7E,IAAI,CAAC,oBAAY,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAY,CAAC,YAAY,CAAC,EAAE;QACvD,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAG,mBAAW,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,eAAe,GAAG,mBAAW,CAAC,YAAY,CAAC,CAAC;IAElD,IAAI,oCAA4B,CAAC,KAAK,CAAC,IAAI,oCAA4B,CAAC,YAAY,CAAC,EAAE;QACrF,MAAM,2BAA2B,GAAG,2CAAmC,CAAC,KAAK,CAAC,CAAC;QAC/E,MAAM,+BAA+B,GAAG,2CAAmC,CAAC,YAAY,CAAC,CAAC;QAE1F,IAAI,2BAA2B,IAAI,+BAA+B,EAAE;YAClE,OAAO,2BAA2B,GAAG,+BAA+B,CAAC;SACtE;KACF;IAED,OAAO,QAAQ,GAAG,eAAe,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import { identity, isEqual, pickBy } from 'lodash';\nimport { MeasurementUnitEnum, Price } from '../entities';\n\nexport const hasMeasurementUnitMultiplier = (price: Price): boolean => !!price && !!price.unitMultiplier && !!price.measurementUnit;\n\nexport const checkIfSamePrices = (_price: Price, _price2: Price): boolean => _price && _price2 && isEqual(\n pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, identity),\n pickBy({ normalPrice: _price2.normalPrice, offerPrice: _price2.offerPrice, cardPrice: _price2.cardPrice }, identity),\n);\n\nexport const isValidPrice = (price: Price): boolean => !(!price || (!price.normalPrice && !price.cardPrice && !price.offerPrice));\n\nexport const removeZeroPrices = (price:Price): Price => {\n const removedZeroesPrice = price;\n\n if (!price.cardPrice) {\n delete removedZeroesPrice.cardPrice;\n }\n\n if (!price.normalPrice) {\n delete removedZeroesPrice.normalPrice;\n }\n\n if (!price.offerPrice) {\n delete removedZeroesPrice.offerPrice;\n }\n\n return removedZeroesPrice;\n};\n\nexport const getPriceOperation = (price: Price, fn: (...p) => number): number => {\n if (!price) {\n return null;\n }\n\n const arr = [price.normalPrice, price.offerPrice, price.cardPrice].filter((v) => v);\n if (arr.length === 0) {\n return null;\n }\n\n return fn(...arr);\n};\n\nexport const getMinPrice = (price: Price): number => getPriceOperation(price, Math.min);\n\nexport const getMaxPrice = (price: Price): number => getPriceOperation(price, Math.max);\n\nexport const getAvgPrice = (price: Price): number => {\n const fn = (...arr) => {\n const sum = arr.reduce(((previousValue, currentValue) => previousValue + currentValue));\n\n return (sum / arr.length);\n };\n\n return getPriceOperation(price, fn);\n};\n\nexport const getPriceByMeasurementUnitMultiplier = (price: Price, minUnit = 100): number => {\n if (!hasMeasurementUnitMultiplier(price)) {\n return null;\n }\n\n const { measurementUnit, unitMultiplier } = price;\n\n const minPrice = getMinPrice(price);\n\n let value;\n if ([MeasurementUnitEnum.KG, MeasurementUnitEnum.L].includes(measurementUnit)) {\n const grams = unitMultiplier * 1000;\n value = (minPrice / grams) * minUnit;\n } else if ([MeasurementUnitEnum.G, MeasurementUnitEnum.ML].includes(measurementUnit)) {\n value = (minPrice / unitMultiplier) * minUnit;\n } else {\n value = minPrice * unitMultiplier;\n }\n\n return value ? Math.round(value) : null;\n};\n\nexport const isCheaper = (price: Price, comparePrice: Price): boolean | null => {\n if (!isValidPrice(price) || !isValidPrice(comparePrice)) {\n return null;\n }\n\n const minPrice = getMinPrice(price);\n const minComparePrice = getMinPrice(comparePrice);\n\n if (hasMeasurementUnitMultiplier(price) && hasMeasurementUnitMultiplier(comparePrice)) {\n const minPriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(price);\n const comparePriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(comparePrice);\n\n if (minPriceWithMeasurementUnit && comparePriceWithMeasurementUnit) {\n return minPriceWithMeasurementUnit < comparePriceWithMeasurementUnit;\n }\n }\n\n return minPrice < minComparePrice;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "store-scrapper-js-common",
3
- "version": "1.0.71",
3
+ "version": "1.0.75",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,22 @@
1
+ import { Column, Entity, Index } from 'typeorm';
2
+ import { IsEnum } from 'class-validator';
3
+ import { AbstractBase } from './abstract-base';
4
+ import { CATEGORY_ENUM } from './keyword';
5
+
6
+ @Entity({ name: 'categories' })
7
+ export class CategoryEntity extends AbstractBase {
8
+ @Index()
9
+ @Column()
10
+ @IsEnum(CATEGORY_ENUM)
11
+ category: CATEGORY_ENUM;
12
+
13
+ @Column()
14
+ displayName?: {
15
+ es?: string;
16
+ en?: string;
17
+ br?: string;
18
+ }
19
+
20
+ @Column({ default: true, type: 'boolean' })
21
+ enabled = true;
22
+ }
@@ -2,9 +2,13 @@ import { Entity } from 'typeorm';
2
2
  import { AbstractBase } from './abstract-base';
3
3
  import { ObjectLiteral } from '../classes';
4
4
  import { Product } from './product';
5
+ import { CATEGORY_ENUM } from './keyword';
5
6
 
6
- @Entity({ name: 'categories' })
7
+ // Mucho webeo cambiarle el nombre a todas las clases..
8
+ @Entity({ name: 'categoryMenus' })
7
9
  export class Category extends AbstractBase {
10
+ category?: CATEGORY_ENUM;
11
+
8
12
  name?: string;
9
13
 
10
14
  path?: string;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  Product, UpdateReasonEnum, CurrencyEnum, ProductAttributes, ConditionalPrice,
6
6
  } from './product';
7
- import { Price } from './price';
7
+ import { Price, MeasurementUnitEnum } from './price';
8
8
  import { Category } from './category';
9
9
  import { AbstractBase } from './abstract-base';
10
10
  import {
@@ -12,13 +12,15 @@ import {
12
12
  } from './keyword';
13
13
  import { User } from './user';
14
14
  import { AlertConditions } from './alert-conditions';
15
+ import { PricesStats } from './prices-stats';
16
+ import { CategoryEntity } from './category-entity';
15
17
 
16
18
  export const Entities = [
17
19
  Store, Product, Price, Keyword, User,
18
20
  ];
19
21
 
20
22
  export {
21
- Store, Product, Price, Category, AbstractBase, Keyword, CONDITION_FIELD_ENUM,
23
+ Store, Product, Price, Category, CategoryEntity, AbstractBase, Keyword, CONDITION_FIELD_ENUM,
22
24
  CONDITION_ENUM, CATEGORY_ENUM, User, AlertConditions, StoreQueueConfig, CountryEnum, PriorityEnum,
23
- CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes,
25
+ CurrencyEnum, UpdateReasonEnum, ConditionalPrice, ProductAttributes, MeasurementUnitEnum, PricesStats,
24
26
  };
@@ -4,6 +4,14 @@ import {
4
4
  import { IsNotEmpty, IsNumber, IsOptional } from 'class-validator';
5
5
  import { AbstractBase } from './abstract-base';
6
6
 
7
+ export enum MeasurementUnitEnum {
8
+ KG = 'kg',
9
+ G = 'g',
10
+ L = 'l',
11
+ ML = 'ml',
12
+ UNIT = 'unit'
13
+ }
14
+
7
15
  @Entity({ name: 'prices' })
8
16
  export class Price extends AbstractBase {
9
17
  @Column()
@@ -30,6 +38,14 @@ export class Price extends AbstractBase {
30
38
  @IsOptional()
31
39
  sourceUrl?: string;
32
40
 
41
+ @Column()
42
+ @IsOptional()
43
+ unitMultiplier?: number;
44
+
45
+ @Column()
46
+ @IsOptional()
47
+ measurementUnit?: MeasurementUnitEnum;
48
+
33
49
  @CreateDateColumn()
34
50
  @Index()
35
51
  createdAt?: Date;
@@ -13,6 +13,7 @@ export enum CurrencyEnum {
13
13
  CMR_PTS = 'cmr_pts',
14
14
  PARIS_PTS = 'paris_pts',
15
15
  RIPLEY_PTS = 'ripley_pts',
16
+ GENERAL_POINTS = 'general_pts',
16
17
  BRL = 'brl',
17
18
  PEN = 'PEN',
18
19
  ARS = 'ars',
@@ -22,6 +23,7 @@ export enum CurrencyEnum {
22
23
  export enum UpdateReasonEnum {
23
24
  TIME = 'time',
24
25
  NEW_PRICE = 'new_price',
26
+ NEW_CONDITIONAL_PRICE = 'new_conditional_price',
25
27
  NEW_NAME = 'new_name',
26
28
  NEW_LISTING = 'new_listing',
27
29
  MISSING_DATA = 'missing_data',
@@ -42,8 +44,9 @@ export interface ProductAttributes {
42
44
 
43
45
  export interface ConditionalPrice {
44
46
  minAmount?: number;
45
- price?: number;
47
+ price?:number;
46
48
  cardRequired?: boolean;
49
+ createdAt?: Date;
47
50
  }
48
51
 
49
52
  @Entity({ name: 'products' })
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  checkIfSamePrices, isCheaper, getMinPrice, isValidPrice, getAvgPrice, getMaxPrice, getPriceOperation, removeZeroPrices,
3
+ hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier,
3
4
  } from './price-utils';
4
5
  import { findLastQuery } from './entity-queries-utils';
5
6
  import {
@@ -14,7 +15,7 @@ import {
14
15
  } from './number-utils';
15
16
 
16
17
  export {
17
- checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne,
18
+ checkIfSamePrices, findLastQuery, replaceMultipleSpacesByOne, hasMeasurementUnitMultiplier, getPriceByMeasurementUnitMultiplier,
18
19
  removeIfEndsWith, getLastAfter, includesStringArray, removeNewLines, reverseString, getParam, getPathname,
19
20
  getHostname, isUrl, isValidPrice, getMinPrice, isCheaper, getMaxPrice, getPriceOperation, getAvgPrice, calculateAverage,
20
21
  roundNumber, removeZeroPrices,
@@ -1,5 +1,7 @@
1
1
  import { identity, isEqual, pickBy } from 'lodash';
2
- import { Price } from '../entities';
2
+ import { MeasurementUnitEnum, Price } from '../entities';
3
+
4
+ export const hasMeasurementUnitMultiplier = (price: Price): boolean => !!price && !!price.unitMultiplier && !!price.measurementUnit;
3
5
 
4
6
  export const checkIfSamePrices = (_price: Price, _price2: Price): boolean => _price && _price2 && isEqual(
5
7
  pickBy({ normalPrice: _price.normalPrice, offerPrice: _price.offerPrice, cardPrice: _price.cardPrice }, identity),
@@ -53,6 +55,28 @@ export const getAvgPrice = (price: Price): number => {
53
55
  return getPriceOperation(price, fn);
54
56
  };
55
57
 
58
+ export const getPriceByMeasurementUnitMultiplier = (price: Price, minUnit = 100): number => {
59
+ if (!hasMeasurementUnitMultiplier(price)) {
60
+ return null;
61
+ }
62
+
63
+ const { measurementUnit, unitMultiplier } = price;
64
+
65
+ const minPrice = getMinPrice(price);
66
+
67
+ let value;
68
+ if ([MeasurementUnitEnum.KG, MeasurementUnitEnum.L].includes(measurementUnit)) {
69
+ const grams = unitMultiplier * 1000;
70
+ value = (minPrice / grams) * minUnit;
71
+ } else if ([MeasurementUnitEnum.G, MeasurementUnitEnum.ML].includes(measurementUnit)) {
72
+ value = (minPrice / unitMultiplier) * minUnit;
73
+ } else {
74
+ value = minPrice * unitMultiplier;
75
+ }
76
+
77
+ return value ? Math.round(value) : null;
78
+ };
79
+
56
80
  export const isCheaper = (price: Price, comparePrice: Price): boolean | null => {
57
81
  if (!isValidPrice(price) || !isValidPrice(comparePrice)) {
58
82
  return null;
@@ -61,5 +85,14 @@ export const isCheaper = (price: Price, comparePrice: Price): boolean | null =>
61
85
  const minPrice = getMinPrice(price);
62
86
  const minComparePrice = getMinPrice(comparePrice);
63
87
 
88
+ if (hasMeasurementUnitMultiplier(price) && hasMeasurementUnitMultiplier(comparePrice)) {
89
+ const minPriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(price);
90
+ const comparePriceWithMeasurementUnit = getPriceByMeasurementUnitMultiplier(comparePrice);
91
+
92
+ if (minPriceWithMeasurementUnit && comparePriceWithMeasurementUnit) {
93
+ return minPriceWithMeasurementUnit < comparePriceWithMeasurementUnit;
94
+ }
95
+ }
96
+
64
97
  return minPrice < minComparePrice;
65
98
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
- checkIfSamePrices, Price, getMinPrice, isCheaper, removeZeroPrices,
2
+ checkIfSamePrices, Price, getMinPrice, isCheaper, removeZeroPrices, hasMeasurementUnitMultiplier,
3
+ getAvgPrice, getMaxPrice, getPriceByMeasurementUnitMultiplier,
4
+ isValidPrice,
3
5
  } from '../../src';
4
- import { getAvgPrice, getMaxPrice } from '../../src/utils/price-utils';
5
- import { isValidPrice } from '../../dist';
6
6
 
7
7
  describe('price utils tests', () => {
8
8
  it('should check if both Prices objects are equal', () => {
@@ -56,6 +56,81 @@ describe('price utils tests', () => {
56
56
  expect(isCheaper(<Price>{ offerPrice: 2, cardPrice: 1 }, <Price>{ normalPrice: 2 })).toStrictEqual(true);
57
57
  });
58
58
 
59
+ it('should return true if price is cheaper than comparing price using measurement unit', () => {
60
+ expect.hasAssertions();
61
+
62
+ // Real example from Santa Isabel
63
+ expect(isCheaper(
64
+ <Price>{ measurementUnit: 'kg', unitMultiplier: 0.1, normalPrice: 720 },
65
+ <Price>{ measurementUnit: 'kg', unitMultiplier: 1.0, normalPrice: 7196 },
66
+ )).toStrictEqual(false);
67
+
68
+ expect(isCheaper(
69
+ <Price>{ normalPrice: 100, unitMultiplier: 0.1, measurementUnit: 'kg' },
70
+ <Price>{ offerPrice: 1000, unitMultiplier: 1, measurementUnit: 'kg' },
71
+ )).toStrictEqual(false);
72
+
73
+ expect(isCheaper(
74
+ <Price>{
75
+ normalPrice: 100, offerPrice: 2, unitMultiplier: 0.1, measurementUnit: 'kg',
76
+ },
77
+ <Price>{
78
+ cardPrice: 1, offerPrice: 1000, unitMultiplier: 1, measurementUnit: 'kg',
79
+ },
80
+ )).toStrictEqual(false);
81
+
82
+ expect(isCheaper(
83
+ <Price>{ normalPrice: 100, unitMultiplier: 1, measurementUnit: 'kg' },
84
+ <Price>{ cardPrice: 900, unitMultiplier: 1, measurementUnit: 'kg' },
85
+ )).toStrictEqual(true);
86
+
87
+ expect(isCheaper(<Price>{ normalPrice: 100, unitMultiplier: 0.1, measurementUnit: 'kg' },
88
+ <Price>{
89
+ cardPrice: 150, offerPrice: 300, unitMultiplier: 0.1, measurementUnit: 'kg',
90
+ })).toStrictEqual(true);
91
+
92
+ expect(isCheaper(
93
+ <Price>{ normalPrice: 90, unitMultiplier: 0.1, measurementUnit: 'kg' },
94
+ <Price>{ cardPrice: 1000, unitMultiplier: 1, measurementUnit: 'kg' },
95
+ )).toStrictEqual(true);
96
+
97
+ // Second item without measurementUnit nor unitMultiplier
98
+ expect(isCheaper(
99
+ <Price>{ normalPrice: 100, unitMultiplier: 0.1, measurementUnit: 'kg' },
100
+ <Price>{ offerPrice: 1000 },
101
+ )).toStrictEqual(true);
102
+ });
103
+
104
+ it('should return true if price have measurement unit and multiplier', () => {
105
+ expect.hasAssertions();
106
+
107
+ expect(hasMeasurementUnitMultiplier(null)).toStrictEqual(false);
108
+ expect(hasMeasurementUnitMultiplier(<Price>{ })).toStrictEqual(false);
109
+ expect(hasMeasurementUnitMultiplier(<Price>{ unitMultiplier: 1 })).toStrictEqual(false);
110
+ expect(hasMeasurementUnitMultiplier(<Price>{ measurementUnit: 'kg' })).toStrictEqual(false);
111
+
112
+ expect(hasMeasurementUnitMultiplier(<Price>{ unitMultiplier: 1, measurementUnit: 'kg' })).toStrictEqual(true);
113
+ });
114
+
115
+ it('should return minimum price unit using measurement unit and unit multiplier', () => {
116
+ expect.hasAssertions();
117
+
118
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{})).toBeNull();
119
+
120
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 1000, unitMultiplier: 1, measurementUnit: 'unit' })).toStrictEqual(1000);
121
+
122
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 120000, unitMultiplier: 1.2, measurementUnit: 'kg' })).toStrictEqual(10000);
123
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 100000, unitMultiplier: 1.0, measurementUnit: 'kg' })).toStrictEqual(10000);
124
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 10000, unitMultiplier: 0.1, measurementUnit: 'kg' })).toStrictEqual(10000);
125
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 20000, unitMultiplier: 0.2, measurementUnit: 'kg' })).toStrictEqual(10000);
126
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 1000, unitMultiplier: 100, measurementUnit: 'g' })).toStrictEqual(1000);
127
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 100, unitMultiplier: 10, measurementUnit: 'g' })).toStrictEqual(1000);
128
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 10, unitMultiplier: 1, measurementUnit: 'g' })).toStrictEqual(1000);
129
+
130
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 10000, unitMultiplier: 0.1, measurementUnit: 'l' })).toStrictEqual(10000);
131
+ expect(getPriceByMeasurementUnitMultiplier(<Price>{ normalPrice: 1000, unitMultiplier: 100, measurementUnit: 'ml' })).toStrictEqual(1000);
132
+ });
133
+
59
134
  it('should remove prices with value of 0', () => {
60
135
  expect.hasAssertions();
61
136