@@ -8,7 +8,7 @@ export class LogService {
88 constructor (
99 private readonly logRepo : LogRepository ,
1010 private readonly creditManagerService : CreditManagerService ,
11- ) { }
11+ ) { }
1212 async createLog ( log : any ) {
1313 Logger . log (
1414 `Storing log to db: ${ log . method } ${ log . path } ${ log . statusCode } ${ log . contentLenght } ${ log . userAgent } ${ log . appId } ` ,
@@ -68,10 +68,49 @@ export class LogService {
6868 ] ,
6969 } ,
7070 } ,
71+ {
72+ $project : {
73+ method : 1 ,
74+ normalizedPath : {
75+ $switch : {
76+ branches : [
77+ {
78+ case : {
79+ $regexMatch : {
80+ input : '$path' ,
81+ regex : '^/api/v1/did/resolve/' ,
82+ } ,
83+ } ,
84+ then : '/api/v1/did/resolve' ,
85+ } ,
86+ {
87+ case : {
88+ $regexMatch : {
89+ input : '$path' ,
90+ regex : '^/api/v1/schema/sch:' ,
91+ } ,
92+ } ,
93+ then : '/api/v1/schema/resolve' ,
94+ } ,
95+ {
96+ case : {
97+ $regexMatch : {
98+ input : '$path' ,
99+ regex : '^/api/v1/credential/vc:' ,
100+ } ,
101+ } ,
102+ then : '/api/v1/credential/resolve' ,
103+ } ,
104+ ] ,
105+ default : '$path' , // If no match, keep the original path
106+ } ,
107+ } ,
108+ } ,
109+ } ,
71110 {
72111 $group : {
73112 _id : {
74- path : '$path ' ,
113+ path : '$normalizedPath ' ,
75114 method : '$method' ,
76115 } ,
77116 count : { $sum : 1 } ,
@@ -86,9 +125,9 @@ export class LogService {
86125 } ,
87126 } ,
88127 ] ;
128+
89129 const serviceDetails =
90130 await this . logRepo . findDataBasedOnAgggregationPipeline ( pipeline ) ;
91-
92131 const updatedServiceDetails = await Promise . all (
93132 serviceDetails . map ( async ( x ) => {
94133 x [ 'apiPath' ] = x [ 'apiPath' ] ;
@@ -98,7 +137,7 @@ export class LogService {
98137 x [ 'method' ] ,
99138 x [ 'apiPath' ] ,
100139 ) ;
101- ( x [ 'onchain_unit_cost' ] = x [ 'unit_cost' ] [ 'attestationCost ' ] ) ,
140+ ( x [ 'onchain_unit_cost' ] = x [ 'unit_cost' ] [ 'hidCost ' ] ) ,
102141 ( x [ 'offchain_unit_cost' ] = x [ 'unit_cost' ] [ 'creditAmountRequired' ] ) ;
103142 x [ 'onchainAmount' ] = Number (
104143 ( x [ 'onchain_unit_cost' ] * x [ 'quantity' ] ) . toFixed ( 2 ) ,
@@ -129,19 +168,67 @@ export class LogService {
129168 {
130169 $match : {
131170 createdAt : { $gte : startDate , $lte : endDate } ,
171+ path : { $exists : true , $ne : null } ,
132172 $nor : [
133173 { path : { $regex : 'usage' } } ,
134174 { path : { $regex : 'credit' } } ,
135175 { path : { $regex : 'presentation' } } ,
136176 ] ,
137177 } ,
138178 } ,
179+ {
180+ $project : {
181+ method : 1 ,
182+ createdAt : 1 ,
183+ path : { $ifNull : [ '$path' , 'unknown' ] } ,
184+ normalizedPath : {
185+ $switch : {
186+ branches : [
187+ {
188+ case : {
189+ $regexMatch : {
190+ input : '$path' ,
191+ regex : '^/api/v1/did/resolve/' ,
192+ } ,
193+ } ,
194+ then : '/api/v1/did/resolve' ,
195+ } ,
196+ {
197+ case : {
198+ $regexMatch : {
199+ input : '$path' ,
200+ regex : '^/api/v1/schema/sch:' ,
201+ } ,
202+ } ,
203+ then : '/api/v1/schema/resolve' ,
204+ } ,
205+ {
206+ case : {
207+ $regexMatch : {
208+ input : '$path' ,
209+ regex : '^/api/v1/credential(/|$)' ,
210+ } ,
211+ } ,
212+ then : '/api/v1/credential/resolve' ,
213+ } ,
214+ ] ,
215+ default : '$path' , // Keep original path if no match
216+ } ,
217+ } ,
218+ } ,
219+ } ,
139220 {
140221 $group : {
141222 _id : {
142- path : '$path' ,
143- date : { $dateToString : { format : '%Y-%m-%d' , date : '$createdAt' } } ,
223+ path : '$normalizedPath' ,
224+ date : {
225+ $ifNull : [
226+ { $dateToString : { format : '%Y-%m-%d' , date : '$createdAt' } } ,
227+ 'unknown-date' ,
228+ ] ,
229+ } ,
144230 } ,
231+
145232 count : { $sum : 1 } ,
146233 } ,
147234 } ,
0 commit comments