mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
WIP Version 0.0.1
This commit is contained in:
@@ -40,6 +40,7 @@ export default {
|
||||
},
|
||||
},
|
||||
|
||||
// Items
|
||||
'items': {
|
||||
'type': {
|
||||
column: 'type',
|
||||
@@ -47,5 +48,27 @@ export default {
|
||||
'name': {
|
||||
column: 'name',
|
||||
},
|
||||
},
|
||||
|
||||
// Manual Journals
|
||||
'manual_journals': {
|
||||
'type': {
|
||||
column: 'transaction_type',
|
||||
},
|
||||
'status': {
|
||||
column: 'status',
|
||||
},
|
||||
'date': {
|
||||
column: 'date',
|
||||
},
|
||||
'journal_number': {
|
||||
column: 'journal_number',
|
||||
},
|
||||
'amount': {
|
||||
column: 'amount',
|
||||
},
|
||||
'created_at': {
|
||||
column: 'created_at',
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,6 +103,35 @@ exports.seed = (knex) => {
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
|
||||
// Manual Journals
|
||||
{
|
||||
id: 13,
|
||||
resource_id: 4,
|
||||
label_name: 'Transaction type',
|
||||
key: 'transaction_key',
|
||||
data_type: 'textbox',
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
{
|
||||
id: 14,
|
||||
resource_id: 4,
|
||||
label_name: 'Amount',
|
||||
key: 'amount',
|
||||
data_type: 'textbox',
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
{
|
||||
id: 15,
|
||||
resource_id: 4,
|
||||
label_name: 'Journal No.',
|
||||
key: 'journal_number',
|
||||
data_type: 'textbox',
|
||||
predefined: 1,
|
||||
columnable: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,11 +5,23 @@ exports.seed = (knex) => {
|
||||
.then(() => {
|
||||
// Inserts seed entries
|
||||
return knex('views').insert([
|
||||
|
||||
// Accounts
|
||||
{ id: 1, name: 'Assets', roles_logic_expression: '1', resource_id: 1, predefined: true },
|
||||
{ id: 2, name: 'Liabilities', roles_logic_expression: '1', resource_id: 1, predefined: true },
|
||||
{ id: 3, name: 'Equity', roles_logic_expression: '1', resource_id: 1, predefined: true },
|
||||
{ id: 4, name: 'Income', roles_logic_expression: '1', resource_id: 1, predefined: true },
|
||||
{ id: 5, name: 'Expenses', roles_logic_expression: '1', resource_id: 1, predefined: true },
|
||||
|
||||
// Items
|
||||
{ id: 6, name: 'Services', roles_logic_expression: '1', resource_id: 2, predefined: true },
|
||||
{ id: 7, name: 'Inventory', roles_logic_expression: '1', resource_id: 2, predefined: true },
|
||||
{ id: 8, name: 'Non-Inventory', roles_logic_expression: '1', resource_id: 2, predefined: true },
|
||||
|
||||
// Manual Journals
|
||||
{ id: 9, name: 'Journal', roles_logic_expression: '1', resource_id: 4, predefined: true },
|
||||
{ id: 10, name: 'Credit', roles_logic_expression: '1', resource_id: 4, predefined: true },
|
||||
{ id: 11, name: 'Reconciliation', roles_logic_expression: '1', resource_id: 4, predefined: true },
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,11 +5,22 @@ exports.seed = (knex) => {
|
||||
.then(() => {
|
||||
// Inserts seed entries
|
||||
return knex('view_roles').insert([
|
||||
// Accounts
|
||||
{ id: 1, field_id: 6, index: 1, comparator: 'equals', value: 'asset', view_id: 1 },
|
||||
{ id: 2, field_id: 6, index: 1, comparator: 'equals', value: 'liability', view_id: 2 },
|
||||
{ id: 3, field_id: 6, index: 1, comparator: 'equals', value: 'equity', view_id: 3 },
|
||||
{ id: 4, field_id: 6, index: 1, comparator: 'equals', value: 'income', view_id: 4 },
|
||||
{ id: 5, field_id: 6, index: 1, comparator: 'equals', value: 'expense', view_id: 5 },
|
||||
|
||||
// Items
|
||||
{ id: 6, field_id: 12, index: 1, comparator: 'equals', value: 'service', view_id: 6 },
|
||||
{ id: 7, field_id: 12, index: 1, comparator: 'equals', value: 'inventory', view_id: 7 },
|
||||
{ id: 8, field_id: 12, index: 1, comparator: 'equals', value: 'non-inventory', view_id: 8 },
|
||||
|
||||
// Manual Journals
|
||||
{ id: 9, field_id: 13, index: 1, comparator: 'equals', value: 'Journal', view_id: 9 },
|
||||
{ id: 10, field_id: 13, index: 1, comparator: 'equals', value: 'CreditNote', view_id: 10 },
|
||||
{ id: 11, field_id: 13, index: 1, comparator: 'equals', value: 'Reconciliation', view_id: 11 },
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -40,6 +40,10 @@ export default {
|
||||
router.get('/:view_id',
|
||||
asyncMiddleware(this.getView.handler));
|
||||
|
||||
router.get('/:view_id/resource',
|
||||
this.getViewResource.validation,
|
||||
asyncMiddleware(this.getViewResource.handler));
|
||||
|
||||
return router;
|
||||
},
|
||||
|
||||
@@ -83,6 +87,8 @@ export default {
|
||||
],
|
||||
async handler(req, res) {
|
||||
const { view_id: viewId } = req.params;
|
||||
const { View } = req.models;
|
||||
|
||||
const view = await View.query()
|
||||
.where('id', viewId)
|
||||
.withGraphFetched('resource')
|
||||
@@ -381,7 +387,7 @@ export default {
|
||||
// Delete view roles.
|
||||
if (rolesIdsShouldDeleted.length > 0) {
|
||||
const deleteOper = ViewRole.query()
|
||||
.where('id', rolesIdsShouldDeleted)
|
||||
.whereIn('id', rolesIdsShouldDeleted)
|
||||
.delete();
|
||||
asyncOpers.push(deleteOper);
|
||||
}
|
||||
@@ -421,4 +427,47 @@ export default {
|
||||
return res.status(200).send();
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve resource columns that associated to the given custom view.
|
||||
*/
|
||||
getViewResource: {
|
||||
validation: [
|
||||
param('view_id').exists().isNumeric().toInt(),
|
||||
],
|
||||
async handler(req, res) {
|
||||
const { view_id: viewId } = req.params;
|
||||
const { View } = req.models;
|
||||
|
||||
const view = await View.query()
|
||||
.where('id', viewId)
|
||||
.withGraphFetched('resource.fields')
|
||||
.first();
|
||||
|
||||
if (!view) {
|
||||
return res.boom.notFound(null, {
|
||||
errors: [{ type: 'VIEW.NOT.FOUND', code: 100 }],
|
||||
});
|
||||
}
|
||||
if (!view.resource) {
|
||||
return res.boom.badData(null, {
|
||||
errors: [{ type: 'VIEW.HAS.NOT.ASSOCIATED.RESOURCE', code: 200 }],
|
||||
});
|
||||
}
|
||||
|
||||
const resourceColumns = view.resource.fields
|
||||
.filter((field) => field.columnable)
|
||||
.map((field) => ({
|
||||
id: field.id,
|
||||
label: field.labelName,
|
||||
key: field.key,
|
||||
}));
|
||||
|
||||
return res.status(200).send({
|
||||
resource_slug: view.resource.name,
|
||||
resource_columns: resourceColumns,
|
||||
resource_fields: view.resource.fields,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,54 +1,13 @@
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { Model } from 'objection';
|
||||
import TenantModel from '@/models/TenantModel';
|
||||
// import PermissionsService from '@/services/PermissionsService';
|
||||
|
||||
export default class TenantUser extends TenantModel {
|
||||
// ...PermissionsService
|
||||
|
||||
static get virtualAttributes() {
|
||||
return ['fullName'];
|
||||
}
|
||||
|
||||
export default class ExchangeRate extends TenantModel {
|
||||
/**
|
||||
* Table name
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'users';
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Role = require('@/models/Role');
|
||||
|
||||
return {
|
||||
roles: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: this.relationBindKnex(Role.default),
|
||||
join: {
|
||||
from: 'users.id',
|
||||
through: {
|
||||
from: 'user_has_roles.userId',
|
||||
to: 'user_has_roles.roleId',
|
||||
},
|
||||
to: 'roles.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the password of the user.
|
||||
* @param {String} password - The given password.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
verifyPassword(password) {
|
||||
return bcrypt.compareSync(password, this.password);
|
||||
}
|
||||
|
||||
fullName() {
|
||||
return `${this.firstName} ${this.lastName}`;
|
||||
return 'exchange_rates';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user