Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaGer Keymanager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer Keymanager
Commits
9a4a7e4c
Commit
9a4a7e4c
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
fixed response code for too many charges
parent
8865ca7a
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#7269
passed
2 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/api.md
+1
-1
1 addition, 1 deletion
docs/api.md
pass/routes/api.js
+18
-15
18 additions, 15 deletions
pass/routes/api.js
with
19 additions
and
16 deletions
docs/api.md
+
1
−
1
View file @
9a4a7e4c
...
@@ -108,7 +108,7 @@ Can take either amount or price. If both supplied only amount is taken into acco
...
@@ -108,7 +108,7 @@ Can take either amount or price. If both supplied only amount is taken into acco
### Example Response
### Example Response
Successfull discharge will have a response code of
`201`
Successfull discharge will have a response code of
`201`
If the key cannot be charged because it is already charged with too many Orders response code will be
`4
0
3`
If the key cannot be charged because it is already charged with too many Orders response code will be
`4
2
3`
```
json
```
json
{
{
...
...
This diff is collapsed.
Click to expand it.
pass/routes/api.js
+
18
−
15
View file @
9a4a7e4c
...
@@ -26,7 +26,7 @@ router.use((req, res, next) => {
...
@@ -26,7 +26,7 @@ router.use((req, res, next) => {
}
}
});
});
router
.
post
(
"
/key/create
"
,
(
req
,
res
)
=>
{
router
.
post
(
"
/key/create
"
,
async
(
req
,
res
)
=>
{
let
amount
=
req
.
body
.
amount
;
let
amount
=
req
.
body
.
amount
;
if
(
!
amount
)
{
if
(
!
amount
)
{
// If amount is not given but price is
// If amount is not given but price is
...
@@ -46,11 +46,9 @@ router.post("/key/create", (req, res) => {
...
@@ -46,11 +46,9 @@ router.post("/key/create", (req, res) => {
/**
/**
* @type {Order}
* @type {Order}
*/
*/
let
key
=
await
Key
.
GET_NEW_KEY
();
let
new_order
;
let
new_order
;
Key
.
GET_NEW_KEY
()
Order
.
CREATE_NEW_ORDER
(
amount
,
key
.
get_key
(),
new
Manual
(
note
))
.
then
((
key
)
=>
Order
.
CREATE_NEW_ORDER
(
amount
,
key
.
get_key
(),
new
Manual
(
note
))
)
.
then
((
order
)
=>
{
.
then
((
order
)
=>
{
new_order
=
order
;
new_order
=
order
;
return
new_order
.
captureOrder
();
return
new_order
.
captureOrder
();
...
@@ -64,9 +62,11 @@ router.post("/key/create", (req, res) => {
...
@@ -64,9 +62,11 @@ router.post("/key/create", (req, res) => {
});
});
})
})
.
catch
((
reason
)
=>
{
.
catch
((
reason
)
=>
{
res
.
status
(
403
).
json
({
res
.
status
(
423
).
json
({
code
:
403
,
code
:
423
,
error
:
"
Cannot create Order for given Key
"
,
error
:
reason
,
key
:
key
.
get_key
(),
charged
:
0
});
});
});
});
});
});
...
@@ -115,7 +115,7 @@ router.post("/key/:key/discharge", (req, res) => {
...
@@ -115,7 +115,7 @@ router.post("/key/:key/discharge", (req, res) => {
});
});
});
});
router
.
post
(
"
/key/:key/charge
"
,
(
req
,
res
)
=>
{
router
.
post
(
"
/key/:key/charge
"
,
async
(
req
,
res
)
=>
{
let
amount
=
req
.
body
.
amount
;
let
amount
=
req
.
body
.
amount
;
if
(
!
amount
)
{
if
(
!
amount
)
{
// If amount is not given but price is
// If amount is not given but price is
...
@@ -137,24 +137,27 @@ router.post("/key/:key/charge", (req, res) => {
...
@@ -137,24 +137,27 @@ router.post("/key/:key/charge", (req, res) => {
/**
/**
* @type {Order}
* @type {Order}
*/
*/
let
key
=
await
Key
.
GET_KEY
(
req
.
params
.
key
);
let
new_order
=
null
;
let
new_order
=
null
;
Order
.
CREATE_NEW_ORDER
(
amount
,
req
.
params
.
key
,
new
Manual
(
note
))
Order
.
CREATE_NEW_ORDER
(
amount
,
key
.
get_
key
()
,
new
Manual
(
note
))
.
then
((
order
)
=>
{
.
then
((
order
)
=>
{
new_order
=
order
;
new_order
=
order
;
return
new_order
.
captureOrder
();
return
new_order
.
captureOrder
();
})
})
.
then
(()
=>
new_order
.
chargeKey
())
.
then
(()
=>
new_order
.
chargeKey
())
.
then
(
async
()
=>
{
.
then
(()
=>
{
res
.
status
(
201
).
json
({
res
.
status
(
201
).
json
({
key
:
await
new_order
.
getKeyFromOrderLink
(),
key
:
key
.
get_key
(),
order_id
:
new_order
.
getOrderID
(),
order_id
:
new_order
.
getOrderID
(),
charged
:
new_order
.
getAmount
(),
charged
:
new_order
.
getAmount
(),
});
});
})
})
.
catch
((
reason
)
=>
{
.
catch
((
reason
)
=>
{
res
.
status
(
403
).
json
({
res
.
status
(
423
).
json
({
code
:
403
,
code
:
423
,
error
:
"
Cannot create Order for given Key
"
,
error
:
reason
,
key
:
key
.
get_key
(),
charged
:
0
});
});
});
});
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment