Commit 9581c0dd authored by Mahdi Sellami's avatar Mahdi Sellami

-Added MongoDB -Implemented add Case application logic

parent 6b78c0de
......@@ -21,3 +21,9 @@ http.createServer(app).listen(serverPort, function () {
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
//Set up mongoose connection
var mongoose = require('mongoose');
var mongoDB = 'mongodb://127.0.0.1';
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
//Require Mongoose
var mongoose = require('mongoose');
//Define a schema
var Schema = mongoose.Schema;
var ApplicationSchema = new Schema({
verfahrensId : String,
leikaId : String,
responsibleAuthority : String,
statusId : String,
statusDescription : String,
statusLastChangeDate : String,
decisionDate : String,
decisionJustification : String,
//applicant : {type: Schema.Types.ObjectId, ref: 'Person'}
});
//Export function to create "Application" model class
module.exports = Application = mongoose.model('Application', ApplicationSchema );
\ No newline at end of file
//Require Mongoose
var mongoose = require('mongoose');
//Define a schema
var Schema = mongoose.Schema;
var PersonSchema = new Schema({
personId : String,
prename : String,
surname : String,
email : String,
//address : {type: Schema.Types.ObjectId, ref: 'PersonAdress'}
});
//Export function to create "Person" model class
module.exports = mongoose.model('Person', PersonSchema );
\ No newline at end of file
//Require Mongoose
var mongoose = require('mongoose');
//Define a schema
var Schema = mongoose.Schema;
var PersonAdressSchema = new Schema({
street : String,
houseno : String,
zip : String,
city : String,
country : String
});
//Export function to create "PersonAdress" model class
module.exports = mongoose.model('PersonAdress', PersonAdressSchema );
\ No newline at end of file
......@@ -15,6 +15,7 @@
"dependencies": {
"connect": "^3.2.0",
"js-yaml": "^3.3.0",
"mongoose": "^5.9.21",
"oas3-tools": "^2.0.2"
}
}
'use strict';
const Application = require('../models/application');
/**
* Submit a new application including the application documents for an administration case
......@@ -9,50 +9,8 @@
**/
exports.postCaseApplication = function(body) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"dataObjects" : [ {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
}, {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
} ],
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"decisionJustification" : "decisionJustification",
"responsibleAuthority" : "responsibleAuthority",
"decisionDate" : "2000-01-23T04:56:07.000+00:00",
"applicant" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
const applicationRecord = Application.create(body);
resolve(applicationRecord);
});
}
'use strict';
const Application = require('../models/application');
/**
......@@ -9,50 +10,8 @@
**/
exports.getCaseByVerfahrensId = function(verfahrensId) {
return new Promise(function(resolve, reject) {
var examples = {};
examples['application/json'] = {
"dataObjects" : [ {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
}, {
"dataObjectId" : "dataObjectId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"title" : "title",
"type" : "type",
"content" : { }
} ],
"statusDescription" : "statusDescription",
"statusLastChangeDate" : "2000-01-23T04:56:07.000+00:00",
"statusId" : "statusId",
"leikaId" : "leikaId",
"verfahrensId" : "verfahrensId",
"decisionJustification" : "decisionJustification",
"responsibleAuthority" : "responsibleAuthority",
"decisionDate" : "2000-01-23T04:56:07.000+00:00",
"applicant" : {
"address" : {
"zip" : "zip",
"country" : "country",
"city" : "city",
"street" : "street",
"houseno" : "houseno"
},
"surname" : "surname",
"personId" : "personId",
"prename" : "prename",
"email" : "email"
}
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
}
const applicationRecord = Application.findById(verfahrensId);
resolve(applicationRecord);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment