Skip to content

Commit d49e4b2

Browse files
committed
Added download logs
1 parent d36098f commit d49e4b2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/api/src/http/download-submissions/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

src/api/src/mssql/sql/schema.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ create table Users (
1818
create unique index users_unique_saeonId on Users(saeonId) where saeonId is not null;
1919
end
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
2241
if not exists (
2342
select *

0 commit comments

Comments
 (0)