Skip to content

Commit 8ea4142

Browse files
Validator decorator + tests implemented
1 parent b2f969e commit 8ea4142

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/services/models.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ export function addOptions(target: any, options: DefineOptions<any>): void {
149149
if (!_options) {
150150
_options = {};
151151
}
152-
153-
setOptions(target, {..._options, ...options});
152+
setOptions(target, {..._options, ...options, validate: {
153+
...(_options.validate || {}),
154+
...(options.validate || {}),
155+
}});
154156
}
155157

156158
/**

test/specs/validation.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ describe('validation', () => {
465465

466466
_sequelize.addModels([User]);
467467

468+
it('should have metadata for multiple validators', () => {
469+
const {validate} = Reflect.getMetadata('sequelize:options', User.prototype);
470+
expect(validate).to.have.property('nameValidator');
471+
expect(validate).to.have.property('ageValidator');
472+
});
473+
468474
it('should throw due to wrong name', () => {
469475
const user = new User({name: 'will', age: VALID_AGE});
470476

0 commit comments

Comments
 (0)