Compare commits

..

No commits in common. "a41aa46c3a755b4c6bf1cbcf45890f2e8eeba085" and "36b3a92ca3ec9525d2be51d17c1a069e70edd35c" have entirely different histories.

6 changed files with 11 additions and 133 deletions

View File

@ -9,10 +9,6 @@ SET foreign_key_checks = 0;
INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled) INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled)
VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE);
INSERT INTO util.binlogQueue (code,logName, `position`)
VALUES ('mylogger', 'bin.000001', 4);
/* #5483 /* #5483
INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk) INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk)
VALUES(1, NULL, 1, 300, 1); VALUES(1, NULL, 1, 300, 1);

View File

@ -1827,9 +1827,9 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`) INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`)
VALUES VALUES
(1, util.VN_CURDATE(), 1, 1101, 19, 3, 0, util.VN_CURDATE(), 0, 11), (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, 11),
(2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16), (2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16),
(3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7), (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, 7),
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8); (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
@ -3761,8 +3761,3 @@ INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,value
INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk) INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
VALUES (1, 1); VALUES (1, 1);
INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES
(8, 1, 19);

View File

@ -1,45 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`binlogQueue_getDelay`(vCode VARCHAR(255))
RETURNS BIGINT
NOT DETERMINISTIC
BEGIN
/**
* Returns the difference between the current position of the binary log and
* the passed queue.
*
* @param vCode The queue code
* @return The difference in MB
*/
DECLARE vCurLogName VARCHAR(255);
DECLARE vCurPosition BIGINT;
DECLARE vQueueLogName VARCHAR(255);
DECLARE vQueuePosition BIGINT;
DECLARE vDelay BIGINT;
SELECT VARIABLE_VALUE INTO vCurLogName
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'BINLOG_SNAPSHOT_FILE';
SELECT VARIABLE_VALUE INTO vCurPosition
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME = 'BINLOG_SNAPSHOT_POSITION';
SELECT logName, `position`
INTO vQueueLogName, vQueuePosition
FROM binlogQueue
WHERE code = vCode;
IF vQueuePosition IS NULL THEN
RETURN NULL;
END IF;
SET vDelay =
vCurPosition - CAST(vQueuePosition AS SIGNED) +
@@max_binlog_size * (
CAST(REGEXP_SUBSTR(vCurLogName, '[0-9]+') AS SIGNED) -
CAST(REGEXP_SUBSTR(vQueueLogName, '[0-9]+') AS SIGNED)
);
RETURN ROUND(vDelay / POW(1024, 2));
END$$
DELIMITER ;

View File

@ -79,12 +79,7 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The claimResponsible id', description: 'The claimResponsible id',
http: {source: 'query'} http: {source: 'query'}
}, }
{
arg: 'myTeam',
type: 'boolean',
description: `Team partners`
},
], ],
returns: { returns: {
type: ['object'], type: ['object'],
@ -97,7 +92,6 @@ module.exports = Self => {
}); });
Self.filter = async(ctx, filter, options) => { Self.filter = async(ctx, filter, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models; const models = Self.app.models;
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const args = ctx.args; const args = ctx.args;
@ -127,23 +121,7 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk); claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
} }
// Apply filter by team const where = buildFilter(args, (param, value) => {
const teamMembersId = [];
if (args.myTeam != null) {
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
@ -174,11 +152,6 @@ module.exports = Self => {
to.setHours(23, 59, 59, 999); to.setHours(23, 59, 59, 999);
return {'cl.created': {between: [value, to]}}; return {'cl.created': {between: [value, to]}};
case 'myTeam':
if (value)
return {'cl.workerFk': {inq: teamMembersId}};
else
return {'cl.workerFk': {nin: teamMembersId}};
} }
}); });

View File

@ -1,25 +1,13 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('claim filter()', () => { describe('claim filter()', () => {
let ctx;
beforeEach(() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
}
};
});
it('should return 1 result filtering by id', async() => { it('should return 1 result filtering by id', async() => {
const tx = await app.models.Claim.beginTransaction({}); const tx = await app.models.Claim.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = {search: 1}; const result = await app.models.Claim.filter({args: {filter: {}, search: 1}}, null, options);
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -37,8 +25,7 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = {search: 'Tony Stark'}; const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options);
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(4); expect(result[0].id).toEqual(4);
@ -56,8 +43,7 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = {workerFk: 18}; const result = await app.models.Claim.filter({args: {filter: {}, workerFk: 18}}, null, options);
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(4); expect(result.length).toEqual(4);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -78,8 +64,7 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = {itemFk: 2}; const result = await app.models.Claim.filter({args: {filter: {}, itemFk: 2}}, null, options);
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -99,8 +84,7 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = {claimResponsibleFk: 7}; const result = await app.models.Claim.filter({args: {filter: {}, claimResponsibleFk: 7}}, null, options);
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(2); expect(result[0].id).toEqual(2);
@ -113,22 +97,4 @@ describe('claim filter()', () => {
throw e; throw e;
} }
}); });
it('should now return claims from the worker team', async() => {
const tx = await models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {itemFk: null, myTeam: true};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
}); });

View File

@ -70,13 +70,6 @@
label="Responsible"> label="Responsible">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal>
<vn-check
vn-one
label="My team"
ng-model="filter.myTeam"
triple-state="true">
</vn-horizontal>
<vn-horizontal class="vn-mt-lg"> <vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit> <vn-submit label="Search"></vn-submit>
</vn-horizontal> </vn-horizontal>