How to use the UniqueConstraintError function from sequelize
Find comprehensive JavaScript sequelize.UniqueConstraintError code examples handpicked from public code repositorys.
GitHub: ikovac/boutique
149 150 151 152 153 154 155 156 157 158
const found = await User.findAll({ where, paranoid: false }); return Promise.map(users, userData => Promise.try(() => { const user = find(found, { email: userData.email }); if (user && !user.deletedAt) { const message = this.rawAttributes.email.unique.msg; throw new UniqueConstraintError({ message }); } if (user) { user.setDataValue('deletedAt', null); return user;
4
0
0
GitHub: dnfrolov/auction
34 35 36 37 38 39 40 41 42 43
register(null, { database: { db: sequelize, errors: { ValidationError: Sequelize.ValidationError, UniqueConstraintError: Sequelize.UniqueConstraintError }, models: { Bid: Bid, Item: Item,
0
12
3
149 150 151 152 153 154 155 156 157 158
} } else { return exports.addUser(user); } }; exports.addUser = async user => { // catch for Sequelize.UniqueConstraintError let newUser = null; try { newUser = await User.create(user); const newToken = jwtUtils.signToken({userId: newUser.userId, email: newUser.email});
1
0
2
30 31 32 33 34 35 36 37 38 39
}); it('should throw an error if username is already taken', async () => { jest .spyOn(db, 'create') .mockRejectedValueOnce(new UniqueConstraintError()); await expect(AuthService.createUser('test', 'password')).rejects.toEqual( expect.objectContaining({ message: 'Username already exists' }) ); });
0
0
1
14 15 16 17 18 19 20 21 22 23
// eslint-disable-next-line no-empty-function exports.notifyErrorDatabase = (e, additionalMessages = () => {}) => { console.log("ERROR DB:", e); if ( e instanceof Sequelize.ForeignKeyConstraintError || e instanceof Sequelize.UniqueConstraintError ) { const message = additionalMessages(e); //return Promise.reject(errors.badRequest(message || defaultErrorMessage(e))); return Promise.reject(
0
0
0
sequelize.col is the most popular function in sequelize (1002 examples)