minor refactor to use better semantics

This commit is contained in:
Carlos Jimenez Ruiz 2021-06-02 10:31:26 +02:00
parent a6883585af
commit df4ebbd775
2 changed files with 10 additions and 10 deletions

View File

@ -14,10 +14,10 @@ module.exports = function(Self) {
description: 'The module name'
},
{
arg: 'action',
arg: 'direction',
type: 'string',
required: true,
description: 'Whether to increases or decreases the module position, last if undefined'
description: 'Whether to move left or right the module position'
}
],
http: {
@ -26,7 +26,7 @@ module.exports = function(Self) {
}
});
Self.setPosition = async(ctx, moduleName, action, options) => {
Self.setPosition = async(ctx, moduleName, direction, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
@ -55,12 +55,12 @@ module.exports = function(Self) {
let operator;
let order;
switch (action) {
case 'increase':
switch (direction) {
case 'left':
operator = {lt: movingModule.position};
order = 'position DESC';
break;
case 'decrease':
case 'right':
operator = {gt: movingModule.position};
order = 'position ASC';
break;

View File

@ -43,7 +43,7 @@ describe('setPosition()', () => {
expect(orders.position).toEqual(1);
expect(clients.position).toEqual(2);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'increase', options);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'left', options);
filter.where.moduleFk = 'Clients';
clients = await app.models.StarredModule.findOne(filter, options);
@ -84,7 +84,7 @@ describe('setPosition()', () => {
expect(orders.position).toEqual(1);
expect(clients.position).toEqual(2);
await app.models.StarredModule.setPosition(ctx, 'Orders', 'decrease', options);
await app.models.StarredModule.setPosition(ctx, 'Orders', 'right', options);
filter.where.moduleFk = 'Orders';
orders = await app.models.StarredModule.findOne(filter, options);
@ -145,7 +145,7 @@ describe('setPosition()', () => {
expect(orders.position).toEqual(4);
expect(zones.position).toEqual(5);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'decrease', options);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'right', options);
filter.where.moduleFk = 'Orders';
orders = await app.models.StarredModule.findOne(filter, options);
@ -203,7 +203,7 @@ describe('setPosition()', () => {
expect(zones.position).toEqual(5);
await app.models.StarredModule.toggleStarredModule(ctx, 'Claims', options);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'decrease', options);
await app.models.StarredModule.setPosition(ctx, 'Clients', 'right', options);
filter.where.moduleFk = 'Clients';
clients = await app.models.StarredModule.findOne(filter, options);