{"size": 1898, "ext": "js", "max_stars_repo_path": "marriage-app/routes/marriage-details.js", "max_stars_repo_name": "kamilslusarczyk/marriage_in_the_air", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "marriage-app/routes/marriage-details.js", "max_issues_repo_name": "kamilslusarczyk/marriage_in_the_air", "max_issues_repo_issues_event_min_datetime": "2017-11-25T09:25:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-13T13:39:02.000Z", "max_forks_repo_path": "marriage-app/routes/marriage-details.js", "max_forks_repo_name": "kamilslusarczyk/marriage-in-the-air", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 29.65625, "max_line_length": 103, "alphanum_fraction": 0.5532139094}
var express = require('express');
var router = express.Router();
var ObjectId = require('mongodb').ObjectID;
var ExceptionService = require('../services/exceptionService');
var AuthenticationService = require('../services/authenticationService');
var jwt = require('jsonwebtoken');
var MarriageDetails = require('../models/marriageDetails');

//get all
router.get('/', function (req, res, next) {
    MarriageDetails.find()
        .exec(function (err, docs) {
            if (err)
                return res.status(500).json({
                    message: "nope.",
                    data: err
                });
            var error = ExceptionService.MongoosHelper.HandleRequest(err, null, docs, res);

            if (error)
                return error;

            res.status(200).json({
                mssage: "Marriage details retreived properly.",
                data: docs
            });
        });
});

router.post('/', function (req, res, next) {
    var verified = AuthenticationService.AuthenticationHelper.Authenticate(req.query.token, next, res);
    if(!verified)
        return res.status(401).json({
            title: "NOT PERMITTED",
            error: "NOT PERMITTED"
        });

    MarriageDetails.remove({}, function (err) {

        if (err)
            return error;

        var details = new MarriageDetails({
            content: req.body.content,
            dateOfPublication: req.body.dateOfPublication,
            latitude: req.body.latitude,
            longtitude: req.body.longtitude
        });
        details.save(function (err, result) {
            var error = ExceptionService.MongoosHelper.HandleRequest(err, null, result, res);

            if (error)
                return error;

            res.status(201).json({
                message: "Ok!",
                data: true
            });
        });
    });
});

module.exports = router;
