Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Omar Elkadi
PStA WP2 OmarElkadi1
Commits
420efe85
Commit
420efe85
authored
Jun 25, 2021
by
Omar Elkadi
Browse files
impelement MongoDb
parent
8ac2cc11
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/src/routes/patientRoutes.ts
View file @
420efe85
...
...
@@ -48,22 +48,46 @@ export class patientRoutes {
// parse JSON to Objects
var
patientStudent
=
JSON
.
parse
(
body
.
patientStudent
);
var
sickNote
=
JSON
.
parse
(
body
.
SickNote
);
var
message
=
JSON
.
parse
(
body
.
Message
);
const
file
=
req
.
file
;
if
(
!
file
)
{
console
.
log
(
"
not file error
"
);
}
const
path
=
"
./uploads/reports/
"
+
patientStudent
.
MatrikelNumber
+
"
.json
"
;
var
sick
ness
Report
=
{
var
sickReport
=
{
patientStudent
,
sickNote
,
message
,
sickNoteFilePath
:
path
,
};
writeFile
(
path
,
JSON
.
stringify
(
sicknessReport
),
function
(
err
)
{
}
const
file
=
req
.
file
;
if
(
!
file
||
sickReport
==
null
)
{
console
.
log
(
"
the data is invalid
"
);
return
res
.
status
(
400
).
send
(
"
Bad Request
"
);
}
// define mongoDb instance
var
MongoClient
=
require
(
'
mongodb
'
).
MongoClient
// connect to the server
MongoClient
.
connect
(
'
mongodb://localhost:27017
'
,
async
function
(
err
,
client
)
{
if
(
err
)
throw
err
// cereat the DB instance
var
db
=
client
.
db
(
'
admin
'
)
// create the collection if not exist
try
{
await
db
.
createCollection
(
"
Students
"
,{}
)
console
.
log
(
"
Collection Student is created
"
)
}
catch
(
error
){
console
.
log
(
"
Collection already exists, so it didnot be created
"
)
}
// define a collection and insert a new record
try
{
await
db
.
collection
(
'
Students
'
).
insertOne
(
sickReport
)
console
.
log
(
"
a record added succsully to the collection Students
"
)
}
catch
(
error
)
{
console
.
log
(
error
)
}
})
// save the recived Object as Json file with the mat number as a name
writeFile
(
path
,
JSON
.
stringify
(
sickReport
),
function
(
err
)
{
if
(
err
)
return
console
.
log
(
err
);
else
return
console
.
log
(
"
file generated in path:
"
+
path
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment