Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function userFind(
- t: Transaction,
- options: {where: {username?: string, email?: string}},
- callbackThen: (data: any) => Promise<any>,
- callbackCatch?: (err: Error) => never
- ): Promise<any> {
- return User.findOne({
- ...options,
- transaction: t
- })
- .then(callbackThen)
- .catch(callbackCatch || (err => {
- throw new Error(); //Provoque un ROLLBACK
- }));
- }
- //username = 'toto'
- //email = 'aaa@aol.com'
- this.sequelize.transaction((t: Transaction) => {
- return userFind(t, {
- where: {username: username}
- }, (data: any) => {
- if(data) {
- throw new Error('...'); //Provoque un ROLLBACK
- }
- return userFind(t, {
- where: {email: email}
- }, (data: any) => {
- if(data) {
- throw new Error('...'); //Provoque un ROLLBACK
- }
- //etc...
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement