-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace dynamodb with dynamodb-toolbox v0.2
- Loading branch information
1 parent
c5e12f0
commit 267711a
Showing
10 changed files
with
80 additions
and
183 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
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 |
---|---|---|
|
@@ -17,5 +17,3 @@ exports.handler = async (event) => { | |
|
||
return event | ||
} | ||
|
||
// 12 |
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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import express from 'express' | ||
import wrapAsync from '../wrap-async' | ||
import { createUser, scanUsers } from '../../../controllers/user' | ||
import { createUser, scanUsers, getUser } from '../../../controllers/user' | ||
|
||
const userRouter = express.Router() | ||
userRouter.get('/', wrapAsync(async (req, res) => { | ||
const users = await scanUsers() | ||
res.json(users) | ||
})) | ||
|
||
userRouter.get('/:userId', wrapAsync(async (req, res) => { | ||
const { userId } = req.params | ||
const users = await getUser({ id: userId }) | ||
res.json(users) | ||
})) | ||
|
||
userRouter.post('/', wrapAsync(async (req, res) => { | ||
const { name } = req.body | ||
const user = await createUser({ name }) | ||
res.json(user) | ||
})) | ||
|
||
export default userRouter | ||
// 1 |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import dynamo from 'dynamodb' | ||
import Joi from '@hapi/joi' | ||
import { Table, Entity } from 'dynamodb-toolbox' | ||
import { dynamoDbDocumentClient } from '../dynamodb-init' | ||
|
||
const UserTable = new Table({ | ||
name: process.env.USER_TABLE, | ||
partitionKey: 'id', | ||
DocumentClient: dynamoDbDocumentClient, | ||
}) | ||
|
||
const User = dynamo.define('User', { | ||
hashKey: 'id', | ||
|
||
// add the timestamp attributes (updatedAt, createdAt) | ||
timestamps: true, | ||
|
||
schema: { | ||
id: Joi.string(), | ||
name: Joi.string(), | ||
const User = new Entity({ | ||
name: 'User', | ||
attributes: { | ||
id: { partitionKey: true }, | ||
name: { type: 'string' }, | ||
}, | ||
tableName: process.env.USER_TABLE, | ||
table: UserTable, | ||
}) | ||
|
||
export default User |
Oops, something went wrong.