fiscalia_bo-nest-helpers 0.0.36 → 0.0.37

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.
@@ -1,6 +1,19 @@
1
1
  export declare class Coordinates {
2
2
  coordinates: [number, number];
3
3
  }
4
- export declare class ValidateCoordinatesPolygonDTO {
5
- polygonCoordinates: Coordinates[];
4
+ declare class GeometryDto {
5
+ type: string;
6
+ coordinates: Object;
6
7
  }
8
+ declare class properties {
9
+ name: string;
10
+ }
11
+ export declare class FeatureDto {
12
+ type: string;
13
+ geometry: GeometryDto;
14
+ id: string;
15
+ properties: {
16
+ name: properties;
17
+ };
18
+ }
19
+ export {};
@@ -9,25 +9,57 @@ 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.ValidateCoordinatesPolygonDTO = exports.Coordinates = void 0;
12
+ exports.FeatureDto = exports.Coordinates = void 0;
13
13
  const class_transformer_1 = require("class-transformer");
14
14
  const class_validator_1 = require("class-validator");
15
15
  class Coordinates {
16
16
  }
17
17
  __decorate([
18
- (0, class_transformer_1.Type)(() => Number),
19
18
  (0, class_validator_1.IsArray)(),
20
19
  (0, class_validator_1.IsNumber)({}, { each: true }),
21
20
  __metadata("design:type", Array)
22
21
  ], Coordinates.prototype, "coordinates", void 0);
23
22
  exports.Coordinates = Coordinates;
24
- class ValidateCoordinatesPolygonDTO {
23
+ class GeometryDto {
25
24
  }
26
25
  __decorate([
27
- (0, class_transformer_1.Type)(() => Coordinates),
26
+ (0, class_validator_1.IsString)(),
27
+ (0, class_validator_1.IsNotEmpty)(),
28
+ __metadata("design:type", String)
29
+ ], GeometryDto.prototype, "type", void 0);
30
+ __decorate([
28
31
  (0, class_validator_1.IsArray)(),
29
- (0, class_validator_1.ValidateNested)({ each: true }),
30
- __metadata("design:type", Array)
31
- ], ValidateCoordinatesPolygonDTO.prototype, "polygonCoordinates", void 0);
32
- exports.ValidateCoordinatesPolygonDTO = ValidateCoordinatesPolygonDTO;
32
+ (0, class_validator_1.ArrayMinSize)(1),
33
+ __metadata("design:type", Object)
34
+ ], GeometryDto.prototype, "coordinates", void 0);
35
+ class properties {
36
+ }
37
+ __decorate([
38
+ (0, class_validator_1.IsString)(),
39
+ (0, class_validator_1.IsNotEmpty)(),
40
+ __metadata("design:type", String)
41
+ ], properties.prototype, "name", void 0);
42
+ class FeatureDto {
43
+ }
44
+ __decorate([
45
+ (0, class_validator_1.IsString)(),
46
+ (0, class_validator_1.IsNotEmpty)(),
47
+ __metadata("design:type", String)
48
+ ], FeatureDto.prototype, "type", void 0);
49
+ __decorate([
50
+ (0, class_validator_1.ValidateNested)(),
51
+ (0, class_transformer_1.Type)(() => GeometryDto),
52
+ __metadata("design:type", GeometryDto)
53
+ ], FeatureDto.prototype, "geometry", void 0);
54
+ __decorate([
55
+ (0, class_validator_1.IsString)(),
56
+ (0, class_validator_1.IsNotEmpty)(),
57
+ __metadata("design:type", String)
58
+ ], FeatureDto.prototype, "id", void 0);
59
+ __decorate([
60
+ (0, class_transformer_1.Type)(() => properties),
61
+ (0, class_validator_1.IsNotEmpty)(),
62
+ __metadata("design:type", Object)
63
+ ], FeatureDto.prototype, "properties", void 0);
64
+ exports.FeatureDto = FeatureDto;
33
65
  //# sourceMappingURL=ms-geojson.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ms-geojson.dto.js","sourceRoot":"","sources":["../../../src/ms-geojson/dto/ms-geojson.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAyC;AACzC,qDAAoE;AAEpE,MAAa,WAAW;CAKvB;AAJC;IAAC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,yBAAO,GAAE;IACT,IAAA,0BAAQ,EAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;gDACC;AAJhC,kCAKC;AAED,MAAa,6BAA6B;CAKzC;AAJC;IAAC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,WAAW,CAAC;IACvB,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;yEACG;AAJpC,sEAKC"}
