Skip to content

Commit

Permalink
Fixes issue for sequelize 4 (when passed logger uses JSON.stringify #572
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RobinBuschmann committed May 1, 2019
1 parent e7eb258 commit 6c23dc2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
13 changes: 8 additions & 5 deletions lib/annotations/Table.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'reflect-metadata';
import {setModelName, addOptions} from "../services/models";
import {IDefineOptions} from "../interfaces/IDefineOptions";
import {setModelName, addOptions} from '../services/models';
import {IDefineOptions} from '../interfaces/IDefineOptions';
import {majorVersion} from '../utils/versioning';

export function Table(options: IDefineOptions): Function;
export function Table(target: any): void;
export function Table(arg: any): void|Function {
export function Table(arg: any): void | Function {

if (typeof arg === 'function') {

Expand All @@ -19,8 +20,10 @@ export function Table(arg: any): void|Function {
}

function annotate(target: any, options: IDefineOptions = {}): void {
options.instanceMethods = target.prototype;
options.classMethods = target;
if (majorVersion < 4) {
options.instanceMethods = target.prototype;
options.classMethods = target;
}

setModelName(target.prototype, options.modelName || target.name);
addOptions(target.prototype, options);
Expand Down
40 changes: 23 additions & 17 deletions test/specs/table_column.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {expect, use} from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import {DefineAttributes} from 'sequelize';
import {Model, Table, Column, DataType} from "../../index";
import {createSequelize} from "../utils/sequelize";
import {User} from "../models/User";
import {getOptions, getAttributes} from "../../lib/services/models";
import {Shoe, SHOE_TABLE_NAME} from "../models/Shoe";
import {Model, Table, Column, DataType} from '../../index';
import {createSequelize} from '../utils/sequelize';
import {User} from '../models/User';
import {getOptions, getAttributes} from '../../lib/services/models';
import {Shoe, SHOE_TABLE_NAME} from '../models/Shoe';
import * as _ from 'lodash';
import {majorVersion} from '../../lib/utils/versioning';

use(chaiAsPromised);

Expand Down Expand Up @@ -107,21 +108,26 @@ describe('table_column', () => {
expect(shoeDefineOptions).to.have.property('tableName', SHOE_TABLE_NAME);
});

it('should have class methods', () => {
const userDefineOptions = getOptions(User.prototype);
expect(userDefineOptions).to.have.property('classMethods', User);
if (majorVersion < 4) {

const shoeDefineOptions = getOptions(Shoe.prototype);
expect(shoeDefineOptions).to.have.property('classMethods', Shoe);
});
it('should have class methods', () => {
const userDefineOptions = getOptions(User.prototype);
expect(userDefineOptions).to.have.property('classMethods', User);

it('should have instance methods', () => {
const userDefineOptions = getOptions(User.prototype);
expect(userDefineOptions).to.have.property('instanceMethods', User.prototype);
const shoeDefineOptions = getOptions(Shoe.prototype);
expect(shoeDefineOptions).to.have.property('classMethods', Shoe);
});

it('should have instance methods', () => {
const userDefineOptions = getOptions(User.prototype);
expect(userDefineOptions).to.have.property('instanceMethods', User.prototype);

const shoeDefineOptions = getOptions(Shoe.prototype);
expect(shoeDefineOptions).to.have.property('instanceMethods', Shoe.prototype);
});

}

const shoeDefineOptions = getOptions(Shoe.prototype);
expect(shoeDefineOptions).to.have.property('instanceMethods', Shoe.prototype);
});
});

describe('attribute options', () => {
Expand Down

0 comments on commit 6c23dc2

Please sign in to comment.