CreateUserProfile: save first email on account table and all emails on client table

This commit is contained in:
Vicente Falco 2017-09-20 12:15:38 +02:00
parent e76f1d74f9
commit 6c3ac042f1
1 changed files with 7 additions and 5 deletions

View File

@ -2,7 +2,7 @@ var app = require('../../../server/server');
module.exports = function(Client){ module.exports = function(Client){
Client.remoteMethod('createUserProfile', { Client.remoteMethod('createUserProfile', {
description: `Creates both client it's web account`, description: 'Creates both client and its web account',
accepts: { accepts: {
arg: 'data', arg: 'data',
type: 'object', type: 'object',
@ -19,13 +19,15 @@ module.exports = function(Client){
}); });
Client.createUserProfile = (data, callback) => { Client.createUserProfile = (data, callback) => {
let firstEmail = data.email.split(',')[0];
let user = { let user = {
name: data.userName, name: data.userName,
email: firstEmail,
password: parseInt(Math.random() * 100000000000000) password: parseInt(Math.random() * 100000000000000)
}; };
app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => { app.models.Account.beginTransaction('READ COMMITTED', (err, transaction) => {
app.models.Account.create (user, {transaction}, (err, account) => { app.models.Account.create(user, {transaction}, (err, account) => {
if (err) { if (err) {
transaction.rollback(); transaction.rollback();
return callback(err); return callback(err);
@ -33,13 +35,13 @@ module.exports = function(Client){
let client = { let client = {
name: data.name, name: data.name,
email: data.email,
fi: data.fi, fi: data.fi,
socialName: data.socialName, socialName: data.socialName,
id: account.id id: account.id,
email: data.email
}; };
Client.create (client, {transaction}, (err, client) => { Client.create(client, {transaction}, (err, client) => {
if (err) { if (err) {
transaction.rollback(); transaction.rollback();
return callback(err); return callback(err);