mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: Items data table.
This commit is contained in:
@@ -74,6 +74,24 @@ exports.seed = (knex) => {
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
|
||||
// Items
|
||||
{
|
||||
id: 10,
|
||||
resource_id: 2,
|
||||
label_name: 'Name',
|
||||
data_type: 'textbox',
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
resource_id: 2,
|
||||
label_name: 'Type',
|
||||
data_type: 'textbox',
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -336,7 +336,7 @@ export default {
|
||||
if (filter.filter_roles.length > 0) {
|
||||
filterConditions.buildQuery()(builder);
|
||||
}
|
||||
}).page(filter.page - 1, filter.page_size);
|
||||
}).pagination(filter.page - 1, filter.page_size);
|
||||
|
||||
return res.status(200).send({
|
||||
items,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Model } from 'objection';
|
||||
import {transform, snakeCase} from 'lodash';
|
||||
import {mapKeysDeep} from '@/utils';
|
||||
import PaginationQueryBuilder from '@/models/Pagination';
|
||||
|
||||
export default class ModelBase extends Model {
|
||||
static get collection() {
|
||||
@@ -24,4 +25,8 @@ export default class ModelBase extends Model {
|
||||
|
||||
return parsedJson;
|
||||
}
|
||||
|
||||
static get QueryBuilder() {
|
||||
return PaginationQueryBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
17
server/src/models/Pagination.js
Normal file
17
server/src/models/Pagination.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Model } from 'objection';
|
||||
|
||||
export default class PaginationQueryBuilder extends Model.QueryBuilder {
|
||||
pagination(page, pageSize) {
|
||||
return super.page(page, pageSize).runAfter(
|
||||
({ results, total }) => {
|
||||
return {
|
||||
results,
|
||||
pagination: {
|
||||
total,
|
||||
page: page + 1,
|
||||
pageSize,
|
||||
},
|
||||
};
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ describe('routes: /accounts/', () => {
|
||||
expect(res.body.accounts[1].account_type_id).equals(2);
|
||||
});
|
||||
|
||||
it.only('Should retrieve accounts based on view roles conditionals with relation join column.', async () => {
|
||||
it('Should retrieve accounts based on view roles conditionals with relation join column.', async () => {
|
||||
const resource = await create('resource', { name: 'accounts' });
|
||||
|
||||
const accountTypeField = await create('resource_field', {
|
||||
|
||||
@@ -575,15 +575,13 @@ describe('routes: `/items`', () => {
|
||||
const res = await request()
|
||||
.get('/api/items')
|
||||
.set('x-access-token', loginRes.body.token)
|
||||
.query({
|
||||
page: 2,
|
||||
})
|
||||
.send();
|
||||
|
||||
expect(res.body.items.results).to.be.a('array');
|
||||
expect(res.body.items.results.length).equals(0);
|
||||
expect(res.body.items.total).to.be.a('number');
|
||||
expect(res.body.items.total).equals(0)
|
||||
expect(res.body.items.pagination).to.be.a('object');
|
||||
expect(res.body.items.pagination.total).to.be.a('number');
|
||||
expect(res.body.items.pagination.total).equals(0)
|
||||
});
|
||||
|
||||
it('Should retrieve filtered items based on custom view conditions.', async () => {
|
||||
|
||||
Reference in New Issue
Block a user