-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: export activity interceptor (#3926)
* fix: export activity interceptor * fix: import path * fix: improve export logging tests * fix: tidy up implementation * fix: commenting for clarity
- Loading branch information
1 parent
e5bf474
commit 5662226
Showing
10 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE "activity_log" ALTER COLUMN "record_id" DROP NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CallHandler, ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { ActivityLogInterceptor } from './activity-log.interceptor'; | ||
import { endWith, from, ignoreElements, mergeMap } from 'rxjs'; | ||
import { PrismaService } from '../services/prisma.service'; | ||
import { Reflector } from '@nestjs/core'; | ||
|
||
@Injectable() | ||
export class ExportLogInterceptor extends ActivityLogInterceptor { | ||
constructor(reflector: Reflector, prisma: PrismaService) { | ||
super(reflector, prisma); | ||
} | ||
|
||
intercept(context: ExecutionContext, next: CallHandler) { | ||
const { module, user } = this.getBasicRequestInfo(context); | ||
return next.handle().pipe( | ||
mergeMap((value) => { | ||
let resourceId; | ||
// only export type tied to a single resourceId | ||
if (module === 'application') { | ||
const req = context.switchToHttp().getRequest(); | ||
resourceId = req.query.listingId; | ||
} | ||
return from( | ||
this.prisma.activityLog.create({ | ||
include: { | ||
userAccounts: true, | ||
}, | ||
data: { | ||
module, | ||
recordId: resourceId, | ||
action: 'export', | ||
userAccounts: { | ||
connect: { | ||
id: user.id, | ||
}, | ||
}, | ||
}, | ||
}), | ||
).pipe(ignoreElements(), endWith(value)); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters