refs #6641 test fixtures
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
jcasado 2024-04-04 14:53:26 +02:00
parent 1c6d913926
commit 84e6e7f7bf
3 changed files with 24 additions and 10 deletions

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, 18, 3, 0, util.VN_CURDATE(), 0, 11), (1, util.VN_CURDATE(), 1, 1101, 19, 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, 18, 1, 1, util.VN_CURDATE(), 5, 7), (3, util.VN_CURDATE(), 3, 1101, 19, 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`)
@ -3745,4 +3745,8 @@ INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,new
INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`) INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`)
VALUES VALUES
(1, 10, 9); (1, 10, 9);
INSERT INTO vn.workerTeam
(id, team, workerFk)
VALUES(8, 1, 19);

View File

@ -4,10 +4,15 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters; const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('filter', { Self.remoteMethod('filter', {
description: 'Find all instances of the model matched by filter from the data source.', description: 'Find all instances of the model matched by filter from the data source.',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
{
arg: 'ctx',
type: 'object',
http: {source: 'context'}
},
{ {
arg: 'filter', arg: 'filter',
type: 'object', type: 'object',
@ -97,7 +102,11 @@ module.exports = Self => {
}); });
Self.filter = async(ctx, filter, options) => { Self.filter = async(ctx, filter, options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx?.req?.accessToken?.userId;
console.log('ctx', ctx);
console.log('ctx.req', ctx.req);
console.log('ctx.req.accessToken', ctx.req.accessToken);
console.log('ctx.req.accessToken.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;
@ -143,7 +152,7 @@ module.exports = Self => {
teamMembersId.push(userId); teamMembersId.push(userId);
} }
const where = buildFilter(args, (param, value) => { const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)

View File

@ -1,6 +1,7 @@
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()', () => { fdescribe('claim filter()', () => {
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({});
@ -104,11 +105,11 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}}; const ctx = {req: {accessToken: {userId: 9}}, args: {myTeam: true}};
const filter = {}; const filter = {};
const result = await models.SalesMonitor.salesFilter(ctx, filter, options); const result = await models.Claim.filter(ctx, filter, options);
expect(result.length).toBeGreaterThan(20); expect(result.length).toEqual(2);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {