CreateUserProfile: save first email on account table and all emails on client table
This commit is contained in:
parent
e76f1d74f9
commit
6c3ac042f1
|
@ -2,7 +2,7 @@ var app = require('../../../server/server');
|
|||
|
||||
module.exports = function(Client){
|
||||
Client.remoteMethod('createUserProfile', {
|
||||
description: `Creates both client it's web account`,
|
||||
description: 'Creates both client and its web account',
|
||||
accepts: {
|
||||
arg: 'data',
|
||||
type: 'object',
|
||||
|
@ -19,13 +19,15 @@ module.exports = function(Client){
|
|||
});
|
||||
|
||||
Client.createUserProfile = (data, callback) => {
|
||||
let firstEmail = data.email.split(',')[0];
|
||||
let user = {
|
||||
name: data.userName,
|
||||
email: firstEmail,
|
||||
password: parseInt(Math.random() * 100000000000000)
|
||||
};
|
||||
|
||||
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) {
|
||||
transaction.rollback();
|
||||
return callback(err);
|
||||
|
@ -33,13 +35,13 @@ module.exports = function(Client){
|
|||
|
||||
let client = {
|
||||
name: data.name,
|
||||
email: data.email,
|
||||
fi: data.fi,
|
||||
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) {
|
||||
transaction.rollback();
|
||||
return callback(err);
|
||||
|
|
Loading…
Reference in New Issue