fix: refs #7917 fix methods, tests, acls #3085
|
@ -72,7 +72,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
filter = mergeFilters(filter, {where});
|
filter = mergeFilters(ctx.args.filter, {where});
|
||||||
|
|
||||||
const supplier = await Self.app.models.Supplier.isSupplier(ctx, myOptions);
|
const supplier = await Self.app.models.Supplier.isSupplier(ctx, myOptions);
|
||||||
carlossa marked this conversation as resolved
Outdated
|
|||||||
if (supplier) {
|
if (supplier) {
|
||||||
|
|
|
@ -1,25 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('AgencyTerm filter()', () => {
|
fdescribe('AgencyTerm filter()', () => {
|
||||||
|
const authUserId = 9;
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
today.setHours(2, 0, 0, 0);
|
today.setHours(2, 0, 0, 0);
|
||||||
|
let tx;
|
||||||
let ctx = beforeAll.getCtx();
|
let ctx = beforeAll.getCtx();
|
||||||
beforeAll(async() => {
|
console.log('ctx', ctx);
|
||||||
ctx = {
|
|
||||||
req: {
|
|
||||||
accessToken: {},
|
|
||||||
headers: {origin: 'http://localhost'},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return all results matching the filter', async() => {
|
it('should return all results matching the filter', async() => {
|
||||||
const tx = await models.AgencyTerm.beginTransaction({});
|
tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const filter = {};
|
const filter = {};
|
||||||
|
ctx = {req: {accessToken: {userId: authUserId}}};
|
||||||
|
|
||||||
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
||||||
const firstAgencyTerm = agencyTerms[0];
|
const firstAgencyTerm = agencyTerms[0];
|
||||||
|
@ -35,39 +30,23 @@ describe('AgencyTerm filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "search" searching by integer', async() => {
|
it('should return results matching "search" searching by integer', async() => {
|
||||||
// ctx = {
|
const ctx = {req: {args: {search: 1}}};
|
||||||
carlossa marked this conversation as resolved
Outdated
jgallego
commented
posau comú en la par superior, en el beforeall hi ha exemples posau comú en la par superior, en el beforeall hi ha exemples
|
|||||||
// args: {
|
|
||||||
// search: 1,
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
const filter = {
|
|
||||||
order: 'isActive ASC, name',
|
|
||||||
search: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx, filter);
|
let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
expect(result[0].routeFk).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "search" searching by string', async() => {
|
it('should return results matching "search" searching by string', async() => {
|
||||||
// ctx = {
|
const ctx = {req: {args: {search: 'Plants SL'}}};
|
||||||
// args: {
|
let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
// search: 'Plants SL',
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
const filter = {
|
|
||||||
search: 'Plants SL'
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx, filter);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "from" and "to"', async() => {
|
it('should return results matching "from" and "to"', async() => {
|
||||||
const tx = await models.Buy.beginTransaction({});
|
tx = await models.Buy.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -77,6 +56,8 @@ describe('AgencyTerm filter()', () => {
|
||||||
const to = Date.vnNew();
|
const to = Date.vnNew();
|
||||||
to.setHours(23, 59, 59, 999);
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
|
const ctx = {req: {args: {from: from, to: to}}};
|
||||||
|
|
||||||
const results = await models.AgencyTerm.filter(ctx, options);
|
const results = await models.AgencyTerm.filter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(5);
|
expect(results.length).toBe(5);
|
||||||
|
@ -89,31 +70,17 @@ describe('AgencyTerm filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "agencyModeFk"', async() => {
|
it('should return results matching "agencyModeFk"', async() => {
|
||||||
// ctx = {
|
const ctx = {req: {args: {agencyModeFk: 1}}};
|
||||||
// args: {
|
|
||||||
// agencyModeFk: 1,
|
let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
// }
|
|
||||||
// };
|
|
||||||
const filter = {
|
|
||||||
agencyModeFk: 1,
|
|
||||||
};
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx, filter);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(1);
|
expect(result[0].routeFk).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "agencyFk"', async() => {
|
it('should return results matching "agencyFk"', async() => {
|
||||||
// ctx = {
|
const ctx = {req: {args: {agencyFk: 1}}};
|
||||||
// args: {
|
let result = await app.models.AgencyTerm.filter(ctx);
|
||||||
// agencyFk: 2,
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const filter = {
|
|
||||||
agencyFk: 2
|
|
||||||
};
|
|
||||||
let result = await app.models.AgencyTerm.filter(ctx, filter);
|
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
expect(result[0].routeFk).toEqual(2);
|
expect(result[0].routeFk).toEqual(2);
|
||||||
|
|
|
@ -164,7 +164,8 @@ module.exports = Self => {
|
||||||
throw new UserError('The social name has an invalid format');
|
throw new UserError('The social name has an invalid format');
|
||||||
});
|
});
|
||||||
|
|
||||||
carlossa marked this conversation as resolved
Outdated
jgallego
commented
aci es mes sencill que pases el userId directament aci es mes sencill que pases el userId directament
|
|||||||
Self.isSupplier = async(userId, options = {}) => {
|
Self.isSupplier = async(ctx, options = {}) => {
|
||||||
carlossa marked this conversation as resolved
Outdated
jgallego
commented
ací es on dia que no cal pasar ctx, sino userId ací es on dia que no cal pasar ctx, sino userId
|
|||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const client = await Self.app.models.Client.findById(userId, options);
|
const client = await Self.app.models.Client.findById(userId, options);
|
||||||
const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, options);
|
const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, options);
|
||||||
return supplier;
|
return supplier;
|
||||||
|
|
Loading…
Reference in New Issue
crear acl getRouteByAgency, comprobar los acl de mas a menos permisivo.
esta part de la tarea no la veig implementada