update options

This commit is contained in:
Chareice 2021-12-07 15:43:14 +08:00
parent f6f8f041f1
commit 30e31a2e79
3 changed files with 22 additions and 28 deletions

View File

@ -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: <number>p1.get('id'),
filterByPk: <any>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 () => {

View File

@ -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() {

View File

@ -108,7 +108,7 @@ export interface CreateOptions extends SequelizeCreateOptions {
context?: any;
}
export interface UpdateOptions extends SequelizeUpdateOptions {
export interface UpdateOptions extends Omit<SequelizeUpdateOptions, 'where'> {
values: Values;
filter?: Filter;
filterByPk?: PrimaryKey;