@volontariapp/domain-event 3.3.6 → 3.4.0-snap-660e713
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/CHANGELOG.md +14 -0
- package/dist/entities/event.entity.d.ts +1 -1
- package/dist/entities/event.entity.d.ts.map +1 -1
- package/dist/repositories/interfaces/event.repository.d.ts +3 -0
- package/dist/repositories/interfaces/event.repository.d.ts.map +1 -1
- package/dist/repositories/postgres-event.repository.d.ts +3 -0
- package/dist/repositories/postgres-event.repository.d.ts.map +1 -1
- package/dist/repositories/postgres-event.repository.js +44 -5
- package/dist/repositories/postgres-event.repository.js.map +1 -1
- package/dist/services/event.service.d.ts +5 -1
- package/dist/services/event.service.d.ts.map +1 -1
- package/dist/services/event.service.js +36 -3
- package/dist/services/event.service.js.map +1 -1
- package/dist/services/geocoding/geocoding.service.d.ts +9 -0
- package/dist/services/geocoding/geocoding.service.d.ts.map +1 -0
- package/dist/services/geocoding/geocoding.service.js +24 -0
- package/dist/services/geocoding/geocoding.service.js.map +1 -0
- package/dist/services/geocoding/strategy/geocoding-strategy.interface.d.ts +11 -0
- package/dist/services/geocoding/strategy/geocoding-strategy.interface.d.ts.map +1 -0
- package/dist/services/geocoding/strategy/geocoding-strategy.interface.js +2 -0
- package/dist/services/geocoding/strategy/geocoding-strategy.interface.js.map +1 -0
- package/dist/services/geocoding/strategy/google-maps.strategy.d.ts +9 -0
- package/dist/services/geocoding/strategy/google-maps.strategy.d.ts.map +1 -0
- package/dist/services/geocoding/strategy/google-maps.strategy.js +39 -0
- package/dist/services/geocoding/strategy/google-maps.strategy.js.map +1 -0
- package/dist/services/geocoding/strategy/open-street-map.strategy.d.ts +17 -0
- package/dist/services/geocoding/strategy/open-street-map.strategy.d.ts.map +1 -0
- package/dist/services/geocoding/strategy/open-street-map.strategy.js +63 -0
- package/dist/services/geocoding/strategy/open-street-map.strategy.js.map +1 -0
- package/dist/test/__test-utils__/mocks/event.repository.mock.d.ts +1 -2
- package/dist/test/__test-utils__/mocks/event.repository.mock.d.ts.map +1 -1
- package/dist/test/__test-utils__/mocks/event.repository.mock.js +5 -11
- package/dist/test/__test-utils__/mocks/event.repository.mock.js.map +1 -1
- package/dist/test/__test-utils__/mocks/geocoding.service.mock.d.ts +3 -0
- package/dist/test/__test-utils__/mocks/geocoding.service.mock.d.ts.map +1 -0
- package/dist/test/__test-utils__/mocks/geocoding.service.mock.js +3 -0
- package/dist/test/__test-utils__/mocks/geocoding.service.mock.js.map +1 -0
- package/dist/test/__test-utils__/mocks/requirement.repository.mock.d.ts +1 -2
- package/dist/test/__test-utils__/mocks/requirement.repository.mock.d.ts.map +1 -1
- package/dist/test/__test-utils__/mocks/requirement.repository.mock.js +2 -8
- package/dist/test/__test-utils__/mocks/requirement.repository.mock.js.map +1 -1
- package/dist/test/__test-utils__/mocks/tag.repository.mock.d.ts +1 -2
- package/dist/test/__test-utils__/mocks/tag.repository.mock.d.ts.map +1 -1
- package/dist/test/__test-utils__/mocks/tag.repository.mock.js +2 -10
- package/dist/test/__test-utils__/mocks/tag.repository.mock.js.map +1 -1
- package/dist/test/__test-utils__/mocks/tag.service.mock.d.ts +1 -2
- package/dist/test/__test-utils__/mocks/tag.service.mock.d.ts.map +1 -1
- package/dist/test/__test-utils__/mocks/tag.service.mock.js +2 -10
- package/dist/test/__test-utils__/mocks/tag.service.mock.js.map +1 -1
- package/dist/test/migrations/domain/1779900000000-UpdateEventTriggerOnlyOnUpdate.d.ts +7 -0
- package/dist/test/migrations/domain/1779900000000-UpdateEventTriggerOnlyOnUpdate.d.ts.map +1 -0
- package/dist/test/migrations/domain/1779900000000-UpdateEventTriggerOnlyOnUpdate.js +20 -0
- package/dist/test/migrations/domain/1779900000000-UpdateEventTriggerOnlyOnUpdate.js.map +1 -0
- package/dist/test/migrations/domain/1780000000000-AddLatLongToEvent.d.ts +6 -0
- package/dist/test/migrations/domain/1780000000000-AddLatLongToEvent.d.ts.map +1 -0
- package/dist/test/migrations/domain/1780000000000-AddLatLongToEvent.js +9 -0
- package/dist/test/migrations/domain/1780000000000-AddLatLongToEvent.js.map +1 -0
- package/dist/test/unit/event.service.unit.spec.js +8 -1
- package/dist/test/unit/event.service.unit.spec.js.map +1 -1
- package/dist/test/unit/geocoding.service.unit.spec.d.ts +2 -0
- package/dist/test/unit/geocoding.service.unit.spec.d.ts.map +1 -0
- package/dist/test/unit/geocoding.service.unit.spec.js +47 -0
- package/dist/test/unit/geocoding.service.unit.spec.js.map +1 -0
- package/dist/test/unit/postgres-event.repository.unit.spec.d.ts +2 -0
- package/dist/test/unit/postgres-event.repository.unit.spec.d.ts.map +1 -0
- package/dist/test/unit/postgres-event.repository.unit.spec.js +71 -0
- package/dist/test/unit/postgres-event.repository.unit.spec.js.map +1 -0
- package/dist/value-objects/find-around-me.value-object.d.ts +11 -0
- package/dist/value-objects/find-around-me.value-object.d.ts.map +1 -0
- package/dist/value-objects/find-around-me.value-object.js +28 -0
- package/dist/value-objects/find-around-me.value-object.js.map +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- geolocode event
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @volontariapp/errors-nest@0.13.0
|
|
13
|
+
- @volontariapp/messaging@2.7.0
|
|
14
|
+
- @volontariapp/database@3.3.1
|
|
15
|
+
- @volontariapp/outbox@0.9.19
|
|
16
|
+
|
|
3
17
|
## 3.3.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.entity.d.ts","sourceRoot":"","sources":["../../src/entities/event.entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAA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AG,MAAM,CAAC;IAC5B,eAAe,EAAG,MAAM,CAAC;IACzB,mBAAmB,EAAG,MAAM,CAAC;IAC7B,WAAW,EAAG,MAAM,CAAC;IACrB,SAAS,EAAG,IAAI,CAAC;IACjB,SAAS,EAAG,IAAI,CAAC;IAEjB,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACnC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;CACpB"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { EventEntity } from '../../entities/event.entity.js';
|
|
2
|
+
import type { EventType, EventState } from '@volontariapp/contracts';
|
|
2
3
|
export interface IEventRepository {
|
|
3
4
|
findById(id: string, relations?: string[]): Promise<EventEntity | null>;
|
|
4
5
|
findAll(relations?: string[]): Promise<EventEntity[]>;
|
|
5
6
|
create(event: Partial<EventEntity>): Promise<EventEntity>;
|
|
6
7
|
createWithEventCreated(event: Partial<EventEntity>): Promise<EventEntity>;
|
|
8
|
+
createWithGeocodeJob(event: Partial<EventEntity>): Promise<EventEntity>;
|
|
7
9
|
update(id: string, data: Partial<EventEntity>): Promise<EventEntity | null>;
|
|
8
10
|
delete(id: string): Promise<boolean>;
|
|
9
11
|
deleteWithEventDeleted(id: string): Promise<boolean>;
|
|
10
12
|
search(searchTerm: string): Promise<EventEntity[]>;
|
|
13
|
+
findAroundMe(lat: number, lng: number, radiusInMeters: number, type?: EventType, state?: EventState): Promise<EventEntity[]>;
|
|
11
14
|
}
|
|
12
15
|
//# sourceMappingURL=event.repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.repository.d.ts","sourceRoot":"","sources":["../../../src/repositories/interfaces/event.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"event.repository.d.ts","sourceRoot":"","sources":["../../../src/repositories/interfaces/event.repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA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EventModel } from '../models/event.model.js';
|
|
4
4
|
import { EventEntity } from '../entities/event.entity.js';
|
|
5
5
|
import { IEventRepository } from './interfaces/event.repository.js';
|
|
6
|
+
import { EventType, EventState } from '@volontariapp/contracts';
|
|
6
7
|
export declare class PostgresEventRepository extends BaseRepository<EventModel, EventEntity> implements IEventRepository {
|
|
7
8
|
constructor(repository: Repository<EventModel>);
|
|
8
9
|
findById(id: string, relations?: string[]): Promise<EventEntity | null>;
|
|
9
10
|
findAll(relations?: string[]): Promise<EventEntity[]>;
|
|
10
11
|
search(searchTerm: string): Promise<EventEntity[]>;
|
|
11
12
|
createWithEventCreated(data: Partial<EventEntity>): Promise<EventEntity>;
|
|
13
|
+
createWithGeocodeJob(data: Partial<EventEntity>): Promise<EventEntity>;
|
|
12
14
|
deleteWithEventDeleted(id: string): Promise<boolean>;
|
|
15
|
+
findAroundMe(lat: number, lng: number, radiusInMeters: number, type?: EventType, state?: EventState): Promise<EventEntity[]>;
|
|
13
16
|
}
|
|
14
17
|
//# sourceMappingURL=postgres-event.repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-event.repository.d.ts","sourceRoot":"","sources":["../../src/repositories/postgres-event.repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"postgres-event.repository.d.ts","sourceRoot":"","sources":["../../src/repositories/postgres-event.repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,cAAc,EAMf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAOpE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEhE,qBACa,uBACX,SAAQ,cAAc,CAAC,UAAU,EAAE,WAAW,CAC9C,YAAW,gBAAgB;gBAIzB,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;IAK9B,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAO3E,OAAO,CAAC,SAAS,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOzD,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIlD,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IA2BxE,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAgCtE,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA2BpD,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EACtB,IAAI,CAAC,EAAE,SAAS,EAChB,KAAK,CAAC,EAAE,UAAU,GACjB,OAAO,CAAC,WAAW,EAAE,CAAC;CAqB1B"}
|
|
@@ -12,12 +12,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { Injectable } from '@nestjs/common';
|
|
14
14
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
15
|
-
import { BaseRepository, ILike, EventQueueEntity, EventQueueModel } from '@volontariapp/database';
|
|
16
|
-
import { EventQueueRepository } from '@volontariapp/outbox';
|
|
15
|
+
import { BaseRepository, ILike, EventQueueEntity, EventQueueModel, JobsOutboxEntity, JobsOutboxModel, } from '@volontariapp/database';
|
|
16
|
+
import { EventQueueRepository, JobsOutboxRepository } from '@volontariapp/outbox';
|
|
17
17
|
import { EventModel } from '../models/event.model.js';
|
|
18
18
|
import { EventEntity } from '../entities/event.entity.js';
|
|
19
19
|
import { Streams } from '@volontariapp/shared';
|
|
20
|
-
import { EventEventMessagingType } from '@volontariapp/messaging';
|
|
20
|
+
import { EventEventMessagingType, EventsJobType, EventsQueue, } from '@volontariapp/messaging';
|
|
21
21
|
let PostgresEventRepository = class PostgresEventRepository extends BaseRepository {
|
|
22
22
|
constructor(repository) {
|
|
23
23
|
super(repository, EventEntity, EventModel);
|
|
@@ -46,7 +46,7 @@ let PostgresEventRepository = class PostgresEventRepository extends BaseReposito
|
|
|
46
46
|
const eventQueueEntity = EventQueueEntity.createEvent({
|
|
47
47
|
type: EventEventMessagingType.EVENT_CREATED,
|
|
48
48
|
emitter: 'ms-event',
|
|
49
|
-
emitterId: savedEventEntity.organizerId
|
|
49
|
+
emitterId: savedEventEntity.organizerId,
|
|
50
50
|
payload: savedEventEntity,
|
|
51
51
|
targetServices: [Streams.SOCIAL_INTERACTIONS],
|
|
52
52
|
});
|
|
@@ -55,6 +55,30 @@ let PostgresEventRepository = class PostgresEventRepository extends BaseReposito
|
|
|
55
55
|
return savedEventEntity;
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
async createWithGeocodeJob(data) {
|
|
59
|
+
return this.executeInTransaction(async (queryRunner) => {
|
|
60
|
+
const modelData = this.toModel(data);
|
|
61
|
+
const eventModel = queryRunner.manager.create(this.modelClass, modelData);
|
|
62
|
+
const savedEventModel = await queryRunner.manager.save(this.modelClass, eventModel);
|
|
63
|
+
const savedEventEntity = this.toEntity(savedEventModel);
|
|
64
|
+
if (savedEventEntity.localisationName &&
|
|
65
|
+
savedEventEntity.localisationName.trim().length > 0) {
|
|
66
|
+
const geocodeJobEntity = JobsOutboxEntity.createJob({
|
|
67
|
+
type: EventsJobType.GEOCODE_EVENT,
|
|
68
|
+
emitter: 'ms-event',
|
|
69
|
+
emitterId: savedEventEntity.organizerId,
|
|
70
|
+
target: EventsQueue.EVENTS,
|
|
71
|
+
payload: {
|
|
72
|
+
eventId: savedEventEntity.id,
|
|
73
|
+
localisationName: savedEventEntity.localisationName,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const jobsOutboxRepo = new JobsOutboxRepository(queryRunner.manager.getRepository(JobsOutboxModel));
|
|
77
|
+
await jobsOutboxRepo.create(geocodeJobEntity);
|
|
78
|
+
}
|
|
79
|
+
return savedEventEntity;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
58
82
|
async deleteWithEventDeleted(id) {
|
|
59
83
|
return this.executeInTransaction(async (queryRunner) => {
|
|
60
84
|
const entity = await this.findById(id);
|
|
@@ -64,7 +88,7 @@ let PostgresEventRepository = class PostgresEventRepository extends BaseReposito
|
|
|
64
88
|
const eventQueueEntity = EventQueueEntity.createEvent({
|
|
65
89
|
type: EventEventMessagingType.EVENT_DELETED,
|
|
66
90
|
emitter: 'ms-event',
|
|
67
|
-
emitterId: entity.organizerId
|
|
91
|
+
emitterId: entity.organizerId,
|
|
68
92
|
payload: entity,
|
|
69
93
|
targetServices: [Streams.SOCIAL_INTERACTIONS],
|
|
70
94
|
});
|
|
@@ -73,6 +97,21 @@ let PostgresEventRepository = class PostgresEventRepository extends BaseReposito
|
|
|
73
97
|
return true;
|
|
74
98
|
});
|
|
75
99
|
}
|
|
100
|
+
async findAroundMe(lat, lng, radiusInMeters, type, state) {
|
|
101
|
+
const origin = `ST_SetSRID(ST_MakePoint(${String(lng)}, ${String(lat)}), 4326)`;
|
|
102
|
+
const query = this.repository.createQueryBuilder('event');
|
|
103
|
+
if (type !== undefined) {
|
|
104
|
+
query.andWhere('event.type = :type', { type });
|
|
105
|
+
}
|
|
106
|
+
if (state !== undefined) {
|
|
107
|
+
query.andWhere('event.state = :state', { state });
|
|
108
|
+
}
|
|
109
|
+
query.andWhere(`ST_DWithin(event.location::geography, ${origin}::geography, :radius)`);
|
|
110
|
+
query.setParameter('radius', radiusInMeters);
|
|
111
|
+
query.orderBy(`ST_Distance(event.location::geography, ${origin}::geography)`, 'ASC');
|
|
112
|
+
const eventModels = await query.getMany();
|
|
113
|
+
return eventModels.map((model) => this.toEntity(model));
|
|
114
|
+
}
|
|
76
115
|
};
|
|
77
116
|
PostgresEventRepository = __decorate([
|
|
78
117
|
Injectable(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-event.repository.js","sourceRoot":"","sources":["../../src/repositories/postgres-event.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"postgres-event.repository.js","sourceRoot":"","sources":["../../src/repositories/postgres-event.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EACL,cAAc,EACd,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EACL,uBAAuB,EAEvB,aAAa,EACb,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAI1B,IAAM,uBAAuB,GAA7B,MAAM,uBACX,SAAQ,cAAuC;IAG/C,YAEE,UAAkC;QAElC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,C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AAG,CAAC,UAAU,CAAC;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAE1D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,KAAK,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,yCAAyC,MAAM,uBAAuB,CAAC,CAAC;QACvF,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE7C,KAAK,CAAC,OAAO,CAAC,0CAA0C,MAAM,cAAc,EAAE,KAAK,CAAC,CAAC;QAErF,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1C,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,CAAC;CACF,CAAA;AA9IY,uBAAuB;IADnC,UAAU,EAAE;IAMR,WAAA,gBAAgB,CAAC,UAAU,CAAC,CAAA;;GALpB,uBAAuB,CA8InC"}
|
|
@@ -2,11 +2,14 @@ import { EventState } from '@volontariapp/contracts';
|
|
|
2
2
|
import type { IEventRepository } from '../repositories/interfaces/event.repository.js';
|
|
3
3
|
import { EventEntity } from '../entities/event.entity.js';
|
|
4
4
|
import { TagService } from './tag.service.js';
|
|
5
|
+
import { GeocodingService } from './geocoding/geocoding.service.js';
|
|
6
|
+
import { FindAroundMeVO } from '../value-objects/find-around-me.value-object.js';
|
|
5
7
|
export declare class EventService {
|
|
6
8
|
private readonly eventRepository;
|
|
7
9
|
private readonly tagService;
|
|
10
|
+
private readonly geocodingService;
|
|
8
11
|
private readonly logger;
|
|
9
|
-
constructor(eventRepository: IEventRepository, tagService: TagService);
|
|
12
|
+
constructor(eventRepository: IEventRepository, tagService: TagService, geocodingService: GeocodingService);
|
|
10
13
|
findById(id: string): Promise<EventEntity>;
|
|
11
14
|
findAll(): Promise<EventEntity[]>;
|
|
12
15
|
create(data: Partial<EventEntity>): Promise<EventEntity>;
|
|
@@ -14,6 +17,7 @@ export declare class EventService {
|
|
|
14
17
|
changeState(id: string, state: EventState): Promise<EventEntity>;
|
|
15
18
|
delete(id: string): Promise<void>;
|
|
16
19
|
search(searchTerm: string): Promise<EventEntity[]>;
|
|
20
|
+
findAroundMe(params: FindAroundMeVO): Promise<EventEntity[]>;
|
|
17
21
|
private validateTags;
|
|
18
22
|
}
|
|
19
23
|
//# sourceMappingURL=event.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../src/services/event.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAEvF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"event.service.d.ts","sourceRoot":"","sources":["../../src/services/event.service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAEvF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAEjF,qBACa,YAAY;IAKrB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IANnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;gBAIlD,eAAe,EAAE,gBAAgB,EACjC,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,gBAAgB;IAG/C,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAe1C,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAUjC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAwCxD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAkCpE,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IA8BhE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAejC,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAYlD,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YAoBpD,YAAY;CAc3B"}
|
|
@@ -19,13 +19,17 @@ import { EventState } from '@volontariapp/contracts';
|
|
|
19
19
|
import { PostgresEventRepository } from '../repositories/postgres-event.repository.js';
|
|
20
20
|
import { EventEntity } from '../entities/event.entity.js';
|
|
21
21
|
import { TagService } from './tag.service.js';
|
|
22
|
+
import { GeocodingService } from './geocoding/geocoding.service.js';
|
|
23
|
+
import { EventLocation } from '../value-objects/event-location.value-object.js';
|
|
22
24
|
let EventService = EventService_1 = class EventService {
|
|
23
25
|
eventRepository;
|
|
24
26
|
tagService;
|
|
27
|
+
geocodingService;
|
|
25
28
|
logger = new Logger({ context: EventService_1.name });
|
|
26
|
-
constructor(eventRepository, tagService) {
|
|
29
|
+
constructor(eventRepository, tagService, geocodingService) {
|
|
27
30
|
this.eventRepository = eventRepository;
|
|
28
31
|
this.tagService = tagService;
|
|
32
|
+
this.geocodingService = geocodingService;
|
|
29
33
|
}
|
|
30
34
|
async findById(id) {
|
|
31
35
|
try {
|
|
@@ -62,7 +66,22 @@ let EventService = EventService_1 = class EventService {
|
|
|
62
66
|
if (data.tags && data.tags.length > 0) {
|
|
63
67
|
data.tags = await this.validateTags(data.tags);
|
|
64
68
|
}
|
|
65
|
-
|
|
69
|
+
let geoResult = null;
|
|
70
|
+
if (data.localisationName && data.localisationName.trim().length > 0) {
|
|
71
|
+
geoResult = await this.geocodingService.geocode(data.localisationName);
|
|
72
|
+
}
|
|
73
|
+
if (geoResult) {
|
|
74
|
+
this.logger.log(`Geocoding successful for event ${String(data.name)}`);
|
|
75
|
+
data.location = new EventLocation(geoResult.lat, geoResult.lng);
|
|
76
|
+
return await this.eventRepository.createWithEventCreated(data);
|
|
77
|
+
}
|
|
78
|
+
else if (data.localisationName) {
|
|
79
|
+
this.logger.warn(`Geocoding failed for event ${String(data.name)}, deferring to worker`);
|
|
80
|
+
return await this.eventRepository.createWithGeocodeJob(data);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return await this.eventRepository.createWithEventCreated(data);
|
|
84
|
+
}
|
|
66
85
|
}
|
|
67
86
|
catch (error) {
|
|
68
87
|
if (isBaseError(error))
|
|
@@ -160,6 +179,19 @@ let EventService = EventService_1 = class EventService {
|
|
|
160
179
|
throw DATABASE_ERROR(`searching events: ${searchTerm}`, err.message);
|
|
161
180
|
}
|
|
162
181
|
}
|
|
182
|
+
async findAroundMe(params) {
|
|
183
|
+
try {
|
|
184
|
+
this.logger.debug(`Finding events around lat: ${String(params.latitude)}, lng: ${String(params.longitude)} within ${String(params.radiusInMeters)}m`);
|
|
185
|
+
return await this.eventRepository.findAroundMe(params.latitude, params.longitude, params.radiusInMeters, params.type, params.state);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (isBaseError(error))
|
|
189
|
+
throw error;
|
|
190
|
+
const err = error;
|
|
191
|
+
this.logger.error('Failed to find events around location', err);
|
|
192
|
+
throw DATABASE_ERROR('finding events around location', err.message);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
163
195
|
async validateTags(tags) {
|
|
164
196
|
const ids = tags.map((t) => t.id);
|
|
165
197
|
const existingTags = await this.tagService.findByIds(ids);
|
|
@@ -176,7 +208,8 @@ let EventService = EventService_1 = class EventService {
|
|
|
176
208
|
EventService = EventService_1 = __decorate([
|
|
177
209
|
Injectable(),
|
|
178
210
|
__param(0, Inject(PostgresEventRepository)),
|
|
179
|
-
__metadata("design:paramtypes", [Object, TagService
|
|
211
|
+
__metadata("design:paramtypes", [Object, TagService,
|
|
212
|
+
GeocodingService])
|
|
180
213
|
], EventService);
|
|
181
214
|
export { EventService };
|
|
182
215
|
//# sourceMappingURL=event.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.service.js","sourceRoot":"","sources":["../../src/services/event.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,C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,CAAC;QAE1D,IAAI,YAAY,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;YACvC,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAClD,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9D,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF,CAAA;AAxMY,YAAY;IADxB,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;6CAEH,UAAU;QACJ,gBAAgB;GAP1C,YAAY,CAwMxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IGeocodingStrategy, GeocodeResponse } from './strategy/geocoding-strategy.interface.js';
|
|
2
|
+
export declare class GeocodingService {
|
|
3
|
+
private readonly primaryStrategy;
|
|
4
|
+
private readonly fallbackStrategy?;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(primaryStrategy: IGeocodingStrategy, fallbackStrategy?: IGeocodingStrategy | undefined);
|
|
7
|
+
geocode(address: string): Promise<GeocodeResponse | null>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=geocoding.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding.service.d.ts","sourceRoot":"","sources":["../../../src/services/geocoding/geocoding.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAElB,eAAe,EAChB,MAAM,4CAA4C,CAAC;AAGpD,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAJpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkD;gBAGtD,eAAe,EAAE,kBAAkB,EACnC,gBAAgB,CAAC,EAAE,kBAAkB,YAAA;IAGlD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAiBhE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Logger } from '@volontariapp/logger';
|
|
2
|
+
export class GeocodingService {
|
|
3
|
+
primaryStrategy;
|
|
4
|
+
fallbackStrategy;
|
|
5
|
+
logger = new Logger({ context: GeocodingService.name });
|
|
6
|
+
constructor(primaryStrategy, fallbackStrategy) {
|
|
7
|
+
this.primaryStrategy = primaryStrategy;
|
|
8
|
+
this.fallbackStrategy = fallbackStrategy;
|
|
9
|
+
}
|
|
10
|
+
async geocode(address) {
|
|
11
|
+
const request = { address };
|
|
12
|
+
const primaryResult = await this.primaryStrategy.geocode(request);
|
|
13
|
+
if (primaryResult !== null) {
|
|
14
|
+
return primaryResult;
|
|
15
|
+
}
|
|
16
|
+
if (this.fallbackStrategy) {
|
|
17
|
+
this.logger.warn('Primary geocoding failed, attempting fallback...');
|
|
18
|
+
const fallbackResult = await this.fallbackStrategy.geocode(request);
|
|
19
|
+
return fallbackResult;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=geocoding.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding.service.js","sourceRoot":"","sources":["../../../src/services/geocoding/geocoding.service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,MAAM,OAAO,gBAAgB;IAIR;IACA;IAJF,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAEzE,YACmB,eAAmC,EACnC,gBAAqC;QADrC,oBAAe,GAAf,eAAe,CAAoB;QACnC,qBAAgB,GAAhB,gBAAgB,CAAqB;IACrD,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,OAAe;QAC3B,MAAM,OAAO,GAAmB,EAAE,OAAO,EAAE,CAAC;QAE5C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAElE,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;YACrE,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACpE,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface GeocodeRequest {
|
|
2
|
+
address: string;
|
|
3
|
+
}
|
|
4
|
+
export interface GeocodeResponse {
|
|
5
|
+
lat: number;
|
|
6
|
+
lng: number;
|
|
7
|
+
}
|
|
8
|
+
export interface IGeocodingStrategy {
|
|
9
|
+
geocode(request: GeocodeRequest): Promise<GeocodeResponse | null>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=geocoding-strategy.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding-strategy.interface.d.ts","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/geocoding-strategy.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding-strategy.interface.js","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/geocoding-strategy.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IGeocodingStrategy, GeocodeRequest, GeocodeResponse } from './geocoding-strategy.interface.js';
|
|
2
|
+
export declare class GoogleMapsStrategy implements IGeocodingStrategy {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly baseUrl;
|
|
6
|
+
constructor(apiKey: string);
|
|
7
|
+
geocode(request: GeocodeRequest): Promise<GeocodeResponse | null>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=google-maps.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-maps.strategy.d.ts","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAI3C,qBAAa,kBAAmB,YAAW,kBAAkB;IAI/C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoD;IAC3E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuD;gBAElD,MAAM,EAAE,MAAM;IAMrC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAuCxE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger } from '@volontariapp/logger';
|
|
2
|
+
import { GEOCODING_FAILED } from '@volontariapp/errors-nest';
|
|
3
|
+
export class GoogleMapsStrategy {
|
|
4
|
+
apiKey;
|
|
5
|
+
logger = new Logger({ context: GoogleMapsStrategy.name });
|
|
6
|
+
baseUrl = 'https://maps.googleapis.com/maps/api/geocode/json';
|
|
7
|
+
constructor(apiKey) {
|
|
8
|
+
this.apiKey = apiKey;
|
|
9
|
+
if (!this.apiKey) {
|
|
10
|
+
throw new Error('GoogleMapsStrategy requires a valid API key.');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async geocode(request) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(this.baseUrl);
|
|
16
|
+
url.searchParams.append('address', request.address);
|
|
17
|
+
url.searchParams.append('key', this.apiKey);
|
|
18
|
+
const response = await fetch(url.toString());
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
this.logger.error(`Google Maps API responded with status: ${String(response.status)}`);
|
|
21
|
+
throw GEOCODING_FAILED('Google Maps', response.status);
|
|
22
|
+
}
|
|
23
|
+
const data = (await response.json());
|
|
24
|
+
if (data.status === 'OK' && data.results.length > 0) {
|
|
25
|
+
const { lat, lng } = data.results[0].geometry.location;
|
|
26
|
+
return { lat, lng };
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error && error.name === 'BadRequestError')
|
|
32
|
+
throw error;
|
|
33
|
+
const err = error;
|
|
34
|
+
this.logger.error('Google Maps geocoding error:', err);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=google-maps.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-maps.strategy.js","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,OAAO,kBAAkB;IAI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GAAG,EAAE,GAAG,EAAE,CAAC;YACtB,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;gBAAE,MAAM,KAAK,CAAC;YAE5E,MAAM,GAAG,GAAG,KAAc,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IGeocodingStrategy, GeocodeRequest, GeocodeResponse } from './geocoding-strategy.interface.js';
|
|
2
|
+
export interface NominatimResult {
|
|
3
|
+
lat: string;
|
|
4
|
+
lon: string;
|
|
5
|
+
display_name?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class OpenStreetMapStrategy implements IGeocodingStrategy {
|
|
8
|
+
private readonly userAgent;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly baseUrl;
|
|
11
|
+
private static rateLimitPromise;
|
|
12
|
+
private readonly rateLimitMs;
|
|
13
|
+
constructor(userAgent: string);
|
|
14
|
+
private delayIfNeeded;
|
|
15
|
+
geocode(request: GeocodeRequest): Promise<GeocodeResponse | null>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=open-street-map.strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-street-map.strategy.d.ts","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/open-street-map.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAI3C,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,qBAAsB,YAAW,kBAAkB;IAOlD,OAAO,CAAC,QAAQ,CAAC,SAAS;IANtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuD;IAC9E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgD;IAExE,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAoC;IACnE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAEP,SAAS,EAAE,MAAM;YAMhC,aAAa;IAQrB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CA6CxE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Logger } from '@volontariapp/logger';
|
|
2
|
+
import { GEOCODING_FAILED } from '@volontariapp/errors-nest';
|
|
3
|
+
export class OpenStreetMapStrategy {
|
|
4
|
+
userAgent;
|
|
5
|
+
logger = new Logger({ context: OpenStreetMapStrategy.name });
|
|
6
|
+
baseUrl = 'https://nominatim.openstreetmap.org/search';
|
|
7
|
+
static rateLimitPromise = Promise.resolve();
|
|
8
|
+
rateLimitMs = 1100;
|
|
9
|
+
constructor(userAgent) {
|
|
10
|
+
this.userAgent = userAgent;
|
|
11
|
+
if (!this.userAgent) {
|
|
12
|
+
throw new Error('OpenStreetMapStrategy requires a valid userAgent.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async delayIfNeeded() {
|
|
16
|
+
const nextPromise = OpenStreetMapStrategy.rateLimitPromise.then(async () => {
|
|
17
|
+
await new Promise((resolve) => setTimeout(resolve, this.rateLimitMs));
|
|
18
|
+
});
|
|
19
|
+
OpenStreetMapStrategy.rateLimitPromise = nextPromise.catch(() => { });
|
|
20
|
+
await nextPromise;
|
|
21
|
+
}
|
|
22
|
+
async geocode(request) {
|
|
23
|
+
try {
|
|
24
|
+
await this.delayIfNeeded();
|
|
25
|
+
const url = new URL(this.baseUrl);
|
|
26
|
+
url.searchParams.append('q', request.address);
|
|
27
|
+
url.searchParams.append('format', 'json');
|
|
28
|
+
url.searchParams.append('limit', '1');
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timeoutId = setTimeout(() => {
|
|
31
|
+
controller.abort();
|
|
32
|
+
}, 5000);
|
|
33
|
+
const response = await fetch(url.toString(), {
|
|
34
|
+
headers: {
|
|
35
|
+
'User-Agent': this.userAgent,
|
|
36
|
+
},
|
|
37
|
+
signal: controller.signal,
|
|
38
|
+
});
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
this.logger.error('OSM API responded with status:', String(response.status));
|
|
42
|
+
throw GEOCODING_FAILED('OSM', response.status);
|
|
43
|
+
}
|
|
44
|
+
const data = (await response.json());
|
|
45
|
+
if (data.length > 0) {
|
|
46
|
+
const { lat, lon } = data[0];
|
|
47
|
+
return {
|
|
48
|
+
lat: parseFloat(lat),
|
|
49
|
+
lng: parseFloat(lon),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof Error && error.name === 'BadRequestError')
|
|
56
|
+
throw error;
|
|
57
|
+
const err = error;
|
|
58
|
+
this.logger.error('OpenStreetMap geocoding error:', err);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=open-street-map.strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-street-map.strategy.js","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/open-street-map.strategy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAQ7D,MAAM,OAAO,qBAAqB;IAOH;IANZ,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,OAAO,EAAE,qBAAqB,CAAC,IAAI,EA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type { IEventRepository } from '../../../repositories/interfaces/event.repository.js';
|
|
3
|
-
export declare const createEventRepositoryMock: () => jest.
|
|
2
|
+
export declare const createEventRepositoryMock: () => import("jest-mock").MockedObject<IEventRepository>;
|
|
4
3
|
//# sourceMappingURL=event.repository.mock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.repository.mock.d.ts","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/event.repository.mock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event.repository.mock.d.ts","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/event.repository.mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sDAAsD,CAAC;AAE7F,eAAO,MAAM,yBAAyB,0DAGrC,CAAC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const createEventRepositoryMock = () =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
createWithEventCreated: jest.fn(),
|
|
7
|
-
update: jest.fn(),
|
|
8
|
-
delete: jest.fn(),
|
|
9
|
-
deleteWithEventDeleted: jest.fn(),
|
|
10
|
-
search: jest.fn(),
|
|
11
|
-
});
|
|
1
|
+
import { createMock } from '@volontariapp/testing';
|
|
2
|
+
export const createEventRepositoryMock = () => {
|
|
3
|
+
const mock = createMock();
|
|
4
|
+
return mock;
|
|
5
|
+
};
|
|
12
6
|
//# sourceMappingURL=event.repository.mock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.repository.mock.js","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/event.repository.mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"event.repository.mock.js","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/event.repository.mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,IAAI,GAAG,UAAU,EAAoB,CAAC;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding.service.mock.d.ts","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/geocoding.service.mock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AAEzF,eAAO,MAAM,0BAA0B,0DAAuC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geocoding.service.mock.js","sourceRoot":"","sources":["../../../../src/test/__test-utils__/mocks/geocoding.service.mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,EAAE,CAAC,UAAU,EAAoB,CAAC"}
|