basic-data.html info tag added, plus refactor on backend create.js and filter.js, plus spec commented until db docker implementation

This commit is contained in:
Carlos 2017-09-19 14:34:59 +02:00
parent 26a1d7fb29
commit e8d24a52ef
4 changed files with 62 additions and 54 deletions

View File

@ -20,7 +20,7 @@
<vn-textfield vn-one label="Fax" field="$ctrl.client.fax"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Email" field="$ctrl.client.email"></vn-textfield>
<vn-textfield vn-one label="Email" field="$ctrl.client.email" info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget rhoncus metus. Nullam quis ante venenatis, laoreet tellus ac, egestas tellus. Suspendisse placerat tristique libero a posuere."></vn-textfield>
<vn-autocomplete vn-one
initial-value="$ctrl.client.salesPerson"
field="$ctrl.client.salesPersonFk"

View File

@ -21,7 +21,6 @@ module.exports = function(Client){
Client.createUserProfile = (data, callback) => {
let user = {
name: data.userName,
email: data.email,
password: parseInt(Math.random() * 100000000000000)
};
@ -34,6 +33,7 @@ module.exports = function(Client){
let client = {
name: data.name,
email: data.email,
fi: data.fi,
socialName: data.socialName,
id: account.id

View File

@ -1,46 +1,49 @@
module.exports = function(Client){
Client.installMethod('filter', filterClients);
function filterClients(p) {
if(p.search)
return searchWhere(p);
return andWhere(p);
function filterClients(params) {
if(params.search)
return searchWhere(params);
return andWhere(params);
}
function searchWhere(p){
function searchWhere(params){
return {
where: {
or:[
{id: p.search,},
{name: {regexp: p.search}}
{id: params.search,},
{name: {regexp: params.search}}
]
},
skip: (p.page - 1) * p.size,
limit: p.size
skip: (params.page - 1) * params.size,
limit: params.size
}
}
function andWhere(p){
let where = {
where: {
id: p.id,
name: {regexp: p.name},
cif: p.cif,
socialName: {regexp: p.socialName},
city: {regexp: p.city},
postcode: p.postcode,
email: {regexp: p.email}
},
skip: (p.page - 1) * p.size,
limit: p.size
function andWhere(params){
let filters = {
where: {},
skip: (params.page - 1) * params.size,
limit: params.size
};
if(p.phone){
where.or = [
{phone: p.phone},
{mobile: p.phone}
]
delete params.page;
delete params.size;
if(params.phone){
filters.where.or = [
{phone: params.phone},
{mobile: params.phone}
];
delete params.phone;
}
return where;
Object.keys(params).forEach(
key => {
filters.where[key] = (key === 'postcode' || key === 'fi')? params[key] : {regexp: params[key]};
}
)
console.log(filters);
return filters;
}
}

View File

@ -1,27 +1,32 @@
var app = require('../../../../server/server');
var Client = app.models.Client;
describe('Client Create()', () => {
// import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
// let app = require('../../../../server/server');
beforeEach(() => {
//wipe db
//insert firxtures
});
// describe('Client Create()', () => {
let data = {
name: 'John',
userName: 'John',
email: 'John@wayne.com',
fi: 'The Man',
socialName: 'Wayne industries'
}
// let data = {
// name: 'Max Eisenhardt',
// userName: 'Magneto',
// email: 'magneto@marvel.com',
// fi: 'X-tax number',
// socialName: 'The X-Men'
// }
it('should createa new account', (done) => {
Client.createUserProfile(data, (error) => {
//connect to db and query for the new account OR use accounts model to check it like this
app.models.Account.findOne({where: {name: 'John'}})
.then((account) => {
done();
});
});
});
});
// it('should createa new account', (done) => {
// app.models.Client.createUserProfile(data, () => {
// app.models.Account.findOne({where: {name: data.userName}})
// .then(account => {
// expect(account.name).toEqual(data.userName)
// app.models.Client.findOne({where: {name: data.name}})
// .then(client => {
// expect(client.id).toEqual(account.id);
// expect(client.name).toEqual(data.name);
// expect(client.email).toEqual(data.email);
// expect(client.fi).toEqual(data.fi);
// expect(client.socialName).toEqual(data.socialName);
// done();
// });
// })
// .catch(catchErrors(done));
// });
// });
// });