refactor for backend create.js transaction and it's html error notification for account implemented

This commit is contained in:
Carlos 2017-09-06 09:56:36 +02:00
parent 9607b2d897
commit a9763e728c
3 changed files with 15 additions and 6 deletions

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/Clients/createNew" options="vnPost"></mg-ajax>
<mg-ajax path="/client/api/Clients/createUserProfile" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.client"

View File

@ -1,8 +1,8 @@
var app = require('../../../server/server');
module.exports = function(Client){
Client.remoteMethod('createNew', {
description: 'Creates a new client',
Client.remoteMethod('createUserProfile', {
description: `Creates both client it's web account`,
accepts: {
arg: 'data',
type: 'object',
@ -14,11 +14,11 @@ module.exports = function(Client){
},
http: {
verb: 'post',
path: '/createNew'
path: '/createUserProfile'
}
});
Client.createNew = (data, callback) => {
Client.createUserProfile = (data, callback) => {
let user = {
name: data.userName,
email: data.email,
@ -28,6 +28,7 @@ module.exports = function(Client){
app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => {
app.models.Account.create (user, {transaction}, (err, account) => {
if (err) {
transaction.rollback();
return callback(err);
}
@ -38,7 +39,7 @@ module.exports = function(Client){
id: account.id
};
Client.create (client, (err, client) => {
Client.create (client, {transaction}, (err, client) => {
if (err) {
transaction.rollback();
return callback(err);

View File

@ -0,0 +1,8 @@
module.exports = function(Account) {
// Validations
Account.validatesUniquenessOf('name', {
message: 'Ya existe un usuario con ese nombre'
});
};