Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PStA WP2 OmarElkadi1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Omar Elkadi
PStA WP2 OmarElkadi1
Commits
293c1a05
Commit
293c1a05
authored
3 years ago
by
Omar Elkadi
Browse files
Options
Downloads
Patches
Plain Diff
sicknotefile name = matrikel + auto file extention
parent
3c453414
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/src/routes/patientRoutes.ts
+26
-21
26 additions, 21 deletions
server/src/routes/patientRoutes.ts
src/views/SickForm.vue
+6
-4
6 additions, 4 deletions
src/views/SickForm.vue
with
32 additions
and
25 deletions
server/src/routes/patientRoutes.ts
+
26
−
21
View file @
293c1a05
import
{
NextFunction
,
Request
,
Response
,
Router
}
from
"
express
"
;
import
{
writeFile
}
from
"
fs
"
;
import
multer
=
require
(
"
multer
"
);
import
{
extname
}
from
"
path
"
;
//import * as bodyParser from "body-parser"; // not necessary, since body-parser is part of NodeJS
export
class
patientRoutes
{
...
...
@@ -14,21 +16,26 @@ export class patientRoutes {
routes
()
{
// configure a multer Storage (folder + filename)
// configure a multer Storage
path
(folder + filename)
var
storage
=
multer
.
diskStorage
({
destination
:
function
(
req
,
file
,
cb
)
{
destination
:
function
(
req
,
file
,
cb
)
{
//uploads is the folder name
cb
(
null
,
"
uploads
"
);
},
filename
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
Date
.
now
()
+
'
-
'
+
file
.
fieldname
+
'
.pdf
'
);
filename
:
function
(
req
,
file
,
cb
)
{
var
patientStudent
=
JSON
.
parse
(
req
.
body
.
patientStudent
);
cb
(
null
,
patientStudent
.
MatrikelNumber
+
extname
(
file
.
originalname
)
);
}
});
//create upload instance (will recive the file and the body from request)
var
upload
=
multer
({
storage
:
storage
});
console
.
log
(
"
patient routes
"
);
// recives the file from request
this
.
router
.
post
(
"
/ppatient
"
,
upload
.
single
(
'
evd
'
)
,
this
.
post
);
// recives the file from request
-> the name of the file in the single() must be the same on the client side in FormData
this
.
router
.
post
(
"
/ppatient
"
,
upload
.
single
(
'
sickNoteEvidence
'
)
,
this
.
post
);
this
.
router
.
get
(
"
/patient
"
,
this
.
get
);
}
...
...
@@ -41,31 +48,29 @@ export class patientRoutes {
post
(
req
:
Request
,
res
:
Response
)
{
//recived the body as a stringified JOSN
var
body
=
req
.
body
;
// response body
// parse JSON to Objects
var
patientStudent
=
JSON
.
parse
(
body
.
patientStudent
)
var
sickNote
=
JSON
.
parse
(
body
.
sickNoteData
);
var
sicknessReport
=
{
patientStudent
,
sickNote
}
const
file
=
req
.
file
;
if
(
!
file
)
{
console
.
log
(
"
not file error
"
)
}
var
patientStudent
=
JSON
.
parse
(
body
.
patientStudent
)
var
sickNote
=
JSON
.
parse
(
body
.
sickNote
)
body
=
{
patientStudent
,
sickNote
}
res
.
status
(
200
).
send
(
"
the body and the file are recived
"
+
JSON
.
stringify
(
body
))
console
.
log
(
typeof
(
body
))
console
.
log
(
typeof
(
patientStudent
))
console
.
log
(
typeof
(
sickNote
))
const
path
=
'
./public/
'
+
patientStudent
.
MatrikelNumber
+
'
.json
'
const
path
=
'
./public/
'
+
'
sickNoteReport
'
+
patientStudent
.
MatrikelNumber
+
'
.json
'
writeFile
(
path
,
JSON
.
stringify
(
body
),
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
)
else
return
console
.
log
(
'
file generated in path:
'
+
path
)
writeFile
(
path
,
JSON
.
stringify
(
sicknessReport
),
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
)
;
else
return
console
.
log
(
"
file generated in path:
"
+
path
)
;
});
}
...
...
This diff is collapsed.
Click to expand it.
src/views/SickForm.vue
+
6
−
4
View file @
293c1a05
...
...
@@ -111,7 +111,8 @@
</div>
<div
class=
"form-group col-md-4"
>
<label
for=
"formFile"
class=
"form-label"
>
Krankmeldung
</label>
<input
class=
"form-control"
type=
"file"
id=
"formFile"
ref=
"file"
accept=
".pdf|.docx|image/*"
@
change=
"handleFileUpload()"
>
<!-- set a refrence on tag using ref="file" will allow us to get the file -->
<input
class=
"form-control"
type=
"file"
id=
"formFile"
ref=
"file"
accept=
".pdf,.docx,image/*"
@
change=
"handleFileUpload()"
required
>
</div>
</div>
<!--
...
...
@@ -402,7 +403,7 @@ export default {
}
},
methods
:
{
handleFileUpload
(
event
)
{
handleFileUpload
()
{
this
.
EvidenceFile
=
this
.
$refs
.
file
.
files
[
0
]
},
async
OnSubmit
()
{
...
...
@@ -410,8 +411,9 @@ export default {
// FormData is a dictionary type -> (key , value)
formData
.
append
(
'
patientStudent
'
,
JSON
.
stringify
(
this
.
patientStudent
))
formData
.
append
(
'
sickNote
'
,
JSON
.
stringify
(
this
.
SickNote
))
formData
.
append
(
'
file
'
,
this
.
EvidenceFile
)
formData
.
append
(
'
sickNoteData
'
,
JSON
.
stringify
(
this
.
SickNote
))
formData
.
append
(
'
sickNoteEvidence
'
,
this
.
EvidenceFile
)
var
res
=
await
axios
.
post
(
'
http://localhost:3000/ppatient
'
,
formData
,
{
...
...
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