Thursday 20 April 2017

Columns [meta] and [type] included in mssql query using holidayextras/jsonapi-server

I am using a jsonapi-server to connect to a mssql (SQL Server Express) instance using a jsonapi-server-relationaldb handler. I have defined a resource for "workers" following the example included in this project and receive the following error when attempting to query rest/workers:

"errors": [
    {
      "status": "500",
      "code": "EUNKNOWN",
      "title": "An unknown error has occured",
      "detail": "Something broke when connecting to the database - Invalid column name 'meta'."
    }
  ]

I've turned on logging to see the raw sequelize query string which is as follows:

SELECT [id], [type], [meta], [first_name], [last_name], [phone_number], [middle_name], [title], [suffix], [email_address], [birth_date], [date_created], [date_modified], [address_line1], [address_line2], [address_line3], [address_line4], [city], [state], [postal_code], [country], [clark_region] FROM [workers] AS [workers];

As you can see in the query, [meta] and [type] are bing included in the query string. What am I doing wrong?

Finally for reference, here is the workers resource model I've created:

const jsonApi = require('../../.')
const workersHandler = require('../handlers/workersHandler.js')

jsonApi.define({
  namespace: 'json:api',
  resource: 'workers',
  description: 'Registered subcontractor workers.',
  handlers: new RelationalDbStore({
    dialect: "mssql",
    host: "rnddevinstance.cg3oj9ysudvn.us-west-2.rds.amazonaws.com",
    port: 1433,
    database: "DevDB", // If not provided, defaults to the name of the resource
    username: "rnam",
    password: "administrator",
    logging: console.log
  }),
  searchParams: { },
  attributes: {
    first_name: jsonApi.Joi.string().alphanum().max(255).required()
      .description('The workers first name')
      .example('Jerry'),
    last_name: jsonApi.Joi.string().alphanum().max(255).required()
      .description('The workers last name')
      .example('Seinfeld'),
    phone_number: jsonApi.Joi.string().max(15).required()
      .description('Primary contact phone number')
      .example('(123) 456-7890'),
    middle_name: jsonApi.Joi.string().alphanum().max(255)
      .description('The workers middle name or initial')
      .example('C'),
    title: jsonApi.Joi.string().alphanum().max(8)
      .description('The workers title')
      .example('Mr'),
    suffix: jsonApi.Joi.string().alphanum().max(8)
      .description('The workers title')
      .example('Jr'),
    email_address: jsonApi.Joi.string().email().max(255)
      .description('The workers preferred contact email address')
      .example('jerry.seinfeld@gmail.com'),
    birth_date: jsonApi.Joi.string().regex(/^[12]\d\d\d-[01]\d-[0123]\d$/)
      .description('The workers birthday, YYYY-MM-DD')
      .example('1985-05-01'),
    date_created: jsonApi.Joi.string().required().regex(/^[12]\d\d\d-[01]\d-[0123]\d$/)
      .description('The day the worker was first registered in the system., YYYY-MM-DD')
      .example('2017-02-01'),
    date_modified: jsonApi.Joi.string().regex(/^[12]\d\d\d-[01]\d-[0123]\d$/)
      .description('The last day this workers profile was updated., YYYY-MM-DD')
      .example('2017-04-01'),
    address_line1: jsonApi.Joi.string().max(255)
      .description('The workers mailing address.')
      .example('7500 Old Georgetown Road'),
    address_line2: jsonApi.Joi.string().max(255)
      .description('The workers mailing address.')
      .example('R&D Office'),
    address_line3: jsonApi.Joi.string().max(255)
      .description('The workers mailing address.')
      .example('Metro Level'),
    address_line4: jsonApi.Joi.string().max(255)
      .description('The workers mailing address.')
      .example('Desk Number 1234'),
    city: jsonApi.Joi.string().max(255)
      .description('The workers city mailing address.')
      .example('Bethesda'),
    state: jsonApi.Joi.string().alphanum().max(2)
      .description('The workers mailing address state in abbreviated form. SS')
      .example('MD'),
    postal_code: jsonApi.Joi.string().alphanum().max(10)
      .description('The workers address postal code.')
      .example('21084'),
    country: jsonApi.Joi.string().max(255).default('United States')
      .description('The workers country of residence.')
      .example('United States'),
    clark_region: jsonApi.Joi.string().max(255)
      .description('Clark region of worker at the time of registration.')
      .example('Mid Atlantic')
  },
  examples: [
    {
      id: '12',
      type: 'people',
      first_name: 'Jerry',
      last_name: 'Seinfeld',
      email: 'jerry.seinfeld@example.com',
      phone_number: '(123) 456-7890',
      date_created: '2017-04-15'
    }
  ]
})



via Ryan Nam

No comments:

Post a Comment