#7648 - Customer View Entries #2659
|
@ -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,27 +48,73 @@ describe('Entry filter()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should return the entry matching the supplier', async() => {
|
||||
const tx = await models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
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: {
|
||||
supplierFk: 2
|
||||
},
|
||||
req: {accessToken: {userId: 9}}
|
||||
};
|
||||
try {
|
||||
const ctx = {
|
||||
args: {},
|
||||
req: {accessToken: {userId: 2}}
|
||||
};
|
||||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(6);
|
||||
expect(result.length).toEqual(6);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
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};
|
||||
|
||||
try {
|
||||
const ctx = {
|
||||
args: {
|
||||
supplierFk: 2
|
||||
},
|
||||
req: {accessToken: {userId: 9}}
|
||||
};
|
||||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(6);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the entry matching the company', async() => {
|
||||
|
|
Loading…
Reference in New Issue