Skip to content

Commit 14c23d7

Browse files
committed
Merge branch 'master' of github.com:codex-team/hawk.api.nodejs into feat/new-diff
2 parents d818a83 + 3201ad9 commit 14c23d7

15 files changed

+522
-128
lines changed

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ module.exports = {
1111
'require-jsdoc': 'warn',
1212
'no-shadow': 'warn',
1313
'no-unused-expressions': 'warn'
14-
}
14+
},
15+
overrides: [
16+
{
17+
files: ['*.js'],
18+
rules: {
19+
'@typescript-eslint/explicit-function-return-type': 'off'
20+
}
21+
}
22+
]
1523
};

.github/workflows/build-and-push-docker-image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-20.04
1818
steps:
1919
- name: Checkout repository
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121

2222
- name: Login to GitHub registry
2323
uses: docker/login-action@v2
@@ -55,4 +55,4 @@ jobs:
5555
file: docker/Dockerfile.prod
5656
tags: ${{ steps.meta.outputs.tags }}
5757
labels: ${{ steps.meta.outputs.labels }}
58-
push: ${{ startsWith(github.ref, 'refs/tags/v') || endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod') }}
58+
push: ${{ github.ref == 'refs/heads/stage' || github.ref == 'refs/heads/prod' || startsWith(github.ref, 'refs/tags/v') }}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.1.15",
3+
"version": "1.1.17",
44
"main": "index.ts",
55
"license": "UNLICENSED",
66
"scripts": {
@@ -37,7 +37,7 @@
3737
"@graphql-tools/schema": "^8.5.1",
3838
"@graphql-tools/utils": "^8.9.0",
3939
"@hawk.so/nodejs": "^3.1.1",
40-
"@hawk.so/types": "^0.1.26",
40+
"@hawk.so/types": "^0.1.28",
4141
"@types/amqp-connection-manager": "^2.0.4",
4242
"@types/bson": "^4.0.5",
4343
"@types/debug": "^4.1.5",
@@ -48,6 +48,7 @@
4848
"@types/mongodb": "^3.6.20",
4949
"@types/node": "^16.11.46",
5050
"@types/node-fetch": "^2.5.4",
51+
"@types/safe-regex": "^1.1.6",
5152
"@types/uuid": "^8.3.4",
5253
"amqp-connection-manager": "^3.1.0",
5354
"amqplib": "^0.5.5",
@@ -72,6 +73,7 @@
7273
"migrate-mongo": "^7.0.1",
7374
"mime-types": "^2.1.25",
7475
"mongodb": "^3.7.3",
76+
"safe-regex": "^2.1.0",
7577
"ts-node-dev": "^2.0.0",
7678
"uuid": "^8.3.2"
7779
}

src/billing/cloudpayments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ export default class CloudPaymentsWebhooks {
886886
{
887887
Items: [ item ],
888888
email: userMail,
889-
taxationSystem: TaxationSystem.GENERAL,
889+
taxationSystem: TaxationSystem.SIMPLIFIED_INCOME,
890890
}
891891
);
892892
}

src/models/eventsFactory.js

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,23 @@ class EventsFactory extends Factory {
149149
* @param {Number} skip - certain number of documents to skip
150150
* @param {'BY_DATE' | 'BY_COUNT'} sort - events sort order
151151
* @param {EventsFilters} filters - marks by which events should be filtered
152+
* @param {String} search - Search query
152153
*
153154
* @return {RecentEventSchema[]}
154155
*/
155156
async findRecent(
156157
limit = 10,
157158
skip = 0,
158159
sort = 'BY_DATE',
159-
filters = {}
160+
filters = {},
161+
search = ''
160162
) {
163+
if (typeof search !== 'string') {
164+
throw new Error('Search parameter must be a string');
165+
}
166+
167+
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
168+
161169
limit = this.validateLimit(limit);
162170

163171
switch (sort) {
@@ -184,71 +192,64 @@ class EventsFactory extends Factory {
184192
},
185193
];
186194

187-
/**
188-
* If some events should be omitted, use alternative pipeline
189-
*/
190-
if (Object.values(filters).length > 0) {
191-
pipeline.push(
192-
/**
193-
* Lookup events object for each daily event
194-
*/
195-
{
196-
$lookup: {
197-
from: 'events:' + this.projectId,
198-
localField: 'groupHash',
199-
foreignField: 'groupHash',
200-
as: 'event',
195+
const searchFilter = search.trim().length > 0
196+
? {
197+
$or: [
198+
{
199+
'event.payload.title': {
200+
$regex: escapedSearch,
201+
$options: 'i',
202+
},
201203
},
202-
},
203-
{
204-
$unwind: '$event',
205-
},
206-
/**
207-
* Match filters
208-
*/
209-
{
210-
$match: {
211-
...Object.fromEntries(
212-
Object
213-
.entries(filters)
214-
.map(([mark, exists]) => [`event.marks.${mark}`, { $exists: exists } ])
215-
),
204+
{
205+
'event.payload.backtrace.file': {
206+
$regex: escapedSearch,
207+
$options: 'i',
208+
},
216209
},
210+
],
211+
}
212+
: {};
213+
214+
const matchFilter = filters
215+
? Object.fromEntries(
216+
Object
217+
.entries(filters)
218+
.map(([mark, exists]) => [`event.marks.${mark}`, { $exists: exists } ])
219+
)
220+
: {};
221+
222+
pipeline.push(
223+
{
224+
$lookup: {
225+
from: 'events:' + this.projectId,
226+
localField: 'groupHash',
227+
foreignField: 'groupHash',
228+
as: 'event',
217229
},
218-
{ $skip: skip },
219-
{ $limit: limit },
220-
{
221-
$group: {
222-
_id: null,
223-
dailyInfo: { $push: '$$ROOT' },
224-
events: { $push: '$event' },
225-
},
230+
},
231+
{
232+
$unwind: '$event',
233+
},
234+
{
235+
$match: {
236+
...matchFilter,
237+
...searchFilter,
226238
},
227-
{
228-
$unset: 'dailyInfo.event',
229-
}
230-
);
231-
} else {
232-
pipeline.push(
233-
{ $skip: skip },
234-
{ $limit: limit },
235-
{
236-
$group: {
237-
_id: null,
238-
groupHash: { $addToSet: '$groupHash' },
239-
dailyInfo: { $push: '$$ROOT' },
240-
},
239+
},
240+
{ $skip: skip },
241+
{ $limit: limit },
242+
{
243+
$group: {
244+
_id: null,
245+
dailyInfo: { $push: '$$ROOT' },
246+
events: { $push: '$event' },
241247
},
242-
{
243-
$lookup: {
244-
from: 'events:' + this.projectId,
245-
localField: 'groupHash',
246-
foreignField: 'groupHash',
247-
as: 'events',
248-
},
249-
}
250-
);
251-
}
248+
},
249+
{
250+
$unset: 'dailyInfo.event',
251+
}
252+
);
252253

253254
const cursor = this.getCollection(this.TYPES.DAILY_EVENTS).aggregate(pipeline);
254255

@@ -316,7 +317,7 @@ class EventsFactory extends Factory {
316317
});
317318

318319
/**
319-
* Group events using 'groupByTimestamp:NNNNNNNN' key
320+
* Group events using 'groupingTimestamp:NNNNNNNN' key
320321
* @type {ProjectChartItem[]}
321322
*/
322323
const groupedData = groupBy('groupingTimestamp')(dailyEvents);

0 commit comments

Comments
 (0)