diff --git a/packages/database/src/__tests__/operator/array-operator.test.ts b/packages/database/src/__tests__/operator/array-operator.test.ts index 3b247f442..81756974a 100644 --- a/packages/database/src/__tests__/operator/array-operator.test.ts +++ b/packages/database/src/__tests__/operator/array-operator.test.ts @@ -13,7 +13,9 @@ describe('array field operator', function () { }); beforeEach(async () => { - db = mockDatabase(); + db = mockDatabase({ + logging: console.log, + }); Test = db.collection({ name: 'test', @@ -43,45 +45,40 @@ describe('array field operator', function () { test('array field update', async () => { const Post = db.collection({ name: 'posts', - fields: [ - { type: 'array', name: 'tags' }, - ], + fields: [{ type: 'array', name: 'tags' }], }); + await db.sync({ force: true }); - await db.sync({force: true}) - - await Post.repository.create({}) + await Post.repository.create({}); const p1 = await Post.repository.create({ values: { - tags: ['t1', 't2'] - } - }) - + tags: ['t1', 't2'], + }, + }); let result = await Post.repository.findOne({ filter: { - 'tags.$match': ['t2', 't1'] - } - }) + 'tags.$match': ['t2', 't1'], + }, + }); - expect(result.get('id')).toEqual(p1.get('id')) + expect(result.get('id')).toEqual(p1.get('id')); await Post.repository.update({ - filterByPk: p1.get('id'), + filterByPk: p1.get('id'), values: { - tags: ['t3', 't2'] - } - }) + tags: ['t3', 't2'], + }, + }); result = await Post.repository.findOne({ filter: { - 'tags.$match': ['t3', 't2'] - } - }) + 'tags.$match': ['t3', 't2'], + }, + }); - - expect(result.get('id')).toEqual(p1.get('id')) + expect(result.get('id')).toEqual(p1.get('id')); }); test('nested array field', async () => { diff --git a/packages/database/src/fields/array-field.ts b/packages/database/src/fields/array-field.ts index 95f20c36d..481708f49 100644 --- a/packages/database/src/fields/array-field.ts +++ b/packages/database/src/fields/array-field.ts @@ -12,7 +12,6 @@ export class ArrayField extends Field { sortValue(model) { const oldValue = model.get(this.options.name); - console.log({oldValue}) if (oldValue) { const newValue = oldValue.sort(); model.set(this.options.name, newValue); @@ -21,9 +20,7 @@ export class ArrayField extends Field { bind() { super.bind(); - this.on('beforeSave', this.sortValue.bind(this)); - } unbind() { diff --git a/packages/database/src/repository.ts b/packages/database/src/repository.ts index e7fb3ae45..284039a92 100644 --- a/packages/database/src/repository.ts +++ b/packages/database/src/repository.ts @@ -108,7 +108,7 @@ export interface CreateOptions extends SequelizeCreateOptions { context?: any; } -export interface UpdateOptions extends SequelizeUpdateOptions { +export interface UpdateOptions extends Omit { values: Values; filter?: Filter; filterByPk?: PrimaryKey;