mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
fix hot bugs.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import express from 'express';
|
||||
import JWTAuth from '@/http/middleware/jwtAuth';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
|
||||
export default {
|
||||
@@ -8,7 +7,6 @@ export default {
|
||||
*/
|
||||
router() {
|
||||
const router = express.Router();
|
||||
router.use(JWTAuth);
|
||||
|
||||
router.get('/',
|
||||
this.getAccountTypesList.validation,
|
||||
|
||||
@@ -3,10 +3,8 @@ import express from 'express';
|
||||
import { difference } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import JWTAuth from '@/http/middleware/jwtAuth';
|
||||
import JournalPoster from '@/services/Accounting/JournalPoster';
|
||||
import JournalEntry from '@/services/Accounting/JournalEntry';
|
||||
import TenancyMiddleware from '@/http/middleware/TenancyMiddleware';
|
||||
import {
|
||||
mapViewRolesToConditionals,
|
||||
mapFilterRolesToDynamicFilter,
|
||||
@@ -25,8 +23,6 @@ export default {
|
||||
*/
|
||||
router() {
|
||||
const router = express.Router();
|
||||
router.use(JWTAuth);
|
||||
router.use(TenancyMiddleware);
|
||||
|
||||
router.get('/manual-journals/:id',
|
||||
this.getManualJournal.validation,
|
||||
@@ -94,6 +90,8 @@ export default {
|
||||
}
|
||||
const { Resource, View, ManualJournal } = req.models;
|
||||
|
||||
console.log(req.models);
|
||||
|
||||
const errorReasons = [];
|
||||
const manualJournalsResource = await Resource.query()
|
||||
.where('name', 'manual_journals')
|
||||
|
||||
@@ -9,8 +9,6 @@ import { difference } from 'lodash';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import JournalPoster from '@/services/Accounting/JournalPoster';
|
||||
import NestedSet from '@/collection/NestedSet';
|
||||
import JWTAuth from '@/http/middleware/jwtAuth';
|
||||
import TenancyMiddleware from '@/http/middleware/TenancyMiddleware';
|
||||
import {
|
||||
mapViewRolesToConditionals,
|
||||
mapFilterRolesToDynamicFilter,
|
||||
@@ -30,9 +28,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(JWTAuth);
|
||||
router.use(TenancyMiddleware);
|
||||
|
||||
router.post('/',
|
||||
this.newAccount.validation,
|
||||
asyncMiddleware(this.newAccount.handler));
|
||||
@@ -243,7 +238,7 @@ export default {
|
||||
|
||||
query('stringified_filter_roles').optional().isJSON(),
|
||||
|
||||
query('column_sort_order').optional(),
|
||||
query('column_sort_by').optional(),
|
||||
query('sort_order').optional().isIn(['desc', 'asc']),
|
||||
],
|
||||
async handler(req, res) {
|
||||
@@ -293,12 +288,13 @@ export default {
|
||||
});
|
||||
const dynamicFilter = new DynamicFilter(Account.tableName);
|
||||
|
||||
if (filter.column_sort_order) {
|
||||
if (resourceFieldsKeys.indexOf(filter.column_sort_order) === -1) {
|
||||
if (filter.column_sort_by) {
|
||||
console.log(filter);
|
||||
if (resourceFieldsKeys.indexOf(filter.column_sort_by) === -1) {
|
||||
errorReasons.push({ type: 'COLUMN.SORT.ORDER.NOT.FOUND', code: 300 });
|
||||
}
|
||||
const sortByFilter = new DynamicFilterSortBy(
|
||||
filter.column_sort_order,
|
||||
filter.column_sort_by,
|
||||
filter.sort_order,
|
||||
);
|
||||
dynamicFilter.setFilter(sortByFilter);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import express from 'express';
|
||||
import { check, param, validationResult } from 'express-validator';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
|
||||
export default {
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
const router = express.Router();
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.get('/',
|
||||
this.all.validation,
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
} from 'express-validator';
|
||||
import moment from 'moment';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
|
||||
export default {
|
||||
/**
|
||||
@@ -15,7 +14,6 @@ export default {
|
||||
*/
|
||||
router() {
|
||||
const router = express.Router();
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.get('/',
|
||||
this.exchangeRates.validation,
|
||||
|
||||
@@ -3,7 +3,6 @@ import { query, oneOf, validationResult } from 'express-validator';
|
||||
import moment from 'moment';
|
||||
import { pick, difference, groupBy } from 'lodash';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
import JournalPoster from '@/services/Accounting/JournalPoster';
|
||||
import { dateRangeCollection } from '@/utils';
|
||||
|
||||
@@ -25,7 +24,6 @@ export default {
|
||||
*/
|
||||
router() {
|
||||
const router = express.Router();
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.get('/journal',
|
||||
this.journal.validation,
|
||||
|
||||
@@ -6,10 +6,6 @@ import {
|
||||
query,
|
||||
} from 'express-validator';
|
||||
import asyncMiddleware from '../middleware/asyncMiddleware';
|
||||
import ItemCategory from '@/models/ItemCategory';
|
||||
import Authorization from '@/http/middleware/authorization';
|
||||
import JWTAuth from '@/http/middleware/jwtAuth';
|
||||
import Resource from '@/models/Resource';
|
||||
import {
|
||||
DynamicFilter,
|
||||
DynamicFilterSortBy,
|
||||
@@ -27,8 +23,6 @@ export default {
|
||||
const router = express.Router();
|
||||
// const permit = Authorization('items_categories');
|
||||
|
||||
router.use(JWTAuth);
|
||||
|
||||
router.post('/:id',
|
||||
this.editCategory.validation,
|
||||
asyncMiddleware(this.editCategory.handler));
|
||||
@@ -62,7 +56,10 @@ export default {
|
||||
.optional({ nullable: true, checkFalsy: true })
|
||||
.isNumeric()
|
||||
.toInt(),
|
||||
check('description').optional().trim().escape()
|
||||
check('description')
|
||||
.optional()
|
||||
.trim()
|
||||
.escape(),
|
||||
],
|
||||
async handler(req, res) {
|
||||
const validationErrors = validationResult(req);
|
||||
@@ -74,6 +71,7 @@ export default {
|
||||
}
|
||||
const { user } = req;
|
||||
const form = { ...req.body };
|
||||
const { ItemCategory } = req.models;
|
||||
|
||||
if (form.parent_category_id) {
|
||||
const foundParentCategory = await ItemCategory.query()
|
||||
@@ -82,7 +80,7 @@ export default {
|
||||
|
||||
if (!foundParentCategory) {
|
||||
return res.boom.notFound('The parent category ID is not found.', {
|
||||
errors: [{ type: 'PARENT_CATEGORY_NOT_FOUND', code: 100 }]
|
||||
errors: [{ type: 'PARENT_CATEGORY_NOT_FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -91,7 +89,7 @@ export default {
|
||||
user_id: user.id,
|
||||
});
|
||||
return res.status(200).send({ category });
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -119,18 +117,19 @@ export default {
|
||||
}
|
||||
|
||||
const form = { ...req.body };
|
||||
const { ItemCategory } = req.models;
|
||||
const itemCategory = await ItemCategory.query()
|
||||
.where('id', id)
|
||||
.first();
|
||||
|
||||
if (!itemCategory) {
|
||||
return res.boom.notFound({
|
||||
errors: [{ type: 'ITEM_CATEGORY.NOT.FOUND', code: 100 }]
|
||||
errors: [{ type: 'ITEM_CATEGORY.NOT.FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
if (
|
||||
form.parent_category_id &&
|
||||
form.parent_category_id !== itemCategory.parent_category_id
|
||||
form.parent_category_id
|
||||
&& form.parent_category_id !== itemCategory.parent_category_id
|
||||
) {
|
||||
const foundParentCategory = await ItemCategory.query()
|
||||
.where('id', form.parent_category_id)
|
||||
@@ -138,7 +137,7 @@ export default {
|
||||
|
||||
if (!foundParentCategory) {
|
||||
return res.boom.notFound('The parent category ID is not found.', {
|
||||
errors: [{ type: 'PARENT_CATEGORY_NOT_FOUND', code: 100 }]
|
||||
errors: [{ type: 'PARENT_CATEGORY_NOT_FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -155,10 +154,11 @@ export default {
|
||||
*/
|
||||
deleteItem: {
|
||||
validation: [
|
||||
param('id').exists().toInt()
|
||||
param('id').exists().toInt(),
|
||||
],
|
||||
async handler(req, res) {
|
||||
const { id } = req.params;
|
||||
const { ItemCategory } = req.models;
|
||||
const itemCategory = await ItemCategory.query()
|
||||
.where('id', id)
|
||||
.first();
|
||||
@@ -166,13 +166,12 @@ export default {
|
||||
if (!itemCategory) {
|
||||
return res.boom.notFound();
|
||||
}
|
||||
|
||||
await ItemCategory.query()
|
||||
.where('id', itemCategory.id)
|
||||
.delete();
|
||||
|
||||
return res.status(200).send();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -193,15 +192,16 @@ export default {
|
||||
});
|
||||
}
|
||||
|
||||
const { Resource, ItemCategory } = req.models;
|
||||
const categoriesResource = await Resource.query()
|
||||
.where('name', 'items_categories')
|
||||
.withGraphFetched('fields')
|
||||
.first();
|
||||
|
||||
if (!categoriesResource) {
|
||||
return res.status(400).send({ errors: [
|
||||
{ type: 'ITEMS.CATEGORIES.RESOURCE.NOT.FOUND', code: 200, }
|
||||
]});
|
||||
return res.status(400).send({
|
||||
errors: [{ type: 'ITEMS.CATEGORIES.RESOURCE.NOT.FOUND', code: 200 }],
|
||||
});
|
||||
}
|
||||
|
||||
const filter = {
|
||||
@@ -256,7 +256,7 @@ export default {
|
||||
});
|
||||
|
||||
return res.status(200).send({ categories });
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -266,15 +266,16 @@ export default {
|
||||
validation: [param('category_id').toInt()],
|
||||
async handler(req, res) {
|
||||
const { category_id: categoryId } = req.params;
|
||||
const { ItemCategory } = req.models;
|
||||
const item = await ItemCategory.where('id', categoryId).fetch();
|
||||
|
||||
if (!item) {
|
||||
return res.boom.notFound(null, {
|
||||
errors: [{ type: 'CATEGORY_NOT_FOUND', code: 100 }]
|
||||
errors: [{ type: 'CATEGORY_NOT_FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).send({ category: item.toJSON() });
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3,8 +3,6 @@ import { check, query, validationResult } from 'express-validator';
|
||||
import { difference } from 'lodash';
|
||||
import fs from 'fs';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
import TenancyMiddleware from '@/http/middleware/TenancyMiddleware';
|
||||
import {
|
||||
mapViewRolesToConditionals,
|
||||
mapFilterRolesToDynamicFilter,
|
||||
@@ -16,7 +14,6 @@ import {
|
||||
DynamicFilterFilterRoles,
|
||||
} from '@/lib/DynamicFilter';
|
||||
import Logger from '@/services/Logger';
|
||||
import ConfiguredMiddleware from '@/http/middleware/ConfiguredMiddleware';
|
||||
|
||||
const fsPromises = fs.promises;
|
||||
|
||||
@@ -27,10 +24,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
router.use(TenancyMiddleware);
|
||||
router.use(ConfiguredMiddleware);
|
||||
|
||||
router.post('/:id',
|
||||
this.editItem.validation,
|
||||
asyncMiddleware(this.editItem.handler));
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
|
||||
import express from 'express';
|
||||
import { check, param, query, validationResult } from 'express-validator';
|
||||
import {
|
||||
param,
|
||||
query,
|
||||
validationResult,
|
||||
} from 'express-validator';
|
||||
import fs from 'fs';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import TenancyMiddleware from '@/http/middleware/TenancyMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
import Logger from '@/services/Logger';
|
||||
|
||||
const fsPromises = fs.promises;
|
||||
@@ -16,9 +18,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
router.use(TenancyMiddleware);
|
||||
|
||||
router.post('/upload',
|
||||
this.upload.validation,
|
||||
asyncMiddleware(this.upload.handler));
|
||||
|
||||
@@ -2,7 +2,6 @@ import express from 'express';
|
||||
import { body, query, validationResult } from 'express-validator';
|
||||
import { pick } from 'lodash';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
|
||||
export default {
|
||||
/**
|
||||
@@ -11,8 +10,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.post('/',
|
||||
this.saveOptions.validation,
|
||||
asyncMiddleware(this.saveOptions.handler));
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
query,
|
||||
} from 'express-validator';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
|
||||
export default {
|
||||
/**
|
||||
@@ -13,8 +12,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.get('/:resource_slug/columns',
|
||||
this.resourceColumns.validation,
|
||||
asyncMiddleware(this.resourceColumns.handler));
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
validationResult,
|
||||
} from 'express-validator';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
import {
|
||||
validateViewRoles,
|
||||
} from '@/lib/ViewRolesBuilder';
|
||||
@@ -22,8 +21,6 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.get('/',
|
||||
this.listViews.validation,
|
||||
asyncMiddleware(this.listViews.handler));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// import OAuth2 from '@/http/controllers/OAuth2';
|
||||
import express from 'express';
|
||||
import Authentication from '@/http/controllers/Authentication';
|
||||
import InviteUsers from '@/http/controllers/InviteUsers';
|
||||
// import Users from '@/http/controllers/Users';
|
||||
@@ -26,33 +27,43 @@ import ExchangeRates from '@/http/controllers/ExchangeRates';
|
||||
// import SalesReports from '@/http/controllers/SalesReports';
|
||||
// import PurchasesReports from '@/http/controllers/PurchasesReports';
|
||||
import Media from '@/http/controllers/Media';
|
||||
import JWTAuth from '@/http/middleware/jwtAuth';
|
||||
import TenancyMiddleware from '@/http/middleware/TenancyMiddleware';
|
||||
|
||||
export default (app) => {
|
||||
// app.use('/api/oauth2', OAuth2.router());
|
||||
app.use('/api/auth', Authentication.router());
|
||||
app.use('/api/invite', InviteUsers.router());
|
||||
app.use('/api/currencies', Currencies.router());
|
||||
|
||||
const dashboard = express.Router();
|
||||
|
||||
dashboard.use(JWTAuth);
|
||||
dashboard.use(TenancyMiddleware);
|
||||
|
||||
dashboard.use('/api/invite', InviteUsers.router());
|
||||
dashboard.use('/api/currencies', Currencies.router());
|
||||
// app.use('/api/users', Users.router());
|
||||
// app.use('/api/roles', Roles.router());
|
||||
app.use('/api/accounts', Accounts.router());
|
||||
app.use('/api/account_types', AccountTypes.router());
|
||||
app.use('/api/accounting', Accounting.router());
|
||||
dashboard.use('/api/accounts', Accounts.router());
|
||||
dashboard.use('/api/account_types', AccountTypes.router());
|
||||
dashboard.use('/api/accounting', Accounting.router());
|
||||
// app.use('/api/accounts_opening_balances', AccountOpeningBalance.router());
|
||||
app.use('/api/views', Views.router());
|
||||
dashboard.use('/api/views', Views.router());
|
||||
// app.use('/api/fields', CustomFields.router());
|
||||
app.use('/api/items', Items.router());
|
||||
app.use('/api/item_categories', ItemCategories.router());
|
||||
dashboard.use('/api/items', Items.router());
|
||||
dashboard.use('/api/item_categories', ItemCategories.router());
|
||||
// app.use('/api/expenses', Expenses.router());
|
||||
app.use('/api/financial_statements', FinancialStatements.router());
|
||||
app.use('/api/options', Options.router());
|
||||
dashboard.use('/api/financial_statements', FinancialStatements.router());
|
||||
dashboard.use('/api/options', Options.router());
|
||||
// app.use('/api/budget_reports', BudgetReports.router());
|
||||
// app.use('/api/customers', Customers.router());
|
||||
// app.use('/api/suppliers', Suppliers.router());
|
||||
// app.use('/api/bills', Bills.router());
|
||||
// app.use('/api/budget', Budget.router());
|
||||
app.use('/api/resources', Resources.router());
|
||||
app.use('/api/exchange_rates', ExchangeRates.router());
|
||||
app.use('/api/media', Media.router());
|
||||
dashboard.use('/api/resources', Resources.router());
|
||||
dashboard.use('/api/exchange_rates', ExchangeRates.router());
|
||||
dashboard.use('/api/media', Media.router());
|
||||
|
||||
app.use('/', dashboard);
|
||||
// app.use('/api/currency_adjustment', CurrencyAdjustment.router());
|
||||
// app.use('/api/reports/sales', SalesReports.router());
|
||||
// app.use('/api/reports/purchases', PurchasesReports.router());
|
||||
|
||||
Reference in New Issue
Block a user