1
+ {"version":3,"file":"ms-geojson.dto.js","sourceRoot":"","sources":["../../../src/ms-geojson/dto/ms-geojson.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAyC;AACzC,qDAAwG;AAGxG,MAAa,WAAW;CAIvB;AAHC;IAAC,IAAA,yBAAO,GAAE;IACT,IAAA,0BAAQ,EAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;gDACC;AAHhC,kCAIC;AAGD,MAAM,WAAW;CAQhB;AAPC;IAAC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;yCACA;AAEb;IAAC,IAAA,yBAAO,GAAE;IACT,IAAA,8BAAY,EAAC,CAAC,CAAC;8BACH,MAAM;gDAAC;AAGtB,MAAM,UAAU;CAIf;AAHC;IAAC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;wCACD;AAGd,MAAa,UAAU;CAiBtB;AAhBC;IAAC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;wCACA;AAEb;IAAC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,WAAW,CAAC;8BACd,WAAW;4CAAC;AAEtB;IAAC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sCACF;AAGX;IAAC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,UAAU,CAAC;IACtB,IAAA,4BAAU,GAAE;;8CACoB;AAhBnC,gCAiBC"}
@@ -1,5 +1,5 @@
1
- import { Coordinates, ValidateCoordinatesPolygonDTO } from './dto/ms-geojson.dto';
1
+ import { Coordinates } from './dto/ms-geojson.dto';
2
2
  export declare class MsGeoJsonService {
3
- validateJson(input: any): ValidateCoordinatesPolygonDTO;
4
- validateArrayCoordinatesGeoJson(coordinatesPolygon: any, { coordinates }: Coordinates, reverseCoordinates: boolean): Promise<any>;
3
+ validateJson(dataGEOJSON: any): Promise<void>;
4
+ validateArrayCoordinatesGeoJson(coordinatesPolygon: any, { coordinates }: Coordinates, reverseCoordinates: Boolean): Promise<any>;
5
5
  }
@@ -11,38 +11,66 @@ const common_1 = require("@nestjs/common");
11
11
  const ms_geojson_dto_1 = require("./dto/ms-geojson.dto");
12
12
  const class_validator_1 = require("class-validator");
13
13
  const turf = require("@turf/turf");
14
+ const class_transformer_1 = require("class-transformer");
14
15
  let MsGeoJsonService = class MsGeoJsonService {
15
- validateJson(input) {
16
+ async validateJson(dataGEOJSON) {
16
17
  var _a;
17
- const dto = new ms_geojson_dto_1.ValidateCoordinatesPolygonDTO();
18
- if (input && ((_a = input.geometry) === null || _a === void 0 ? void 0 : _a.coordinates) && Array.isArray(input.geometry.coordinates[0])) {
19
- const arrayCoordinates = input.geometry.coordinates[0];
20
- dto.polygonCoordinates = arrayCoordinates === null || arrayCoordinates === void 0 ? void 0 : arrayCoordinates.map((coords) => ({
21
- coordinates: coords,
22
- }));
23
- }
24
- const errors = (0, class_validator_1.validateSync)(dto);
25
- if (errors.length > 0) {
26
- throw new Error('La entrada de datos es inválida.');
18
+ for (const item of dataGEOJSON) {
19
+ if (((_a = item.geometry) === null || _a === void 0 ? void 0 : _a.coordinates) && Array.isArray(item.geometry.coordinates[0])) {
20
+ let setCoordinatesValidate = [];
21
+ for (let cood of item.geometry.coordinates) {
22
+ let setCood = cood.map(e => {
23
+ return { coordinate: [e[0], e[1]] };
24
+ });
25
+ setCoordinatesValidate.push(setCood);
26
+ }
27
+ item.geometry.coordinates = setCoordinatesValidate;
28
+ }
29
+ const dto = (0, class_transformer_1.plainToClass)(ms_geojson_dto_1.FeatureDto, item);
30
+ const errors = await (0, class_validator_1.validate)(dto);
31
+ if (errors.length > 0) {
32
+ throw new Error('La entrada de datos es inválida.');
33
+ }
27
34
  }
28
- return dto;
29
35
  }
30
36
  async validateArrayCoordinatesGeoJson(coordinatesPolygon, { coordinates }, reverseCoordinates) {
31
- try {
32
- this.validateJson(coordinatesPolygon);
33
- let dataCoordinates = coordinatesPolygon.geometry.coordinates[0];
34
- if (reverseCoordinates) {
35
- dataCoordinates = dataCoordinates.map((e) => [e[1], e[0]]);
36
- }
37
- const pointCoordinates = coordinates;
38
- const pointGeoJSON = turf.point(pointCoordinates);
39
- const polygonGeoJSON = turf.polygon([dataCoordinates]);
40
- const isPointInside = turf.booleanPointInPolygon(pointGeoJSON, polygonGeoJSON);
41
- return { isValid: isPointInside };
37
+ const coordinatesReal = JSON.parse(JSON.stringify(coordinatesPolygon));
38
+ let response = {
39
+ index: null,
40
+ isPointInside: false
41
+ };
42
+ await this.validateJson(coordinatesPolygon);
43
+ let setCoordinates = coordinates;
44
+ if (reverseCoordinates) {
45
+ setCoordinates = [coordinates[1], coordinates[0]];
42
46
  }
43
- catch (error) {
44
- throw error.message;
47
+ for (let [i, cood] of coordinatesReal.entries()) {
48
+ if (cood.geometry.type === "MultiPolygon") {
49
+ const polygonGeoJSON = turf.multiPolygon(cood.geometry.coordinates);
50
+ const pointGeoJSON = turf.point(setCoordinates);
51
+ const isPointInside = turf.booleanPointInPolygon(pointGeoJSON, polygonGeoJSON);
52
+ if (isPointInside) {
53
+ response = {
54
+ index: i,
55
+ isPointInside
56
+ };
57
+ break;
58
+ }
59
+ }
60
+ else if (cood.geometry.type === "Polygon") {
61
+ const polygonGeoJSON = turf.polygon(cood.geometry.coordinates);
62
+ const pointGeoJSON = turf.point(setCoordinates);
63
+ const isPointInside = turf.booleanPointInPolygon(pointGeoJSON, polygonGeoJSON);
64
+ if (isPointInside) {
65
+ response = {
66
+ index: i,
67
+ isPointInside
68
+ };
69
+ break;
70
+ }
71
+ }
45
72
  }
73
+ return response;
46
74
  }
47
75
  };
48
76
  MsGeoJsonService = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"ms-geojson.service.js","sourceRoot":"","sources":["../../src/ms-geojson/ms-geojson.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAkF;AAClF,qDAA+C;AAC/C,mCAAmC;AAG5B,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAM3B,YAAY,CAAC,KAAU;;QACrB,MAAM,GAAG,GAAG,IAAI,8CAA6B,EAAE,CAAC;QAChD,IAAI,KAAK,KAAI,MAAA,KAAK,CAAC,QAAQ,0CAAE,WAAW,CAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE;YACxF,MAAM,gBAAgB,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACvD,GAAG,CAAC,kBAAkB,GAAG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,CAAC,MAAwB,EAAE,EAAE,CAAC,CAAC;gBAC5E,WAAW,EAAE,MAAM;aACpB,CAAC,CAAC,CAAC;SACL;QACD,MAAM,MAAM,GAAG,IAAA,8BAAY,EAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAUD,KAAK,CAAC,+BAA+B,CACnC,kBAAuB,EACvB,EAAE,WAAW,EAAe,EAC5B,kBAA2B;QAE3B,IAAI;YACF,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;YACtC,IAAI,eAAe,GAAG,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACjE,IAAI,kBAAkB,EAAE;gBACtB,eAAe,GAAG,eAAe,CAAC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W,CAAC,CAAA;gBACnE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;gBAChD,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;gBAC/E,IAAG,aAAa,EAAC;oBACf,QAAQ,GAAG;wBACT,KAAK,EAAC,CAAC;wBACP,aAAa;qBACd,CAAA;oBACD,MAAK;iBACN;aACF;iBAAK,IAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAC;gBACxC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;gBAC9D,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;gBAChD,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;gBAC/E,IAAG,aAAa,EAAC;oBACf,QAAQ,GAAG;wBACT,KAAK,EAAC,CAAC;wBACP,aAAa;qBACd,CAAA;oBACD,MAAK;iBACN;aACF;SAEJ;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC;CAEJ,CAAA;AA5EY,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CA4E5B;AA5EY,4CAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiscalia_bo-nest-helpers",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "author": "UTIC",
5
5
  "contact": {
6
6
  "name": "Unidad de Tecnologías de la Información y Comunicación - Ministerio Público",