mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
Migrate from Vue to React framework.
This commit is contained in:
@@ -205,13 +205,14 @@ factory.define('view_role', 'view_roles', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
factory.define('view_has_columns', 'view_has_columns', async () => {
|
||||
factory.define('view_column', 'view_has_columns', async () => {
|
||||
const view = await factory.create('view');
|
||||
const field = await factory.create('resource_field');
|
||||
|
||||
return {
|
||||
field_id: field.id,
|
||||
view_id: view.id,
|
||||
// index: 1,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ exports.up = function (knex) {
|
||||
table.increments();
|
||||
table.integer('view_id').unsigned();
|
||||
table.integer('field_id').unsigned();
|
||||
table.integer('index').unsigned();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
exports.up = function(knex) {
|
||||
|
||||
};
|
||||
|
||||
exports.down = function(knex) {
|
||||
|
||||
};
|
||||
@@ -52,9 +52,9 @@ export default {
|
||||
check('type').exists().trim().escape().isIn(['service', 'product']),
|
||||
check('cost_price').exists().isNumeric(),
|
||||
check('sell_price').exists().isNumeric(),
|
||||
check('cost_account_id').exists().isInt(),
|
||||
check('sell_account_id').exists().isInt(),
|
||||
check('category_id').optional().isInt(),
|
||||
check('cost_account_id').exists().isInt().toInt(),
|
||||
check('sell_account_id').exists().isInt().toInt(),
|
||||
check('category_id').optional().isInt().toInt(),
|
||||
|
||||
check('custom_fields').optional().isArray({ min: 1 }),
|
||||
check('custom_fields.*.key').exists().isNumeric().toInt(),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { difference } from 'lodash';
|
||||
import { difference, pick } from 'lodash';
|
||||
import express from 'express';
|
||||
import { check, query, validationResult } from 'express-validator';
|
||||
import asyncMiddleware from '@/http/middleware/asyncMiddleware';
|
||||
import jwtAuth from '@/http/middleware/jwtAuth';
|
||||
import Resource from '@/models/Resource';
|
||||
import View from '../../models/View';
|
||||
import View from '@/models/View';
|
||||
import ViewRole from '@/models/ViewRole';
|
||||
|
||||
export default {
|
||||
resource: 'items',
|
||||
@@ -14,6 +16,8 @@ export default {
|
||||
router() {
|
||||
const router = express.Router();
|
||||
|
||||
router.use(jwtAuth);
|
||||
|
||||
router.post('/',
|
||||
this.createView.validation,
|
||||
asyncMiddleware(this.createView.handler));
|
||||
@@ -29,6 +33,10 @@ export default {
|
||||
router.get('/:view_id',
|
||||
asyncMiddleware(this.getView.handler));
|
||||
|
||||
router.get('/resource/:resource_name',
|
||||
this.getResourceViews.validation,
|
||||
asyncMiddleware(this.getResourceViews.handler));
|
||||
|
||||
return router;
|
||||
},
|
||||
|
||||
@@ -105,7 +113,9 @@ export default {
|
||||
check('roles.*.comparator').exists(),
|
||||
check('roles.*.value').exists(),
|
||||
check('roles.*.index').exists().isNumeric().toInt(),
|
||||
check('columns.*').exists().escape().trim(),
|
||||
check('columns').exists().isArray(),
|
||||
check('columns.*.field').exists().escape().trim(),
|
||||
check('columns.*.index').exists().isNumeric().toInt(),
|
||||
],
|
||||
async handler(req, res) {
|
||||
const validationErrors = validationResult(req);
|
||||
@@ -115,7 +125,6 @@ export default {
|
||||
code: 'validation_error', ...validationErrors,
|
||||
});
|
||||
}
|
||||
|
||||
const form = { ...req.body };
|
||||
const resource = await Resource.query().where('name', form.resource_name).first();
|
||||
|
||||
@@ -152,11 +161,23 @@ export default {
|
||||
predefined: false,
|
||||
resource_id: resource.id,
|
||||
});
|
||||
|
||||
// Save view roles.
|
||||
|
||||
// Save view roles async operations.
|
||||
const saveViewRolesOpers = [];
|
||||
|
||||
return res.status(200).send();
|
||||
form.roles.forEach((role) => {
|
||||
const fieldModel = resourceFields.find((f) => f.slug === role.field);
|
||||
|
||||
const oper = ViewRole.query().insert({
|
||||
...pick(role, ['comparator', 'value', 'index']),
|
||||
field_id: fieldModel.id,
|
||||
view_id: view.id,
|
||||
});
|
||||
saveViewRolesOpers.push(oper);
|
||||
});
|
||||
await Promise.all(saveViewRolesOpers);
|
||||
|
||||
return res.status(200).send({ id: view.id });
|
||||
},
|
||||
},
|
||||
|
||||
@@ -190,4 +211,13 @@ export default {
|
||||
return res.status(200).send();
|
||||
},
|
||||
},
|
||||
|
||||
getResourceViews: {
|
||||
validation: [
|
||||
|
||||
],
|
||||
async handler(req, res) {
|
||||
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,15 +14,19 @@ export default class View extends BaseModel {
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Resource = require('@/models/Resource');
|
||||
const ViewColumn = require('@/models/ViewColumn');
|
||||
const ViewRole = require('@/models/ViewRole');
|
||||
|
||||
return {
|
||||
/**
|
||||
* View model belongs to resource model.
|
||||
*/
|
||||
resource: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelBase: path.join(__dirname, 'Resource'),
|
||||
modelClass: Resource.default,
|
||||
join: {
|
||||
from: 'views.resource_id',
|
||||
from: 'views.resourceId',
|
||||
to: 'resources.id',
|
||||
},
|
||||
},
|
||||
@@ -30,38 +34,26 @@ export default class View extends BaseModel {
|
||||
/**
|
||||
* View model may has many columns.
|
||||
*/
|
||||
// columns: {
|
||||
// relation: Model.ManyToManyRelation,
|
||||
// modelBase: path.join(__dirname, 'ResourceField'),
|
||||
// join: {
|
||||
// from: 'id',
|
||||
// through: {
|
||||
// from: 'view_has_columns.view_id',
|
||||
// to: 'view_has_columns.field_id',
|
||||
// },
|
||||
// to: 'resource_fields.view_id',
|
||||
// }
|
||||
// }
|
||||
columns: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: ViewColumn.default,
|
||||
join: {
|
||||
from: 'views.id',
|
||||
to: 'view_has_columns.view_id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* View model may has many view roles.
|
||||
*/
|
||||
viewRoles: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelBase: path.join(__dirname, 'ViewRole'),
|
||||
modelClass: ViewRole.default,
|
||||
join: {
|
||||
from: 'views.id',
|
||||
to: 'view_id',
|
||||
to: 'view_roles.view_id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// columns() {
|
||||
// return this.belongsToMany('ResourceField', 'view_has_columns', 'view_id', 'field_id');
|
||||
// },
|
||||
|
||||
// viewRoles() {
|
||||
// return this.hasMany('ViewRole', 'view_id');
|
||||
// },
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export default class ViewColumn extends BaseModel {
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'view_columns';
|
||||
return 'view_has_columns';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user