-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
push before things become catastrophically bad
- Loading branch information
Showing
16 changed files
with
174 additions
and
55 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as db from '../../database' | ||
import { responses } from '../../responses' | ||
|
||
export default { | ||
method: 'POST', | ||
path: '/store/:id/buy', | ||
requireAuth: true, | ||
schema: { | ||
params: { | ||
type: 'object', | ||
properties: { | ||
id: { | ||
type: 'string' | ||
} | ||
}, | ||
required: ['id'] | ||
} | ||
}, | ||
handler: async ({ req, user }) => { | ||
const item = await db.store.getItemById({ id: req.params.id }) | ||
const userObj = await db.users.getUserById({ id: user.id }) | ||
if (userObj.chips >= item.price) { | ||
try { | ||
return [ | ||
responses.goodPurchase, | ||
await db.store.buyItem(userObj.id, item) | ||
] | ||
} catch (e) { | ||
if (e.constraint === 'already_owned') { | ||
return responses.badItemAlreadyOwned | ||
} | ||
|
||
throw e | ||
} | ||
} | ||
|
||
return responses.badPurchase | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default [ | ||
require('./buy').default, | ||
require('./list').default | ||
] |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { responses } from '../../responses' | ||
import * as store from '../../store' | ||
|
||
export default { | ||
method: 'GET', | ||
path: '/store', | ||
requireAuth: true, | ||
handler: async () => { | ||
const items = store.getAllItems() | ||
return [responses.goodItems, items] | ||
} | ||
} |
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
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
Oops, something went wrong.