Commit 895cf924 authored by Mahdi Sellami's avatar Mahdi Sellami

verify existance of the service before accepting application

parent c9e94d53
'use strict';
const Application = require('../models/application');
const Service = require('../models/service');
/**
* Submit a new application including the application documents for an administration case
......@@ -10,12 +11,19 @@ const Application = require('../models/application');
exports.postCaseApplication = function(body) {
return new Promise(function(resolve, reject) {
// TODO maybe remove VerfahrensId later (discuss with Peter)
var applicationRecord = Application.create(body).then(function(doc) {
doc.verfahrensId = doc.id
doc.save()
return doc
});
resolve(applicationRecord);
//Verify if the leikaId exists
const serviceRecord = Service.findOne({leikaId: body.leikaId}, function (err, result) {
if (!result) {
reject({error: 'The service with ID ' + body.leikaId + ' is not available here.'})
} else {
var applicationRecord = Application.create(body).then(function(doc) {
doc.verfahrensId = doc.id
doc.save()
return doc
});
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