transaction for account and client creation at create.js
This commit is contained in:
parent
e24a36aa08
commit
9607b2d897
|
@ -18,29 +18,36 @@ module.exports = function(Client){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Client.createNew = (data, cb) => {
|
Client.createNew = (data, callback) => {
|
||||||
let user = {
|
let user = {
|
||||||
name: data.userName,
|
name: data.userName,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
password: parseInt(Math.random() * 100000000000000)
|
password: parseInt(Math.random() * 100000000000000)
|
||||||
};
|
};
|
||||||
app.models.Account.create (user, (err, obj) => {
|
|
||||||
if (err) {
|
app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => {
|
||||||
cb(err);
|
app.models.Account.create (user, {transaction}, (err, account) => {
|
||||||
} else {
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
let client = {
|
let client = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
fi: data.fi,
|
fi: data.fi,
|
||||||
socialName: data.socialName,
|
socialName: data.socialName,
|
||||||
id: obj.id
|
id: account.id
|
||||||
};
|
};
|
||||||
Client.create (client, (err, obj) => {
|
|
||||||
if (err)
|
Client.create (client, (err, client) => {
|
||||||
cb(err);
|
if (err) {
|
||||||
else
|
transaction.rollback();
|
||||||
cb(null, true);
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.commit();
|
||||||
|
callback(null, true);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
Reference in New Issue