<commit_before>var express = require('express');
var monk = require('monk');
var bodyParser = require('body-parser');

var dbAPI = require('api/db.js');
var common = require('api/routing_common.js');

var Item = require('api/models/Item.js');
var Reservation = require('api/models/Reservation.js');

var router = express.Router();
router.use(bodyParser.json());


/* Get info on all part reservations. */
router.get('/reservations', (req, res) => {
    dbAPI.reservations.find({}, {}).then(
        (docs) => {
            promises = docs.map(
                (doc) => {
                    rsvp = new Reservation(doc._id);
                    return rsvp.summary();
                }
            );

            return Promise.all(promises);
        }
    ).then(common.jsonSuccess(res)).catch(common.apiErrorHandler(req, res));
});

/* Add new reservation.
   Parameters:
    - "part": part ID to reserve.
    - "count": number of parts to reserve.
    - "requester": ID of user to reserve the parts under.
    - "asm" [optional]: Assembly ID to reserve the parts for.
 */
router.post('/reservations', (req, res) => {
    common.checkRequestParameters(req, 'part', 'count', 'requester').then(
        () => {
            var item = new Item(monk.id(req.body.part));
            var requester = new User(monk.id(req.body.requester));

            return Promise.all([item.exists(), requester.exists()]);
        }
    ).then(
        (retns) => {
            item_exists = retns[0];
            requester_exists = retns[1];

            if(!item_exists) return Promise.reject("Requested part does not exist!");
            if(!requester_exists) return Promise.reject("Requesting user does not exist!");

            return item.available();
        }
    ).then(
        (avail_parts) => {
            requested_parts = parseInt(req.body.count);
            if(requested_parts > avail_parts)<commit_msg>Finish moving Reservations over to UserIDs for requester<commit_after>var express = require('express');
var monk = require('monk');
var bodyParser = require('body-parser');

var dbAPI = require('api/db.js');
var common = require('api/routing_common.js');

var Item = require('api/models/Item.js');
var Reservation = require('api/models/Reservation.js');
var User = require('api/models/User.js');

var router = express.Router();
router.use(bodyParser.json());


/* Get info on all part reservations. */
router.get('/reservations', (req, res) => {
    dbAPI.reservations.find({}, {}).then(
        (docs) => {
            promises = docs.map(
                (doc) => {
                    rsvp = new Reservation(doc._id);
                    return rsvp.summary();
                }
            );

            return Promise.all(promises);
        }
    ).then(common.jsonSuccess(res)).catch(common.apiErrorHandler(req, res));
});

/* Add new reservation.
   Parameters:
    - "part": part ID to reserve.
    - "count": number of parts to reserve.
    - "requester": ID of user to reserve the parts under.
    - "asm" [optional]: Assembly ID to reserve the parts for.
 */
router.post('/reservations', (req, res) => {
    common.checkRequestParameters(req, 'part', 'count', 'requester').then(
        () => {
            var item = new Item(monk.id(req.body.part));
            var requester = new User(monk.id(req.body.requester));

            return Promise.all([item.exists(), requester.exists(), item]);
        }
    ).then(
        (retns) => {
            item_exists = retns[0];
            requester_exists = retns[1];
            item = retns[2];

            if(!item_exists) return Promise.reject("Requested part does not exist!");
            if(!requester_exists) return Promise.reject("Requesting user does not exist!");

            return item.available();
        }
    ).then(
        (avail_parts) => {
            requested_parts = parseInt(req.body.count);
            if(requested_parts > avail_parts)
{'fraction_non_alphanumeric': 0.15274949083503056, 'fraction_numerical': 0.0012729124236252546, 'mean_word_length': 2.372532188841202, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3055110', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1134, 'n_words': 268}