@rafikidota/cuba-ofertas-scraping 0.47.1 → 0.48.0
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.
- package/dist/common/class/category.d.ts +4 -4
- package/dist/common/class/category.js.map +1 -1
- package/dist/common/class/image.d.ts +3 -3
- package/dist/common/class/image.js.map +1 -1
- package/dist/common/class/municipality.d.ts +5 -4
- package/dist/common/class/municipality.js.map +1 -1
- package/dist/common/class/product.d.ts +25 -29
- package/dist/common/class/product.js +0 -1
- package/dist/common/class/product.js.map +1 -1
- package/dist/common/class/provider.d.ts +3 -3
- package/dist/common/class/provider.js.map +1 -1
- package/dist/common/class/province.d.ts +5 -4
- package/dist/common/class/province.js.map +1 -1
- package/dist/common/enum/event.enum.d.ts +5 -0
- package/dist/common/enum/event.enum.js +5 -0
- package/dist/common/enum/event.enum.js.map +1 -1
- package/dist/common/interface/category.interface.d.ts +1 -1
- package/dist/common/interface/image.interface.d.ts +1 -1
- package/dist/common/interface/product.interface.d.ts +1 -1
- package/dist/common/interface/provider.interface.d.ts +1 -1
- package/dist/modules/repository/entity.repository.service.d.ts +28 -0
- package/dist/modules/repository/entity.repository.service.js +97 -0
- package/dist/modules/repository/entity.repository.service.js.map +1 -0
- package/dist/modules/repository/repository.service.d.ts +12 -5
- package/dist/modules/repository/repository.service.js +19 -10
- package/dist/modules/repository/repository.service.js.map +1 -1
- package/dist/modules/repository/services/category.repository.service.d.ts +9 -8
- package/dist/modules/repository/services/category.repository.service.js +17 -45
- package/dist/modules/repository/services/category.repository.service.js.map +1 -1
- package/dist/modules/repository/services/image.repository.service.d.ts +9 -8
- package/dist/modules/repository/services/image.repository.service.js +17 -45
- package/dist/modules/repository/services/image.repository.service.js.map +1 -1
- package/dist/modules/repository/services/product.repository.service.d.ts +9 -8
- package/dist/modules/repository/services/product.repository.service.js +17 -45
- package/dist/modules/repository/services/product.repository.service.js.map +1 -1
- package/dist/modules/repository/services/provider.repository.service.d.ts +9 -8
- package/dist/modules/repository/services/provider.repository.service.js +17 -45
- package/dist/modules/repository/services/provider.repository.service.js.map +1 -1
- package/dist/modules/repository/services/province.repository.service.d.ts +9 -8
- package/dist/modules/repository/services/province.repository.service.js +17 -45
- package/dist/modules/repository/services/province.repository.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ICategory } from '../interface/category.interface';
|
|
2
2
|
export declare class Category {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly parentId?: string;
|
|
7
7
|
constructor(data: ICategory);
|
|
8
8
|
update(data: Partial<ICategory>): void;
|
|
9
9
|
getData(): ICategory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.js","sourceRoot":"","sources":["../../../src/common/class/category.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAMnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"category.js","sourceRoot":"","sources":["../../../src/common/class/category.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAMnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,IAAwB;QACpC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAA4B,CAAC;IACtC,CAAC;CACF;AAjBD,4BAiBC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IImage } from '../interface/image.interface';
|
|
2
2
|
export declare class Image {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly url: string;
|
|
6
6
|
constructor(data: IImage);
|
|
7
7
|
update(data: Partial<IImage>): void;
|
|
8
8
|
getData(): IImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/common/class/image.ts"],"names":[],"mappings":";;;AAEA,MAAa,KAAK;IAKhB,YAAY,IAAY;QACtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/common/class/image.ts"],"names":[],"mappings":";;;AAEA,MAAa,KAAK;IAKhB,YAAY,IAAY;QACtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,IAAqB;QACjC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAAyB,CAAC;IACnC,CAAC;CACF;AAhBD,sBAgBC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IMunicipality } from '../interface/municipality.interface';
|
|
2
|
+
import { IProvince } from '../interface/province.interface';
|
|
2
3
|
export declare class Municipality {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly province?: IProvince;
|
|
7
|
+
readonly hasProducts?: boolean;
|
|
7
8
|
constructor(data: IMunicipality);
|
|
8
9
|
update(data: IMunicipality): void;
|
|
9
10
|
getData(): IMunicipality;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"municipality.js","sourceRoot":"","sources":["../../../src/common/class/municipality.ts"],"names":[],"mappings":";;;AAGA,MAAa,YAAY;IAMvB,YAAY,IAAmB;QAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"municipality.js","sourceRoot":"","sources":["../../../src/common/class/municipality.ts"],"names":[],"mappings":";;;AAGA,MAAa,YAAY;IAMvB,YAAY,IAAmB;QAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,IAAmB;QAC/B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAAgC,CAAC;IAC1C,CAAC;CACF;AAjBD,oCAiBC"}
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import { IProduct } from '../interface/product.interface';
|
|
2
2
|
export declare class Product {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly currentPrice: number;
|
|
8
|
+
readonly oldPrice: number;
|
|
9
|
+
readonly currency: string;
|
|
10
|
+
readonly categories: string[];
|
|
11
|
+
readonly mainCategory: string;
|
|
12
|
+
readonly image: string;
|
|
13
|
+
readonly extraImages: string[];
|
|
14
|
+
readonly manufacturer: string;
|
|
15
|
+
readonly provider: string;
|
|
16
|
+
readonly provinces: string[];
|
|
17
|
+
readonly freeShipping: boolean;
|
|
18
|
+
readonly orders: number;
|
|
19
|
+
readonly rating: number;
|
|
20
|
+
readonly reviewsCount: number;
|
|
21
|
+
readonly stockQuantity: number;
|
|
22
|
+
readonly priceByWeight: number;
|
|
23
|
+
readonly currencyPriceByWeight: number;
|
|
24
|
+
readonly weightUnit: number;
|
|
25
|
+
readonly buyPrice: number;
|
|
26
|
+
readonly classification: string;
|
|
27
|
+
readonly slug: string;
|
|
28
28
|
constructor(data: IProduct);
|
|
29
29
|
update(data: IProduct): void;
|
|
30
30
|
getData(): IProduct;
|
|
31
31
|
}
|
|
32
|
-
export type ProductRating = {
|
|
33
|
-
rating: number;
|
|
34
|
-
reviews: number;
|
|
35
|
-
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/common/class/product.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;IAqClB,YAAY,IAAc;QA/
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../../src/common/class/product.ts"],"names":[],"mappings":";;;AAEA,MAAa,OAAO;IAqClB,YAAY,IAAc;QA/BV,aAAQ,GAAW,CAAC,CAAC;QACrB,aAAQ,GAAW,KAAK,CAAC;QAEzB,eAAU,GAAa,EAAE,CAAC;QAI1B,gBAAW,GAAa,EAAE,CAAC;QAK3B,cAAS,GAAa,EAAE,CAAC;QACzB,iBAAY,GAAY,KAAK,CAAC;QAE9B,WAAM,GAAW,CAAC,CAAC;QACnB,WAAM,GAAW,CAAC,CAAC;QACnB,iBAAY,GAAW,CAAC,CAAC;QAEzB,kBAAa,GAAW,CAAC,CAAC;QAE1B,kBAAa,GAAW,CAAC,CAAC;QAE1B,0BAAqB,GAAW,CAAC,CAAC;QAClC,eAAU,GAAW,CAAC,CAAC;QACvB,aAAQ,GAAW,CAAC,CAAC;QAOnC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,IAAc;QAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAA2B,CAAC;IACrC,CAAC;CACF;AAhDD,0BAgDC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IProvider } from '../interface/provider.interface';
|
|
2
2
|
export declare class Provider {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly url: string;
|
|
6
6
|
constructor(data: IProvider);
|
|
7
7
|
update(data: IProvider): void;
|
|
8
8
|
getData(): IProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/common/class/provider.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAKnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/common/class/provider.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAKnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IACM,MAAM,CAAC,IAAe;QAC3B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IACM,OAAO;QACZ,OAAO,IAA4B,CAAC;IACtC,CAAC;CACF;AAdD,4BAcC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IProvince } from '../interface/province.interface';
|
|
2
|
+
import { Municipality } from './municipality';
|
|
2
3
|
export declare class Province {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly municipalities?: Municipality[];
|
|
7
|
+
readonly hasProducts?: boolean;
|
|
7
8
|
constructor(data: IProvince);
|
|
8
9
|
update(data: IProvince): void;
|
|
9
10
|
getData(): IProvince;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"province.js","sourceRoot":"","sources":["../../../src/common/class/province.ts"],"names":[],"mappings":";;;AAGA,MAAa,QAAQ;IAMnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;
|
|
1
|
+
{"version":3,"file":"province.js","sourceRoot":"","sources":["../../../src/common/class/province.ts"],"names":[],"mappings":";;;AAGA,MAAa,QAAQ;IAMnB,YAAY,IAAe;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,IAAe;QAC3B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEM,OAAO;QACZ,OAAO,IAA4B,CAAC;IACtC,CAAC;CACF;AAjBD,4BAiBC"}
|
|
@@ -4,6 +4,11 @@ export declare enum ScrapingEvent {
|
|
|
4
4
|
SAVE_CATEGORIES = "save.categories",
|
|
5
5
|
SAVE_PRODUCTS = "save.products",
|
|
6
6
|
SAVE_PROVIDERS = "save.providers",
|
|
7
|
+
UPDATE_PROVINCES = "update.provinces",
|
|
8
|
+
UPDATE_IMAGES = "update.images",
|
|
9
|
+
UPDATE_CATEGORIES = "update.categories",
|
|
10
|
+
UPDATE_PRODUCTS = "update.products",
|
|
11
|
+
UPDATE_PROVIDERS = "update.providers",
|
|
7
12
|
RESET = "reset",
|
|
8
13
|
SCRAPING_COMPLETED = "scraping.completed"
|
|
9
14
|
}
|
|
@@ -8,6 +8,11 @@ var ScrapingEvent;
|
|
|
8
8
|
ScrapingEvent["SAVE_CATEGORIES"] = "save.categories";
|
|
9
9
|
ScrapingEvent["SAVE_PRODUCTS"] = "save.products";
|
|
10
10
|
ScrapingEvent["SAVE_PROVIDERS"] = "save.providers";
|
|
11
|
+
ScrapingEvent["UPDATE_PROVINCES"] = "update.provinces";
|
|
12
|
+
ScrapingEvent["UPDATE_IMAGES"] = "update.images";
|
|
13
|
+
ScrapingEvent["UPDATE_CATEGORIES"] = "update.categories";
|
|
14
|
+
ScrapingEvent["UPDATE_PRODUCTS"] = "update.products";
|
|
15
|
+
ScrapingEvent["UPDATE_PROVIDERS"] = "update.providers";
|
|
11
16
|
ScrapingEvent["RESET"] = "reset";
|
|
12
17
|
ScrapingEvent["SCRAPING_COMPLETED"] = "scraping.completed";
|
|
13
18
|
})(ScrapingEvent || (exports.ScrapingEvent = ScrapingEvent = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.enum.js","sourceRoot":"","sources":["../../../src/common/enum/event.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"event.enum.js","sourceRoot":"","sources":["../../../src/common/enum/event.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAaX;AAbD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,4CAA2B,CAAA;IAC3B,oDAAmC,CAAA;IACnC,gDAA+B,CAAA;IAC/B,kDAAiC,CAAA;IACjC,sDAAqC,CAAA;IACrC,gDAA+B,CAAA;IAC/B,wDAAuC,CAAA;IACvC,oDAAmC,CAAA;IACnC,sDAAqC,CAAA;IACrC,gCAAe,CAAA;IACf,0DAAyC,CAAA;AAC3C,CAAC,EAbW,aAAa,6BAAb,aAAa,QAaxB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { FindManyOptions } from 'typeorm';
|
|
4
|
+
import { Logger } from '../../common/logger/logger';
|
|
5
|
+
interface Item<T> extends IItem {
|
|
6
|
+
getData(): Partial<T>;
|
|
7
|
+
}
|
|
8
|
+
interface IItem {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class EntityRepository<T extends IItem, K extends Item<T>> {
|
|
12
|
+
protected readonly repository: Repository<T>;
|
|
13
|
+
protected readonly config: ConfigService;
|
|
14
|
+
protected readonly key: string;
|
|
15
|
+
protected readonly label: string;
|
|
16
|
+
protected logger: Logger;
|
|
17
|
+
protected readonly logging: boolean;
|
|
18
|
+
constructor(repository: Repository<T>, config: ConfigService, key: string, label: string);
|
|
19
|
+
abstract map(entity: T): K;
|
|
20
|
+
abstract notify(entity: T): string;
|
|
21
|
+
find(options?: FindManyOptions<T>): Promise<K[]>;
|
|
22
|
+
count(options?: FindManyOptions<T>): Promise<number>;
|
|
23
|
+
create(data: Partial<T>): T;
|
|
24
|
+
_save(items: K[]): Promise<void>;
|
|
25
|
+
_update(items: K[]): Promise<void>;
|
|
26
|
+
reset(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityRepository = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const logger_1 = require("../../common/logger/logger");
|
|
6
|
+
const repository_service_1 = require("./repository.service");
|
|
7
|
+
class EntityRepository {
|
|
8
|
+
constructor(repository, config, key, label) {
|
|
9
|
+
this.repository = repository;
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.key = key;
|
|
12
|
+
this.label = label;
|
|
13
|
+
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
14
|
+
this.logging = this.config?.get(this.key) ?? false;
|
|
15
|
+
}
|
|
16
|
+
async find(options) {
|
|
17
|
+
const entities = await this.repository.find(options);
|
|
18
|
+
return entities.map((entity) => this.map(entity));
|
|
19
|
+
}
|
|
20
|
+
async count(options) {
|
|
21
|
+
return this.repository.count(options);
|
|
22
|
+
}
|
|
23
|
+
create(data) {
|
|
24
|
+
return this.repository.create(data);
|
|
25
|
+
}
|
|
26
|
+
async _save(items) {
|
|
27
|
+
try {
|
|
28
|
+
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
29
|
+
const datas = items.map((x) => x.getData()).filter((x) => x.id);
|
|
30
|
+
const identificators = datas.map((x) => x.id);
|
|
31
|
+
const query = {
|
|
32
|
+
select: ['id'],
|
|
33
|
+
where: { id: (0, typeorm_1.In)(identificators) },
|
|
34
|
+
};
|
|
35
|
+
const existing = await this.repository.find(query);
|
|
36
|
+
const map = new Map(existing.map((x) => [x.id, x]));
|
|
37
|
+
const shouldCreate = (x) => !map.has(x.id);
|
|
38
|
+
const entities = datas.filter(shouldCreate).map((x) => this.create(x));
|
|
39
|
+
if (entities?.length) {
|
|
40
|
+
await this.repository.manager.transaction(async (manager) => {
|
|
41
|
+
await manager.save(entities);
|
|
42
|
+
});
|
|
43
|
+
if (this.logging) {
|
|
44
|
+
entities.forEach((x) => this.logger.debug(`✅ ${this.notify(x)}`));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
sizes.current = sizes.previous + entities.length;
|
|
48
|
+
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
49
|
+
const { current: total } = sizes;
|
|
50
|
+
this.logger.verbose(`✅ ${total} ${this.label} saved successfully`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const { message, stack } = error;
|
|
55
|
+
this.logger.error(`🔥 Failed to save ${this.label}`);
|
|
56
|
+
this.logger.error(message);
|
|
57
|
+
this.logger.error(stack);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async _update(items) {
|
|
61
|
+
try {
|
|
62
|
+
const datas = items.map((x) => x.getData()).filter((x) => x.id);
|
|
63
|
+
const identificators = datas.map((x) => x.id);
|
|
64
|
+
const query = {
|
|
65
|
+
where: { id: (0, typeorm_1.In)(identificators) },
|
|
66
|
+
};
|
|
67
|
+
const existing = await this.repository.find(query);
|
|
68
|
+
const map = new Map(existing.map((x) => [x.id, x]));
|
|
69
|
+
const shouldUpdate = (x) => map.has(x.id);
|
|
70
|
+
const updates = datas.filter(shouldUpdate);
|
|
71
|
+
if (updates?.length) {
|
|
72
|
+
await this.repository.manager.transaction(async (manager) => {
|
|
73
|
+
await manager.save(updates);
|
|
74
|
+
});
|
|
75
|
+
const entities = await this.repository.find({
|
|
76
|
+
where: { id: (0, typeorm_1.In)(updates.map((x) => x.id)) },
|
|
77
|
+
});
|
|
78
|
+
if (this.logging) {
|
|
79
|
+
entities.forEach((x) => this.logger.debug(`🔄 ${this.notify(x)}`));
|
|
80
|
+
}
|
|
81
|
+
const message = `🔄 ${entities.length} ${this.label} updated successfully`;
|
|
82
|
+
this.logger.verbose(message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const { message, stack } = error;
|
|
87
|
+
this.logger.error(`🔥 Failed to update ${this.label}`);
|
|
88
|
+
this.logger.error(message);
|
|
89
|
+
this.logger.error(stack);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async reset() {
|
|
93
|
+
await this.repository.clear();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.EntityRepository = EntityRepository;
|
|
97
|
+
//# sourceMappingURL=entity.repository.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.repository.service.js","sourceRoot":"","sources":["../../../src/modules/repository/entity.repository.service.ts"],"names":[],"mappings":";;;AACA,qCAAsD;AAGtD,uDAAoD;AACpD,6DAAyD;AAUzD,MAAsB,gBAAgB;IAIpC,YACqB,UAAyB,EACzB,MAAqB,EACrB,GAAW,EACX,KAAa;QAHb,eAAU,GAAV,UAAU,CAAe;QACzB,WAAM,GAAN,MAAM,CAAe;QACrB,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QAPxB,WAAM,GAAG,IAAI,eAAM,CAAC,sCAAiB,CAAC,IAAI,CAAC,CAAC;QASpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,KAA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K,EAAE,CAAC;IAChC,CAAC;CACF;AApHD,4CAoHC"}
|
|
@@ -14,11 +14,18 @@ export declare class RepositoryService implements OnModuleInit, OnApplicationShu
|
|
|
14
14
|
constructor(_province: ProvinceRepositoryService, _image: ImageRepositoryService, _category: CategoryRepositoryService, _provider: ProviderRepositoryService, _product: ProductRepositoryService);
|
|
15
15
|
onModuleInit(): Promise<void>;
|
|
16
16
|
onApplicationShutdown(): Promise<void>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
get category(): CategoryRepositoryService;
|
|
18
|
+
get image(): ImageRepositoryService;
|
|
19
|
+
get product(): ProductRepositoryService;
|
|
20
|
+
get provider(): ProviderRepositoryService;
|
|
21
|
+
get province(): ProvinceRepositoryService;
|
|
22
|
+
find(): Promise<{
|
|
23
|
+
categories: import("../..").Category[];
|
|
24
|
+
images: import("../..").Image[];
|
|
25
|
+
products: import("../..").Product[];
|
|
26
|
+
providers: import("../..").Provider[];
|
|
27
|
+
provinces: import("../..").Province[];
|
|
28
|
+
}>;
|
|
22
29
|
count(): Promise<{
|
|
23
30
|
categories: number;
|
|
24
31
|
images: number;
|
|
@@ -35,20 +35,29 @@ let RepositoryService = RepositoryService_1 = class RepositoryService {
|
|
|
35
35
|
async onApplicationShutdown() {
|
|
36
36
|
await this.reset();
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
return this._category
|
|
38
|
+
get category() {
|
|
39
|
+
return this._category;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return this._image
|
|
41
|
+
get image() {
|
|
42
|
+
return this._image;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
return this._product
|
|
44
|
+
get product() {
|
|
45
|
+
return this._product;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
return this._provider
|
|
47
|
+
get provider() {
|
|
48
|
+
return this._provider;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
return this._province
|
|
50
|
+
get province() {
|
|
51
|
+
return this._province;
|
|
52
|
+
}
|
|
53
|
+
async find() {
|
|
54
|
+
return {
|
|
55
|
+
categories: await this._category.find(),
|
|
56
|
+
images: await this._image.find(),
|
|
57
|
+
products: await this._product.find(),
|
|
58
|
+
providers: await this._provider.find(),
|
|
59
|
+
provinces: await this._province.find(),
|
|
60
|
+
};
|
|
52
61
|
}
|
|
53
62
|
async count() {
|
|
54
63
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.service.js","sourceRoot":"","sources":["../../../src/modules/repository/repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,yDAAgD;AAEhD,wFAAmF;AACnF,wFAAmF;AACnF,kFAA6E;AAC7E,wFAAmF;AACnF,sFAAiF;AAEjF,uDAAoD;AACpD,6DAA6D;AAGtD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAG5B,YACmB,SAAoC,EACpC,MAA8B,EAC9B,SAAoC,EACpC,SAAoC,EACpC,QAAkC;QAJlC,cAAS,GAAT,SAAS,CAA2B;QACpC,WAAM,GAAN,MAAM,CAAwB;QAC9B,cAAS,GAAT,SAAS,CAA2B;QACpC,cAAS,GAAT,SAAS,CAA2B;QACpC,aAAQ,GAAR,QAAQ,CAA0B;QAP7C,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IAQjD,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"repository.service.js","sourceRoot":"","sources":["../../../src/modules/repository/repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,yDAAgD;AAEhD,wFAAmF;AACnF,wFAAmF;AACnF,kFAA6E;AAC7E,wF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SACvC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO;YACL,UAAU,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;YACxC,MAAM,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACjC,QAAQ,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;YACrC,SAAS,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;YACvC,SAAS,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;SACxC,CAAC;IACJ,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK;QACT,MAAM,YAAY,GAAG;YACnB,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,MAAM;YACX,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,SAAS;SACf,CAAC;QACF,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;CACF,CAAA;AAvEY,8CAAiB;AA4DtB;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,KAAK,CAAC;;;;8CAW5B;4BAtEU,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAKmB,uDAAyB;QAC5B,iDAAsB;QACnB,uDAAyB;QACzB,uDAAyB;QAC1B,qDAAwB;GAR1C,iBAAiB,CAuE7B"}
|
|
@@ -2,14 +2,15 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
3
|
import { Category } from '../../../common/class/category';
|
|
4
4
|
import { CategoryEntity } from '../entities/category.entity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { EntityRepository } from '../entity.repository.service';
|
|
6
|
+
declare const Repo: abstract new (repository: Repository<CategoryEntity>, config: ConfigService, key: string, label: string) => EntityRepository<CategoryEntity, Category>;
|
|
7
|
+
export declare class CategoryRepositoryService extends Repo {
|
|
8
|
+
protected readonly repository: Repository<CategoryEntity>;
|
|
9
|
+
protected readonly config: ConfigService;
|
|
10
10
|
constructor(repository: Repository<CategoryEntity>, config: ConfigService);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
map(entity: CategoryEntity): Category;
|
|
12
|
+
notify(entity: CategoryEntity): string;
|
|
13
13
|
save(categories: Category[]): Promise<void>;
|
|
14
|
-
|
|
14
|
+
update(categories: Category[]): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export {};
|
|
@@ -18,62 +18,28 @@ const config_1 = require("@nestjs/config");
|
|
|
18
18
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
20
|
const typeorm_2 = require("typeorm");
|
|
21
|
-
const repository_service_1 = require("../repository.service");
|
|
22
|
-
const logger_1 = require("../../../common/logger/logger");
|
|
23
21
|
const category_1 = require("../../../common/class/category");
|
|
24
22
|
const category_entity_1 = require("../entities/category.entity");
|
|
25
23
|
const event_enum_1 = require("../../../common/enum/event.enum");
|
|
26
|
-
|
|
24
|
+
const entity_repository_service_1 = require("../entity.repository.service");
|
|
25
|
+
const Repo = (entity_repository_service_1.EntityRepository);
|
|
26
|
+
let CategoryRepositoryService = class CategoryRepositoryService extends Repo {
|
|
27
27
|
constructor(repository, config) {
|
|
28
|
+
super(repository, config, 'REPOSITORY_SAVE_CATEGORY_LOG', 'categories');
|
|
28
29
|
this.repository = repository;
|
|
29
30
|
this.config = config;
|
|
30
|
-
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
31
|
-
this.logging = this.config.get('REPOSITORY_SAVE_CATEGORY_LOG');
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return entities.map((entity) => new category_1.Category(entity));
|
|
32
|
+
map(entity) {
|
|
33
|
+
return new category_1.Category(entity);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
notify(entity) {
|
|
36
|
+
return entity.name;
|
|
39
37
|
}
|
|
40
38
|
async save(categories) {
|
|
41
|
-
|
|
42
|
-
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
43
|
-
const datas = categories.map((c) => c.getData()).filter((x) => x.id);
|
|
44
|
-
const identificators = datas.map((x) => x.id);
|
|
45
|
-
const matches = await this.repository
|
|
46
|
-
.find({
|
|
47
|
-
select: ['id'],
|
|
48
|
-
where: { id: (0, typeorm_2.In)(identificators) },
|
|
49
|
-
})
|
|
50
|
-
.then((res) => new Set(res.map((x) => x.id)));
|
|
51
|
-
const entities = datas
|
|
52
|
-
.filter((x) => !matches.has(x.id))
|
|
53
|
-
.map((x) => this.repository.create(x));
|
|
54
|
-
if (entities.length > 0) {
|
|
55
|
-
await this.repository.manager.transaction(async (manager) => {
|
|
56
|
-
await manager.save(entities);
|
|
57
|
-
});
|
|
58
|
-
if (this.logging) {
|
|
59
|
-
entities.forEach((x) => this.logger.debug(`✅ ${x.name}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
sizes.current = sizes.previous + entities.length;
|
|
63
|
-
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
64
|
-
const { current: total } = sizes;
|
|
65
|
-
this.logger.verbose(`✅ ${total} categories saved successfully`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const { message, stack } = error;
|
|
70
|
-
this.logger.error('🔥 Failed to save categories');
|
|
71
|
-
this.logger.error(message);
|
|
72
|
-
this.logger.error(stack);
|
|
73
|
-
}
|
|
39
|
+
await this._save(categories);
|
|
74
40
|
}
|
|
75
|
-
async
|
|
76
|
-
await this.
|
|
41
|
+
async update(categories) {
|
|
42
|
+
await this._update(categories);
|
|
77
43
|
}
|
|
78
44
|
};
|
|
79
45
|
exports.CategoryRepositoryService = CategoryRepositoryService;
|
|
@@ -83,6 +49,12 @@ __decorate([
|
|
|
83
49
|
__metadata("design:paramtypes", [Array]),
|
|
84
50
|
__metadata("design:returntype", Promise)
|
|
85
51
|
], CategoryRepositoryService.prototype, "save", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(event_enum_1.ScrapingEvent.UPDATE_CATEGORIES),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Array]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], CategoryRepositoryService.prototype, "update", null);
|
|
86
58
|
exports.CategoryRepositoryService = CategoryRepositoryService = __decorate([
|
|
87
59
|
(0, common_1.Injectable)(),
|
|
88
60
|
__param(0, (0, typeorm_1.InjectRepository)(category_entity_1.CategoryEntity)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/category.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"category.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/category.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,qCAAqC;AAErC,6DAA0D;AAC1D,iEAA6D;AAC7D,gEAAgE;AAChE,4EAAgE;AAEhE,MAAM,IAAI,GAAG,CAAA,4CAA0C,CAAA,CAAC;AAGjD,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,IAAI;IACjD,YAEqB,UAAsC,EACtC,MAAqB;QAExC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,8BAA8B,EAAE,YAAY,CAAC,CAAC;QAHrD,eAAU,GAAV,UAAU,CAA4B;QACtC,WAAM,GAAN,MAAM,CAAe;IAG1C,CAAC;IAED,GAAG,CAAC,MAAsB;QACxB,OAAO,IAAI,mBAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAC,UAAsB;QAC/B,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAC,UAAsB;QACjC,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;CACF,CAAA;AA1BY,8DAAyB;AAkB9B;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,eAAe,CAAC;;;;qDAGtC;AAGK;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,iBAAiB,CAAC;;;;uDAGxC;oCAzBU,yBAAyB;IADrC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,gCAAc,CAAC,CAAA;qCACF,oBAAU;QACd,sBAAa;GAJ/B,yBAAyB,CA0BrC"}
|
|
@@ -2,14 +2,15 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
3
|
import { Image } from '../../../common/class/image';
|
|
4
4
|
import { ImageEntity } from '../entities/image.entity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { EntityRepository } from '../entity.repository.service';
|
|
6
|
+
declare const Repo: abstract new (repository: Repository<ImageEntity>, config: ConfigService, key: string, label: string) => EntityRepository<ImageEntity, Image>;
|
|
7
|
+
export declare class ImageRepositoryService extends Repo {
|
|
8
|
+
protected readonly repository: Repository<ImageEntity>;
|
|
9
|
+
protected readonly config: ConfigService;
|
|
10
10
|
constructor(repository: Repository<ImageEntity>, config: ConfigService);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
map(entity: ImageEntity): Image;
|
|
12
|
+
notify(entity: ImageEntity): string;
|
|
13
13
|
save(images: Image[]): Promise<void>;
|
|
14
|
-
|
|
14
|
+
update(images: Image[]): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export {};
|
|
@@ -18,62 +18,28 @@ const config_1 = require("@nestjs/config");
|
|
|
18
18
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
20
|
const typeorm_2 = require("typeorm");
|
|
21
|
-
const repository_service_1 = require("../repository.service");
|
|
22
|
-
const logger_1 = require("../../../common/logger/logger");
|
|
23
21
|
const image_1 = require("../../../common/class/image");
|
|
24
22
|
const image_entity_1 = require("../entities/image.entity");
|
|
25
23
|
const event_enum_1 = require("../../../common/enum/event.enum");
|
|
26
|
-
|
|
24
|
+
const entity_repository_service_1 = require("../entity.repository.service");
|
|
25
|
+
const Repo = (entity_repository_service_1.EntityRepository);
|
|
26
|
+
let ImageRepositoryService = class ImageRepositoryService extends Repo {
|
|
27
27
|
constructor(repository, config) {
|
|
28
|
+
super(repository, config, 'REPOSITORY_SAVE_IMAGE_LOG', 'images');
|
|
28
29
|
this.repository = repository;
|
|
29
30
|
this.config = config;
|
|
30
|
-
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
31
|
-
this.logging = this.config.get('REPOSITORY_SAVE_IMAGE_LOG');
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return entities.map((entity) => new image_1.Image(entity));
|
|
32
|
+
map(entity) {
|
|
33
|
+
return new image_1.Image(entity);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
notify(entity) {
|
|
36
|
+
return entity.name;
|
|
39
37
|
}
|
|
40
38
|
async save(images) {
|
|
41
|
-
|
|
42
|
-
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
43
|
-
const datas = images.map((c) => c.getData()).filter((x) => x.id);
|
|
44
|
-
const identificators = datas.map((x) => x.id);
|
|
45
|
-
const matches = await this.repository
|
|
46
|
-
.find({
|
|
47
|
-
select: ['id'],
|
|
48
|
-
where: { id: (0, typeorm_2.In)(identificators) },
|
|
49
|
-
})
|
|
50
|
-
.then((res) => new Set(res.map((x) => x.id)));
|
|
51
|
-
const entities = datas
|
|
52
|
-
.filter((x) => !matches.has(x.id))
|
|
53
|
-
.map((x) => this.repository.create(x));
|
|
54
|
-
if (entities.length > 0) {
|
|
55
|
-
await this.repository.manager.transaction(async (manager) => {
|
|
56
|
-
await manager.save(entities);
|
|
57
|
-
});
|
|
58
|
-
if (this.logging) {
|
|
59
|
-
entities.forEach((x) => this.logger.debug(`✅ ${x.name}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
sizes.current = sizes.previous + entities.length;
|
|
63
|
-
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
64
|
-
const { current: total } = sizes;
|
|
65
|
-
this.logger.verbose(`✅ ${total} images saved successfully`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const { message, stack } = error;
|
|
70
|
-
this.logger.error('🔥 Failed to save images');
|
|
71
|
-
this.logger.error(message);
|
|
72
|
-
this.logger.error(stack);
|
|
73
|
-
}
|
|
39
|
+
await this._save(images);
|
|
74
40
|
}
|
|
75
|
-
async
|
|
76
|
-
await this.
|
|
41
|
+
async update(images) {
|
|
42
|
+
await this._update(images);
|
|
77
43
|
}
|
|
78
44
|
};
|
|
79
45
|
exports.ImageRepositoryService = ImageRepositoryService;
|
|
@@ -83,6 +49,12 @@ __decorate([
|
|
|
83
49
|
__metadata("design:paramtypes", [Array]),
|
|
84
50
|
__metadata("design:returntype", Promise)
|
|
85
51
|
], ImageRepositoryService.prototype, "save", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(event_enum_1.ScrapingEvent.UPDATE_IMAGES),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Array]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], ImageRepositoryService.prototype, "update", null);
|
|
86
58
|
exports.ImageRepositoryService = ImageRepositoryService = __decorate([
|
|
87
59
|
(0, common_1.Injectable)(),
|
|
88
60
|
__param(0, (0, typeorm_1.InjectRepository)(image_entity_1.ImageEntity)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/image.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"image.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/image.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,qCAAqC;AAErC,uDAAoD;AACpD,2DAAuD;AACvD,gEAAgE;AAChE,4EAAgE;AAEhE,MAAM,IAAI,GAAG,CAAA,4CAAoC,CAAA,CAAC;AAG3C,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,IAAI;IAC9C,YAEqB,UAAmC,EACnC,MAAqB;QAExC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,2BAA2B,EAAE,QAAQ,CAAC,CAAC;QAH9C,eAAU,GAAV,UAAU,CAAyB;QACnC,WAAM,GAAN,MAAM,CAAe;IAG1C,CAAC;IAED,GAAG,CAAC,MAAmB;QACrB,OAAO,IAAI,aAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,MAAmB;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAC,MAAe;QACxB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAC,MAAe;QAC1B,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF,CAAA;AA1BY,wDAAsB;AAkB3B;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,WAAW,CAAC;;;;kDAGlC;AAGK;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,aAAa,CAAC;;;;oDAGpC;iCAzBU,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,0BAAW,CAAC,CAAA;qCACC,oBAAU;QACd,sBAAa;GAJ/B,sBAAsB,CA0BlC"}
|
|
@@ -2,14 +2,15 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
3
|
import { Product } from '../../../common/class/product';
|
|
4
4
|
import { ProductEntity } from '../entities/product.entity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { EntityRepository } from '../entity.repository.service';
|
|
6
|
+
declare const Repo: abstract new (repository: Repository<ProductEntity>, config: ConfigService, key: string, label: string) => EntityRepository<ProductEntity, Product>;
|
|
7
|
+
export declare class ProductRepositoryService extends Repo {
|
|
8
|
+
protected readonly repository: Repository<ProductEntity>;
|
|
9
|
+
protected readonly config: ConfigService;
|
|
10
10
|
constructor(repository: Repository<ProductEntity>, config: ConfigService);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
map(entity: ProductEntity): Product;
|
|
12
|
+
notify(entity: ProductEntity): string;
|
|
13
13
|
save(products: Product[]): Promise<void>;
|
|
14
|
-
|
|
14
|
+
update(products: Product[]): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export {};
|
|
@@ -18,62 +18,28 @@ const config_1 = require("@nestjs/config");
|
|
|
18
18
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
20
|
const typeorm_2 = require("typeorm");
|
|
21
|
-
const repository_service_1 = require("../repository.service");
|
|
22
|
-
const logger_1 = require("../../../common/logger/logger");
|
|
23
21
|
const product_1 = require("../../../common/class/product");
|
|
24
22
|
const product_entity_1 = require("../entities/product.entity");
|
|
25
23
|
const event_enum_1 = require("../../../common/enum/event.enum");
|
|
26
|
-
|
|
24
|
+
const entity_repository_service_1 = require("../entity.repository.service");
|
|
25
|
+
const Repo = (entity_repository_service_1.EntityRepository);
|
|
26
|
+
let ProductRepositoryService = class ProductRepositoryService extends Repo {
|
|
27
27
|
constructor(repository, config) {
|
|
28
|
+
super(repository, config, 'REPOSITORY_SAVE_PRODUCT_LOG', 'products');
|
|
28
29
|
this.repository = repository;
|
|
29
30
|
this.config = config;
|
|
30
|
-
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
31
|
-
this.logging = this.config.get('REPOSITORY_SAVE_PRODUCT_LOG');
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return entities.map((entity) => new product_1.Product(entity));
|
|
32
|
+
map(entity) {
|
|
33
|
+
return new product_1.Product(entity);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
notify(entity) {
|
|
36
|
+
return entity.url;
|
|
39
37
|
}
|
|
40
38
|
async save(products) {
|
|
41
|
-
|
|
42
|
-
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
43
|
-
const datas = products.map((c) => c.getData()).filter((x) => x.id);
|
|
44
|
-
const identificators = datas.map((x) => x.id);
|
|
45
|
-
const matches = await this.repository
|
|
46
|
-
.find({
|
|
47
|
-
select: ['id'],
|
|
48
|
-
where: { id: (0, typeorm_2.In)(identificators) },
|
|
49
|
-
})
|
|
50
|
-
.then((res) => new Set(res.map((x) => x.id)));
|
|
51
|
-
const entities = datas
|
|
52
|
-
.filter((x) => !matches.has(x.id))
|
|
53
|
-
.map((x) => this.repository.create(x));
|
|
54
|
-
if (entities.length > 0) {
|
|
55
|
-
await this.repository.manager.transaction(async (manager) => {
|
|
56
|
-
await manager.save(entities);
|
|
57
|
-
});
|
|
58
|
-
if (this.logging) {
|
|
59
|
-
entities.forEach((x) => this.logger.debug(`✅ ${x.url}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
sizes.current = sizes.previous + entities.length;
|
|
63
|
-
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
64
|
-
const { current: total } = sizes;
|
|
65
|
-
this.logger.verbose(`✅ ${total} products saved successfully`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const { message, stack } = error;
|
|
70
|
-
this.logger.error('🔥 Failed to save products');
|
|
71
|
-
this.logger.error(message);
|
|
72
|
-
this.logger.error(stack);
|
|
73
|
-
}
|
|
39
|
+
await this._save(products);
|
|
74
40
|
}
|
|
75
|
-
async
|
|
76
|
-
await this.
|
|
41
|
+
async update(products) {
|
|
42
|
+
await this._update(products);
|
|
77
43
|
}
|
|
78
44
|
};
|
|
79
45
|
exports.ProductRepositoryService = ProductRepositoryService;
|
|
@@ -83,6 +49,12 @@ __decorate([
|
|
|
83
49
|
__metadata("design:paramtypes", [Array]),
|
|
84
50
|
__metadata("design:returntype", Promise)
|
|
85
51
|
], ProductRepositoryService.prototype, "save", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(event_enum_1.ScrapingEvent.UPDATE_PRODUCTS),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Array]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], ProductRepositoryService.prototype, "update", null);
|
|
86
58
|
exports.ProductRepositoryService = ProductRepositoryService = __decorate([
|
|
87
59
|
(0, common_1.Injectable)(),
|
|
88
60
|
__param(0, (0, typeorm_1.InjectRepository)(product_entity_1.ProductEntity)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/product.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"product.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/product.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,qCAAqC;AAErC,2DAAwD;AACxD,+DAA2D;AAC3D,gEAAgE;AAChE,4EAAgE;AAEhE,MAAM,IAAI,GAAG,CAAA,4CAAwC,CAAA,CAAC;AAG/C,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,IAAI;IAChD,YAEqB,UAAqC,EACrC,MAAqB;QAExC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,6BAA6B,EAAE,UAAU,CAAC,CAAC;QAHlD,eAAU,GAAV,UAAU,CAA2B;QACrC,WAAM,GAAN,MAAM,CAAe;IAG1C,CAAC;IAED,GAAG,CAAC,MAAqB;QACvB,OAAO,IAAI,iBAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,MAAqB;QAC1B,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAC,QAAmB;QAC5B,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAC,QAAmB;QAC9B,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AA1BY,4DAAwB;AAkB7B;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,aAAa,CAAC;;;;oDAGpC;AAGK;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,eAAe,CAAC;;;;sDAGtC;mCAzBU,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,8BAAa,CAAC,CAAA;qCACD,oBAAU;QACd,sBAAa;GAJ/B,wBAAwB,CA0BpC"}
|
|
@@ -2,14 +2,15 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
3
|
import { Provider } from '../../../common/class/provider';
|
|
4
4
|
import { ProviderEntity } from '../entities/provider.entity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { EntityRepository } from '../entity.repository.service';
|
|
6
|
+
declare const Repo: abstract new (repository: Repository<ProviderEntity>, config: ConfigService, key: string, label: string) => EntityRepository<ProviderEntity, Provider>;
|
|
7
|
+
export declare class ProviderRepositoryService extends Repo {
|
|
8
|
+
protected readonly repository: Repository<ProviderEntity>;
|
|
9
|
+
protected readonly config: ConfigService;
|
|
10
10
|
constructor(repository: Repository<ProviderEntity>, config: ConfigService);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
map(entity: ProviderEntity): Provider;
|
|
12
|
+
notify(entity: ProviderEntity): string;
|
|
13
13
|
save(providers: Provider[]): Promise<void>;
|
|
14
|
-
|
|
14
|
+
update(providers: Provider[]): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export {};
|
|
@@ -18,62 +18,28 @@ const config_1 = require("@nestjs/config");
|
|
|
18
18
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
20
|
const typeorm_2 = require("typeorm");
|
|
21
|
-
const repository_service_1 = require("../repository.service");
|
|
22
|
-
const logger_1 = require("../../../common/logger/logger");
|
|
23
21
|
const provider_1 = require("../../../common/class/provider");
|
|
24
22
|
const provider_entity_1 = require("../entities/provider.entity");
|
|
25
23
|
const event_enum_1 = require("../../../common/enum/event.enum");
|
|
26
|
-
|
|
24
|
+
const entity_repository_service_1 = require("../entity.repository.service");
|
|
25
|
+
const Repo = (entity_repository_service_1.EntityRepository);
|
|
26
|
+
let ProviderRepositoryService = class ProviderRepositoryService extends Repo {
|
|
27
27
|
constructor(repository, config) {
|
|
28
|
+
super(repository, config, 'REPOSITORY_SAVE_PROVIDER_LOG', 'providers');
|
|
28
29
|
this.repository = repository;
|
|
29
30
|
this.config = config;
|
|
30
|
-
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
31
|
-
this.logging = this.config.get('REPOSITORY_SAVE_PROVIDER_LOG');
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return entities.map((entity) => new provider_1.Provider(entity));
|
|
32
|
+
map(entity) {
|
|
33
|
+
return new provider_1.Provider(entity);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
notify(entity) {
|
|
36
|
+
return entity.name;
|
|
39
37
|
}
|
|
40
38
|
async save(providers) {
|
|
41
|
-
|
|
42
|
-
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
43
|
-
const datas = providers.map((c) => c.getData()).filter((x) => x.id);
|
|
44
|
-
const identificators = datas.map((x) => x.id);
|
|
45
|
-
const matches = await this.repository
|
|
46
|
-
.find({
|
|
47
|
-
select: ['id'],
|
|
48
|
-
where: { id: (0, typeorm_2.In)(identificators) },
|
|
49
|
-
})
|
|
50
|
-
.then((res) => new Set(res.map((x) => x.id)));
|
|
51
|
-
const entities = datas
|
|
52
|
-
.filter((x) => !matches.has(x.id))
|
|
53
|
-
.map((x) => this.repository.create(x));
|
|
54
|
-
if (entities.length > 0) {
|
|
55
|
-
await this.repository.manager.transaction(async (manager) => {
|
|
56
|
-
await manager.save(entities);
|
|
57
|
-
});
|
|
58
|
-
if (this.logging) {
|
|
59
|
-
entities.forEach((x) => this.logger.debug(`✅ ${x.name}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
sizes.current = sizes.previous + entities.length;
|
|
63
|
-
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
64
|
-
const { current: total } = sizes;
|
|
65
|
-
this.logger.verbose(`✅ ${total} providers saved successfully`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const { message, stack } = error;
|
|
70
|
-
this.logger.error('🔥 Failed to save providers');
|
|
71
|
-
this.logger.error(message);
|
|
72
|
-
this.logger.error(stack);
|
|
73
|
-
}
|
|
39
|
+
await this._save(providers);
|
|
74
40
|
}
|
|
75
|
-
async
|
|
76
|
-
await this.
|
|
41
|
+
async update(providers) {
|
|
42
|
+
await this._update(providers);
|
|
77
43
|
}
|
|
78
44
|
};
|
|
79
45
|
exports.ProviderRepositoryService = ProviderRepositoryService;
|
|
@@ -83,6 +49,12 @@ __decorate([
|
|
|
83
49
|
__metadata("design:paramtypes", [Array]),
|
|
84
50
|
__metadata("design:returntype", Promise)
|
|
85
51
|
], ProviderRepositoryService.prototype, "save", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(event_enum_1.ScrapingEvent.UPDATE_PROVIDERS),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Array]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], ProviderRepositoryService.prototype, "update", null);
|
|
86
58
|
exports.ProviderRepositoryService = ProviderRepositoryService = __decorate([
|
|
87
59
|
(0, common_1.Injectable)(),
|
|
88
60
|
__param(0, (0, typeorm_1.InjectRepository)(provider_entity_1.ProviderEntity)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/provider.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"provider.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/provider.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,qCAAqC;AAErC,6DAA0D;AAC1D,iEAA6D;AAC7D,gEAAgE;AAChE,4EAAgE;AAEhE,MAAM,IAAI,GAAG,CAAA,4CAA0C,CAAA,CAAC;AAGjD,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,IAAI;IACjD,YAEqB,UAAsC,EACtC,MAAqB;QAExC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,8BAA8B,EAAE,WAAW,CAAC,CAAC;QAHpD,eAAU,GAAV,UAAU,CAA4B;QACtC,WAAM,GAAN,MAAM,CAAe;IAG1C,CAAC;IAED,GAAG,CAAC,MAAsB;QACxB,OAAO,IAAI,mBAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAC,SAAqB;QAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAC,SAAqB;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AA1BY,8DAAyB;AAkB9B;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,cAAc,CAAC;;;;qDAGrC;AAGK;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,gBAAgB,CAAC;;;;uDAGvC;oCAzBU,yBAAyB;IADrC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,gCAAc,CAAC,CAAA;qCACF,oBAAU;QACd,sBAAa;GAJ/B,yBAAyB,CA0BrC"}
|
|
@@ -2,14 +2,15 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Repository } from 'typeorm';
|
|
3
3
|
import { Province } from '../../../common/class/province';
|
|
4
4
|
import { ProvinceEntity } from '../entities/province.entity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { EntityRepository } from '../entity.repository.service';
|
|
6
|
+
declare const Repo: abstract new (repository: Repository<ProvinceEntity>, config: ConfigService, key: string, label: string) => EntityRepository<ProvinceEntity, Province>;
|
|
7
|
+
export declare class ProvinceRepositoryService extends Repo {
|
|
8
|
+
protected readonly repository: Repository<ProvinceEntity>;
|
|
9
|
+
protected readonly config: ConfigService;
|
|
10
10
|
constructor(repository: Repository<ProvinceEntity>, config: ConfigService);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
map(entity: ProvinceEntity): Province;
|
|
12
|
+
notify(entity: ProvinceEntity): string;
|
|
13
13
|
save(provinces: Province[]): Promise<void>;
|
|
14
|
-
|
|
14
|
+
update(provinces: Province[]): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
export {};
|
|
@@ -18,62 +18,28 @@ const config_1 = require("@nestjs/config");
|
|
|
18
18
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
19
19
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
20
20
|
const typeorm_2 = require("typeorm");
|
|
21
|
-
const logger_1 = require("../../../common/logger/logger");
|
|
22
|
-
const repository_service_1 = require("./../repository.service");
|
|
23
21
|
const province_1 = require("../../../common/class/province");
|
|
24
22
|
const province_entity_1 = require("../entities/province.entity");
|
|
25
23
|
const event_enum_1 = require("../../../common/enum/event.enum");
|
|
26
|
-
|
|
24
|
+
const entity_repository_service_1 = require("../entity.repository.service");
|
|
25
|
+
const Repo = (entity_repository_service_1.EntityRepository);
|
|
26
|
+
let ProvinceRepositoryService = class ProvinceRepositoryService extends Repo {
|
|
27
27
|
constructor(repository, config) {
|
|
28
|
+
super(repository, config, 'REPOSITORY_SAVE_PROVINCE_LOG', 'provinces');
|
|
28
29
|
this.repository = repository;
|
|
29
30
|
this.config = config;
|
|
30
|
-
this.logger = new logger_1.Logger(repository_service_1.RepositoryService.name);
|
|
31
|
-
this.logging = this.config.get('REPOSITORY_SAVE_PROVINCE_LOG');
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return entities.map((entity) => new province_1.Province(entity));
|
|
32
|
+
map(entity) {
|
|
33
|
+
return new province_1.Province(entity);
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
35
|
+
notify(entity) {
|
|
36
|
+
return entity.name;
|
|
39
37
|
}
|
|
40
38
|
async save(provinces) {
|
|
41
|
-
|
|
42
|
-
const sizes = { previous: await this.repository.count(), current: 0 };
|
|
43
|
-
const datas = provinces.map((c) => c.getData()).filter((x) => x.id);
|
|
44
|
-
const identificators = datas.map((x) => x.id);
|
|
45
|
-
const matches = await this.repository
|
|
46
|
-
.find({
|
|
47
|
-
select: ['id'],
|
|
48
|
-
where: { id: (0, typeorm_2.In)(identificators) },
|
|
49
|
-
})
|
|
50
|
-
.then((res) => new Set(res.map((x) => x.id)));
|
|
51
|
-
const entities = datas
|
|
52
|
-
.filter((x) => !matches.has(x.id))
|
|
53
|
-
.map((x) => this.repository.create(x));
|
|
54
|
-
if (entities.length > 0) {
|
|
55
|
-
await this.repository.manager.transaction(async (manager) => {
|
|
56
|
-
await manager.save(entities);
|
|
57
|
-
});
|
|
58
|
-
if (this.logging) {
|
|
59
|
-
entities.forEach((x) => this.logger.debug(`✅ ${x.name}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
sizes.current = sizes.previous + entities.length;
|
|
63
|
-
if (Math.floor(sizes.current / 10) > Math.floor(sizes.previous / 10)) {
|
|
64
|
-
const { current: total } = sizes;
|
|
65
|
-
this.logger.verbose(`✅ ${total} provinces saved successfully`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const { message, stack } = error;
|
|
70
|
-
this.logger.error('🔥 Failed to save provinces');
|
|
71
|
-
this.logger.error(message);
|
|
72
|
-
this.logger.error(stack);
|
|
73
|
-
}
|
|
39
|
+
await this._save(provinces);
|
|
74
40
|
}
|
|
75
|
-
async
|
|
76
|
-
await this.
|
|
41
|
+
async update(provinces) {
|
|
42
|
+
await this._update(provinces);
|
|
77
43
|
}
|
|
78
44
|
};
|
|
79
45
|
exports.ProvinceRepositoryService = ProvinceRepositoryService;
|
|
@@ -83,6 +49,12 @@ __decorate([
|
|
|
83
49
|
__metadata("design:paramtypes", [Array]),
|
|
84
50
|
__metadata("design:returntype", Promise)
|
|
85
51
|
], ProvinceRepositoryService.prototype, "save", null);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, event_emitter_1.OnEvent)(event_enum_1.ScrapingEvent.UPDATE_PROVINCES),
|
|
54
|
+
__metadata("design:type", Function),
|
|
55
|
+
__metadata("design:paramtypes", [Array]),
|
|
56
|
+
__metadata("design:returntype", Promise)
|
|
57
|
+
], ProvinceRepositoryService.prototype, "update", null);
|
|
86
58
|
exports.ProvinceRepositoryService = ProvinceRepositoryService = __decorate([
|
|
87
59
|
(0, common_1.Injectable)(),
|
|
88
60
|
__param(0, (0, typeorm_1.InjectRepository)(province_entity_1.ProvinceEntity)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"province.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/province.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"province.repository.service.js","sourceRoot":"","sources":["../../../../src/modules/repository/services/province.repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,yDAAgD;AAChD,6CAAmD;AACnD,qCAAqC;AAErC,6DAA0D;AAC1D,iEAA6D;AAC7D,gEAAgE;AAChE,4EAAgE;AAEhE,MAAM,IAAI,GAAG,CAAA,4CAA0C,CAAA,CAAC;AAGjD,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,IAAI;IACjD,YAEqB,UAAsC,EACtC,MAAqB;QAExC,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,8BAA8B,EAAE,WAAW,CAAC,CAAC;QAHpD,eAAU,GAAV,UAAU,CAA4B;QACtC,WAAM,GAAN,MAAM,CAAe;IAG1C,CAAC;IAED,GAAG,CAAC,MAAsB;QACxB,OAAO,IAAI,mBAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAsB;QAC3B,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAC,SAAqB;QAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAC,SAAqB;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AA1BY,8DAAyB;AAkB9B;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,cAAc,CAAC;;;;qDAGrC;AAGK;IADL,IAAA,uBAAO,EAAC,0BAAa,CAAC,gBAAgB,CAAC;;;;uDAGvC;oCAzBU,yBAAyB;IADrC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,gCAAc,CAAC,CAAA;qCACF,oBAAU;QACd,sBAAa;GAJ/B,yBAAyB,CA0BrC"}
|