parent
f41c2489d9
commit
89a394a10d
|
@ -149,7 +149,7 @@ module.exports = Self => {
|
|||
const isSupplier = await Self.app.models.Supplier.findById(userId, options);
|
||||
if (isSupplier) {
|
||||
if (!filter.where) filter.where = {};
|
||||
filter.where.supplierFk = ctx.req.accessToken.userId;
|
||||
filter.where[`e.supplierFk`] = ctx.req.accessToken.userId;
|
||||
}
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Entry filter()', () => {
|
||||
fdescribe('Entry filter()', () => {
|
||||
it('should return the entry matching "search"', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
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 options = {transaction: tx};
|
||||
|
||||
|
@ -70,6 +115,7 @@ describe('Entry filter()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the entry matching the company', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
|
|
Loading…
Reference in New Issue