#7648 - Customer View Entries #2659

Merged
jsegarra merged 17 commits from 7648_dev_customerEntries into dev 2024-07-03 07:29:02 +00:00
2 changed files with 65 additions and 19 deletions
Showing only changes of commit 89a394a10d - Show all commits

View File

@ -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;

View File

@ -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() => {