<commit_before>var app = require('../../server/server')

module.exports = function (AvailableCodes) {
  // this is the logic for accepting a request to add codes from the client and
  // adding the new codes to the database
  AvailableCodes.add = function (productId, codes, cb) {
    // grab the object representing the SQL data
    var availableCodes = app.datasources.mysqlDs.models.availableCodes
    codes.forEach(function (val) {
      availableCodes.create({
        productId: productId,
        code: val
      }, function (err) {
        if (err) {throw err}
      })
    })
    cb(null, {productId: productId, codes: codes})
  }

  // this registers the above 'add' function as a remote array of our model and
  // makes it available via URL in our API
  AvailableCodes.remoteMethod(
    'add',
    {
      accepts: [
        {arg: 'productId', type: 'string'},
        {arg: 'codes', type: 'array'}
      ],
      returns: [
        {arg: 'productId', type: 'string'},
        {arg: 'codes', type: 'array'}
      ],
      http: {path: '/addCodes'}
    }<commit_msg>change availableCodes model to correct datasource<commit_after>var app = require('../../server/server')

module.exports = function (AvailableCodes) {
  // this is the logic for accepting a request to add codes from the client and
  // adding the new codes to the database
  AvailableCodes.add = function (productId, codes, cb) {
    // grab the object representing the SQL data
    var availableCodes = app.datasources.mydb.models.availableCodes
    codes.forEach(function (val) {
      availableCodes.create({
        productId: productId,
        code: val
      }, function (err) {
        if (err) {throw err}
      })
    })
    cb(null, {productId: productId, codes: codes})
  }

  // this registers the above 'add' function as a remote array of our model and
  // makes it available via URL in our API
  AvailableCodes.remoteMethod(
    'add',
    {
      accepts: [
        {arg: 'productId', type: 'string'},
        {arg: 'codes', type: 'array'}
      ],
      returns: [
        {arg: 'productId', type: 'string'},
        {arg: 'codes', type: 'array'}
      ],
      http: {path: '/addCodes'}
    }
{'fraction_non_alphanumeric': 0.12528577960676726, 'fraction_numerical': 0.0, 'mean_word_length': 2.529032258064516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4129549', 'n_tokens_mistral': 630, 'n_tokens_neox': 639, 'n_words': 217}