Skip to content

Commit

Permalink
Add a UserSearchLog table
Browse files Browse the repository at this point in the history
  • Loading branch information
kmjennison committed Mar 19, 2019
1 parent 3f987f3 commit 5fadb08
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dynamodb/serverless.yml
Expand Up @@ -119,6 +119,15 @@ custom:
minimum: 1
maximum: 1000
usage: 0.60
userSearchLogTable:
read:
minimum: 1
maximum: 1000
usage: 0.75
write:
minimum: 1
maximum: 1000
usage: 0.60
referralDataLogTable:
read:
minimum: 1
Expand Down Expand Up @@ -230,6 +239,15 @@ custom:
minimum: 30
maximum: 9001
usage: 0.60
userSearchLogTable:
read:
minimum: 1
maximum: 9001
usage: 0.75
write:
minimum: 1
maximum: 9001
usage: 0.60
referralDataLogTable:
read:
minimum: 20
Expand Down Expand Up @@ -345,6 +363,15 @@ custom:
minimum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.minimum}
maximum: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.maximum}
usage: ${self:custom.customCapacities.${self:provider.stage}.userTabsLogTable.write.usage}
- table: userSearchLogTable
read:
minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.minimum}
maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.maximum}
usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.read.usage}
write:
minimum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.minimum}
maximum: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.maximum}
usage: ${self:custom.customCapacities.${self:provider.stage}.userSearchLogTable.write.usage}
- table: referralDataLogTable
index:
- ReferralsByReferrer
Expand Down Expand Up @@ -560,6 +587,24 @@ resources:
ReadCapacityUnits: 1
WriteCapacityUnits: 1

userSearchLogTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: UserSearchLog-${self:provider.stage}
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: timestamp
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1

referralDataLogTable:
Type: AWS::DynamoDB::Table
Properties:
Expand Down
15 changes: 15 additions & 0 deletions dynamodb/tables.json
Expand Up @@ -173,6 +173,21 @@
"WriteCapacityUnits": 1
}
},
{
"TableName": "UserSearchLog",
"KeySchema": [
{ "AttributeName": "userId", "KeyType": "HASH" },
{ "AttributeName": "timestamp", "KeyType": "RANGE" }
],
"AttributeDefinitions": [
{ "AttributeName": "userId", "AttributeType": "S" },
{ "AttributeName": "timestamp", "AttributeType": "S" }
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
},
{
"TableName": "ReferralDataLog",
"KeySchema": [{ "AttributeName": "userId", "KeyType": "HASH" }],
Expand Down
1 change: 1 addition & 0 deletions graphql/database/constants.js
Expand Up @@ -7,6 +7,7 @@ export const USER_WIDGET = 'UserWidget'
export const VC_DONATION = 'VcDonation'
export const VC_DONATION_BY_CHARITY = 'VcDonationByCharity'
export const USER_TABS_LOG = 'UserTabsLog'
export const USER_SEARCH_LOG = 'UserSearchLog'
export const USER_LEVEL = 'UserLevel'
export const BACKGROUND_IMAGE = 'BackgroundImage'
export const USER_RECRUITS = 'UserRecruits'
Expand Down
1 change: 1 addition & 0 deletions graphql/database/tables.js
Expand Up @@ -17,6 +17,7 @@ const tables = {
widgets: 'Widgets',
userWidgets: 'UserWidgets',
userTabsLog: 'UserTabsLog',
userSearchLog: 'UserSearchLog',
referralDataLog: 'ReferralDataLog',
}

Expand Down
47 changes: 47 additions & 0 deletions graphql/database/users/UserSearchLogModel.js
@@ -0,0 +1,47 @@
import BaseModel from '../base/BaseModel'
import types from '../fieldTypes'
import tableNames from '../tables'
import { USER_SEARCH_LOG } from '../constants'
import { permissionAuthorizers } from '../../utils/authorization-helpers'

/*
* @extends BaseModel
*/
class UserSearchLog extends BaseModel {
static get name() {
return USER_SEARCH_LOG
}

static get hashKey() {
return 'userId'
}

static get rangeKey() {
return 'timestamp'
}

static get tableName() {
return tableNames.userSearchLog
}

static get schema() {
return {
userId: types.string().required(),
timestamp: types
.string()
.isoDate()
.required(),
source: types.string(),
}
}

static get permissions() {
return {
create: permissionAuthorizers.userIdMatchesHashKey,
}
}
}

UserSearchLog.register()

export default UserSearchLog
39 changes: 39 additions & 0 deletions graphql/database/users/__tests__/UserSearchLogModel.test.js
@@ -0,0 +1,39 @@
/* eslint-env jest */

import tableNames from '../../tables'
import UserSearchLogModel from '../UserSearchLogModel'
import { permissionAuthorizers } from '../../../utils/authorization-helpers'

jest.mock('../../databaseClient')

describe('UserSearchLogModel', () => {
it('implements the name property', () => {
expect(UserSearchLogModel.name).toBe('UserSearchLog')
})

it('implements the hashKey property', () => {
expect(UserSearchLogModel.hashKey).toBe('userId')
})

it('implements the tableName property', () => {
expect(UserSearchLogModel.tableName).toBe(tableNames.userSearchLog)
})

it('has the correct get permission', () => {
expect(UserSearchLogModel.permissions.get).toBeUndefined()
})

it('has the correct getAll permission', () => {
expect(UserSearchLogModel.permissions.getAll).toBeUndefined()
})

it('has the correct update permission', () => {
expect(UserSearchLogModel.permissions.update).toBeUndefined()
})

it('has the correct create permission', () => {
expect(UserSearchLogModel.permissions.create).toBe(
permissionAuthorizers.userIdMatchesHashKey
)
})
})
5 changes: 5 additions & 0 deletions graphql/integration-tests/utils/table-utils.js
Expand Up @@ -47,6 +47,10 @@ export const tableKeys = {
hash: 'userId',
range: 'timestamp',
},
userSearchLog: {
hash: 'userId',
range: 'timestamp',
},
referralDataLog: {
hash: 'userId',
range: null,
Expand All @@ -63,5 +67,6 @@ export const tableFixtureFileNames = {
widgets: 'Widgets.json',
userWidgets: 'UserWidgets.json',
userTabsLog: '',
userSearchLog: '',
referralDataLog: 'ReferralDataLog.json',
}
5 changes: 5 additions & 0 deletions graphql/serverless.yml
Expand Up @@ -94,6 +94,11 @@ provider:
Action:
- "dynamodb:PutItem"
Resource: "${self:custom.dbTableArnBase}UserTabsLog-${self:provider.stage}"
# UserSearchLog table
- Effect: "Allow"
Action:
- "dynamodb:PutItem"
Resource: "${self:custom.dbTableArnBase}UserSearchLog-${self:provider.stage}"
# UserRevenueLog table
- Effect: "Allow"
Action:
Expand Down
1 change: 1 addition & 0 deletions lambda/src/utils/tables.js
Expand Up @@ -16,6 +16,7 @@ const tables = {
widgets: 'Widgets',
userWidgets: 'UserWidgets',
userTabsLog: 'UserTabsLog',
userSearchLog: 'UserSearchLog',
referralDataLog: 'ReferralDataLog',
}

Expand Down

0 comments on commit 5fadb08

Please sign in to comment.