Skip to content

Commit

Permalink
Added download logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zachsa committed Oct 10, 2022
1 parent d36098f commit d49e4b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/api/src/http/download-submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,22 @@ export default async ctx => {
throw error
})

request.on('done', () => {
request.on('done', async () => {
dataStream.push(null)

// Log the download event
try {
const logger = (await pool.connect()).request()
logger.input('userId', user.info(ctx).id)
logger.input('submissionIds', JSON.stringify(ids))
logger.input('submissionSearch', search)

await logger.query(`
insert into DownloadLog (userId, submissionIds, submissionSearch)
values (@userId, @submissionIds, @submissionSearch);`)
} catch (error) {
console.error('Error logging download', error.message)
}
})
} catch (error) {
console.error(error.message)
Expand Down
19 changes: 19 additions & 0 deletions src/api/src/mssql/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ create table Users (
create unique index users_unique_saeonId on Users(saeonId) where saeonId is not null;
end

-- Downloads
if not exists (
select *
from sys.objects
where
object_id = OBJECT_ID(N'[dbo].[DownloadLog]')
and type = 'U'
)
begin
create table DownloadLog (
id int not null identity primary key,
userId int not null foreign key references Users (id),
timestamp datetime2 not null default GETDATE(),
submissionIds nvarchar(max) null,
submissionSearch nvarchar(max) null,
index ix_DownloadLog_userId nonclustered (userId)
)
end

-- Logins
if not exists (
select *
Expand Down

0 comments on commit d49e4b2

Please sign in to comment.