parent
f41c2489d9
commit
89a394a10d
|
@ -149,7 +149,7 @@ module.exports = Self => {
|
||||||
const isSupplier = await Self.app.models.Supplier.findById(userId, options);
|
const isSupplier = await Self.app.models.Supplier.findById(userId, options);
|
||||||
if (isSupplier) {
|
if (isSupplier) {
|
||||||
if (!filter.where) filter.where = {};
|
if (!filter.where) filter.where = {};
|
||||||
filter.where.supplierFk = ctx.req.accessToken.userId;
|
filter.where[`e.supplierFk`] = ctx.req.accessToken.userId;
|
||||||
}
|
}
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Entry filter()', () => {
|
fdescribe('Entry filter()', () => {
|
||||||
it('should return the entry matching "search"', async() => {
|
it('should return the entry matching "search"', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
@ -48,7 +48,52 @@ describe('Entry filter()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entry matching the supplier', async() => {
|
describe('should return the entry matching the supplier', () => {
|
||||||
|
it('when userId is supplier ', async() => {
|
||||||
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
|
args: {},
|
||||||
|
req: {accessToken: {userId: 2}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when userId is supplier fetching other supplier', async() => {
|
||||||
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
supplierFk: 1
|
||||||
|
},
|
||||||
|
req: {accessToken: {userId: 2}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when userId is not supplier', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
@ -70,6 +115,7 @@ describe('Entry filter()', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the entry matching the company', async() => {
|
it('should return the entry matching the company', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
|
Loading…
Reference in New Issue