File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
http/download-submissions Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -147,8 +147,22 @@ export default async ctx => {
147147 throw error
148148 } )
149149
150- request . on ( 'done' , ( ) => {
150+ request . on ( 'done' , async ( ) => {
151151 dataStream . push ( null )
152+
153+ // Log the download event
154+ try {
155+ const logger = ( await pool . connect ( ) ) . request ( )
156+ logger . input ( 'userId' , user . info ( ctx ) . id )
157+ logger . input ( 'submissionIds' , JSON . stringify ( ids ) )
158+ logger . input ( 'submissionSearch' , search )
159+
160+ await logger . query ( `
161+ insert into DownloadLog (userId, submissionIds, submissionSearch)
162+ values (@userId, @submissionIds, @submissionSearch);` )
163+ } catch ( error ) {
164+ console . error ( 'Error logging download' , error . message )
165+ }
152166 } )
153167 } catch ( error ) {
154168 console . error ( error . message )
Original file line number Diff line number Diff line change @@ -18,6 +18,25 @@ create table Users (
1818create unique index users_unique_saeonId on Users(saeonId) where saeonId is not null ;
1919end
2020
21+ -- Downloads
22+ if not exists (
23+ select *
24+ from sys .objects
25+ where
26+ object_id = OBJECT_ID (N ' [dbo].[DownloadLog]' )
27+ and type = ' U'
28+ )
29+ begin
30+ create table DownloadLog (
31+ id int not null identity primary key ,
32+ userId int not null foreign key references Users (id),
33+ timestamp datetime2 not null default GETDATE (),
34+ submissionIds nvarchar (max ) null ,
35+ submissionSearch nvarchar (max ) null ,
36+ index ix_DownloadLog_userId nonclustered (userId)
37+ )
38+ end
39+
2140-- Logins
2241if not exists (
2342 select *
You can’t perform that action at this time.
0 commit comments