Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
64aebc22
Commit
64aebc22
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
ParamsCallback => Add callback on enonce name or url
parent
43738359
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExpressAPI/src/middlewares/ParamsCallbackManager.ts
+7
-3
7 additions, 3 deletions
ExpressAPI/src/middlewares/ParamsCallbackManager.ts
ExpressAPI/src/models/ApiRequest.ts
+4
-1
4 additions, 1 deletion
ExpressAPI/src/models/ApiRequest.ts
with
11 additions
and
4 deletions
ExpressAPI/src/middlewares/ParamsCallbackManager.ts
+
7
−
3
View file @
64aebc22
...
@@ -2,6 +2,7 @@ import { Express } from 'express-serve-static-core';
...
@@ -2,6 +2,7 @@ import { Express } from 'express-serve-static-core';
import
ApiRequest
from
'
../models/ApiRequest
'
;
import
ApiRequest
from
'
../models/ApiRequest
'
;
import
express
from
'
express
'
;
import
express
from
'
express
'
;
import
{
StatusCodes
}
from
'
http-status-codes
'
;
import
{
StatusCodes
}
from
'
http-status-codes
'
;
import
EnonceManager
from
'
../managers/EnonceManager
'
;
class
ParamsCallbackManager
{
class
ParamsCallbackManager
{
...
@@ -18,8 +19,8 @@ class ParamsCallbackManager {
...
@@ -18,8 +19,8 @@ class ParamsCallbackManager {
}
}
protected
listenParam
(
paramName
:
string
,
backend
:
Express
,
context
:
any
,
functionName
:
string
,
indexName
:
string
)
{
protected
listenParam
(
paramName
:
string
,
backend
:
Express
,
context
:
any
,
functionName
:
string
,
indexName
:
string
)
{
backend
.
param
(
paramName
,
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
,
id
:
number
|
string
)
=>
{
backend
.
param
(
paramName
,
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
,
id
:
string
|
number
)
=>
{
(
context
[
functionName
]
as
(
id
:
number
|
Array
<
number
>
)
=>
Promise
<
any
>
)(
typeof
id
===
'
string
'
?
JSON
.
parse
(
id
)
as
Array
<
number
>
:
id
).
then
(
result
=>
{
(
context
[
functionName
]
as
(
id
:
string
|
number
)
=>
Promise
<
any
>
)(
id
).
then
(
result
=>
{
if
(
result
)
{
if
(
result
)
{
this
.
initBoundParams
(
req
);
this
.
initBoundParams
(
req
);
(
req
.
boundParams
as
any
)[
indexName
]
=
result
;
(
req
.
boundParams
as
any
)[
indexName
]
=
result
;
...
@@ -34,11 +35,14 @@ class ParamsCallbackManager {
...
@@ -34,11 +35,14 @@ class ParamsCallbackManager {
initBoundParams
(
req
:
ApiRequest
)
{
initBoundParams
(
req
:
ApiRequest
)
{
if
(
!
req
.
boundParams
)
{
if
(
!
req
.
boundParams
)
{
req
.
boundParams
=
{};
req
.
boundParams
=
{
enonce
:
null
};
}
}
}
}
register
(
backend
:
Express
)
{
register
(
backend
:
Express
)
{
this
.
listenParam
(
'
enonceNameOrUrl
'
,
backend
,
EnonceManager
,
'
get
'
,
'
enonce
'
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/models/ApiRequest.ts
+
4
−
1
View file @
64aebc22
import
express
from
'
express
'
;
import
express
from
'
express
'
;
import
Session
from
'
../controllers/Session
'
;
import
Session
from
'
../controllers/Session
'
;
import
Enonce
from
'
./Enonce
'
;
type
ApiRequest
=
express
.
Request
&
{
type
ApiRequest
=
express
.
Request
&
{
session
:
Session
,
boundParams
:
{}
session
:
Session
,
boundParams
:
{
enonce
:
Enonce
}
}
}
...
...
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