<commit_before>function onPreSave(request,response,modules){
  var rooms = modules.collectionAccess.collection('conferencerooms');

  // find the first available room, and set available = false if one is found.  
  rooms.findAndModify({"available":true}, {"lastUsed": 1}, {$set: {"available": false, "lastUsed": request.body.bookingTime}}, function(err, result) {
    if (err) {
      // Database query error, return an error response to the client and terminate the request
      response.error(err);
    } else {
      // If no rooms found, End the request without saving, with a message of "no resource available"
      if (!result._id) {
        response.body = {message: "No Resources Available"};
        response.complete();  // completes the request and returns the result to the client 
      } else {
        // If a room was found, add the room to the temp object store, 
        // and add the room ID and name to the request for saving to the bookings collection
        modules.utils.tempObjectStore.set("room", result);
        request.body.room = {id: result._id, name: result.name};
        response.continue();    // continues the request 
      }
    }
  }); 
}<commit_msg>Modified error message to reflect rooms rather than resources<commit_after>/**
 * Copyright (c) 2014 Kinvey, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function onPreSave(request,response,modules){
  var rooms = modules.collectionAccess.collection('conferencerooms');

  // find the first available room, and set available = false if one is found.  
  rooms.findAndModify({"available":true}, {"lastUsed": 1}, {$set: {"available": false, "lastUsed": request.body.bookingTime}}, function(err, result) {
    if (err) {
      // Database query error, return an error response to the client and terminate the request
      response.error(err);
    } else {
      // If no rooms found, End the request without saving, with a message of "no rooms available"
      if (!result._id) {
        response.body = {message: "No Rooms Available"};
        response.complete();  // completes the request and returns the result to the client 
      } else {
        // If a room was found, add the room to the temp object store, 
        // and add the room ID and name to the request for saving to the bookings collection
        modules.utils.tempObjectStore.set("room", result);
        request.body.room = {id: result._id, name: result.name};
        response.continue();    // continues the request 
      }
    }
  }); 
}
{'fraction_non_alphanumeric': 0.1024454725710509, 'fraction_numerical': 0.003304692663582287, 'mean_word_length': 3.1239782016348774, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '6808452', 'n_tokens_mistral': 797, 'n_tokens_neox': 774, 'n_words': 334}