mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix(sorting): add the missing the resources columns.
This commit is contained in:
@@ -5,12 +5,16 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import BaseController from './BaseController';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import ExchangeRatesService from 'services/ExchangeRates/ExchangeRatesService';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
|
||||
@Service()
|
||||
export default class ExchangeRatesController extends BaseController {
|
||||
@Inject()
|
||||
exchangeRatesService: ExchangeRatesService;
|
||||
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
@@ -22,7 +26,8 @@ export default class ExchangeRatesController extends BaseController {
|
||||
[...this.exchangeRatesListSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.exchangeRates.bind(this)),
|
||||
this.handleServiceError
|
||||
this.dynamicListService.handlerErrorsToResponse,
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.post(
|
||||
'/',
|
||||
@@ -59,6 +64,9 @@ export default class ExchangeRatesController extends BaseController {
|
||||
return [
|
||||
query('page').optional().isNumeric().toInt(),
|
||||
query('page_size').optional().isNumeric().toInt(),
|
||||
|
||||
query('column_sort_by').optional(),
|
||||
query('sort_order').optional().isIn(['desc', 'asc']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -96,8 +104,14 @@ export default class ExchangeRatesController extends BaseController {
|
||||
const filter = {
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
...req.query,
|
||||
filterRoles: [],
|
||||
columnSortBy: 'created_at',
|
||||
sortOrder: 'asc',
|
||||
...this.matchedQueryData(req),
|
||||
};
|
||||
if (filter.stringifiedFilterRoles) {
|
||||
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
||||
}
|
||||
try {
|
||||
const exchangeRates = await this.exchangeRatesService.listExchangeRates(
|
||||
tenantId,
|
||||
|
||||
@@ -12,7 +12,7 @@ exports.up = function(knex) {
|
||||
table.text('note');
|
||||
table.text('terms_conditions');
|
||||
table.text('send_to_email');
|
||||
|
||||
|
||||
table.date('delivered_at').index();
|
||||
table.date('approved_at').index();
|
||||
table.date('rejected_at').index();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { IFilterRole } from './DynamicFilter';
|
||||
|
||||
export interface IExchangeRate {
|
||||
id: number,
|
||||
@@ -21,6 +22,9 @@ export interface IExchangeRateEditDTO {
|
||||
export interface IExchangeRateFilter {
|
||||
page: number,
|
||||
pageSize: number,
|
||||
filterRoles?: IFilterRole[];
|
||||
columnSortBy: string;
|
||||
sortOrder: string;
|
||||
};
|
||||
|
||||
export interface IExchangeRatesService {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ISystemUser } from './User';
|
||||
import { IFilterRole } from './DynamicFilter';
|
||||
|
||||
export interface IPaginationMeta {
|
||||
total: number;
|
||||
@@ -9,6 +10,9 @@ export interface IPaginationMeta {
|
||||
export interface IExpensesFilter {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
filterRoles?: IFilterRole[];
|
||||
columnSortBy: string;
|
||||
sortOrder: string;
|
||||
}
|
||||
|
||||
export interface IExpense {
|
||||
|
||||
@@ -16,4 +16,29 @@ export default class ExchangeRate extends TenantModel {
|
||||
get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Model defined fields.
|
||||
*/
|
||||
static get fields(){
|
||||
return {
|
||||
currency_code: {
|
||||
label: 'Currency',
|
||||
column: 'currency_code'
|
||||
},
|
||||
exchange_rate: {
|
||||
label: 'Exchange rate',
|
||||
column: 'exchange_rate',
|
||||
},
|
||||
date: {
|
||||
label: 'Date',
|
||||
column: 'date',
|
||||
},
|
||||
created_at: {
|
||||
label: "Created at",
|
||||
column: "created_at",
|
||||
columnType: "date",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export default class Expense extends TenantModel {
|
||||
},
|
||||
published: {
|
||||
label: "Published",
|
||||
column: "published",
|
||||
column: "published_at",
|
||||
},
|
||||
created_at: {
|
||||
label: "Created at",
|
||||
|
||||
@@ -125,6 +125,12 @@ export default class SaleEstimate extends TenantModel {
|
||||
approved(query) {
|
||||
query.whereNot('approved_at', null)
|
||||
},
|
||||
/**
|
||||
* Sorting the estimates orders by delivery status.
|
||||
*/
|
||||
orderByDraft(query, order) {
|
||||
query.orderByRaw(`delivered_at is null ${order}`)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -238,6 +244,9 @@ export default class SaleEstimate extends TenantModel {
|
||||
query.modify('expired'); break;
|
||||
}
|
||||
},
|
||||
sortQuery: (query, role) => {
|
||||
query.modify('orderByDraft', role.order);
|
||||
}
|
||||
},
|
||||
created_at: {
|
||||
label: 'Created at',
|
||||
|
||||
@@ -60,6 +60,13 @@ export default class SaleReceipt extends TenantModel {
|
||||
draft(query) {
|
||||
query.where('closed_at', null);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sorting the receipts order by status.
|
||||
*/
|
||||
sortByStatus(query, order) {
|
||||
query.orderByRaw(`CLOSED_AT IS NULL ${order}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -196,6 +203,9 @@ export default class SaleReceipt extends TenantModel {
|
||||
break;
|
||||
}
|
||||
},
|
||||
sortQuery(query, role) {
|
||||
query.modify('sortByStatus', role.order);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import moment from 'moment';
|
||||
import { difference } from 'lodash';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import {
|
||||
EventDispatcher,
|
||||
EventDispatcherInterface,
|
||||
@@ -32,6 +33,9 @@ export default class ExchangeRatesService implements IExchangeRatesService {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
/**
|
||||
* Creates a new exchange rate.
|
||||
* @param {number} tenantId
|
||||
@@ -116,10 +120,17 @@ export default class ExchangeRatesService implements IExchangeRatesService {
|
||||
exchangeRateFilter: IExchangeRateFilter
|
||||
): Promise<void> {
|
||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
||||
const exchangeRates = await ExchangeRate.query().pagination(
|
||||
exchangeRateFilter.page - 1,
|
||||
exchangeRateFilter.pageSize
|
||||
const dynamicFilter = await this.dynamicListService.dynamicList(
|
||||
tenantId,
|
||||
ExchangeRate,
|
||||
exchangeRateFilter
|
||||
);
|
||||
// Retrieve exchange rates by the given query.
|
||||
const exchangeRates = await ExchangeRate.query()
|
||||
.onBuild((query) => {
|
||||
dynamicFilter.buildQuery()(query);
|
||||
})
|
||||
.pagination(exchangeRateFilter.page - 1, exchangeRateFilter.pageSize);
|
||||
|
||||
return exchangeRates;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user