mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
WIP Items module.
This commit is contained in:
58
server/src/database/factories/index.js
Normal file
58
server/src/database/factories/index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import knexFactory from 'knex-factory';
|
||||
import faker from 'faker';
|
||||
import knex from '@/database/knex';
|
||||
import { hashPassword } from '@/utils';
|
||||
|
||||
const factory = knexFactory(knex);
|
||||
|
||||
factory.define('user', 'users', async () => {
|
||||
const hashedPassword = await hashPassword('admin');
|
||||
|
||||
return {
|
||||
first_name: faker.name.firstName(),
|
||||
last_name: faker.name.lastName(),
|
||||
email: faker.internet.email(),
|
||||
phone_number: faker.phone.phoneNumber(),
|
||||
active: 1,
|
||||
password: hashedPassword,
|
||||
};
|
||||
});
|
||||
|
||||
factory.define('account', 'accounts', async () => ({
|
||||
name: faker.lorem.word(),
|
||||
type: faker.lorem.word(),
|
||||
description: faker.lorem.paragraph(),
|
||||
}));
|
||||
|
||||
factory.define('item_category', 'items_categories', () => ({
|
||||
label: faker.name.firstName(),
|
||||
description: faker.lorem.text(),
|
||||
parent_category_id: null,
|
||||
}));
|
||||
|
||||
factory.define('item_metadata', 'items_metadata', async () => {
|
||||
const item = await factory.create('item');
|
||||
|
||||
return {
|
||||
key: faker.lorem.slug(),
|
||||
value: faker.lorem.word(),
|
||||
item_id: item.id,
|
||||
};
|
||||
});
|
||||
|
||||
factory.define('item', 'items', async () => {
|
||||
const category = await factory.create('item_category');
|
||||
const account = await factory.create('account');
|
||||
|
||||
return {
|
||||
name: faker.lorem.word(),
|
||||
note: faker.lorem.paragraph(),
|
||||
cost_price: faker.random.number(),
|
||||
sell_price: faker.random.number(),
|
||||
cost_account_id: account.id,
|
||||
sell_account_id: account.id,
|
||||
category_id: category.id,
|
||||
};
|
||||
});
|
||||
|
||||
export default factory;
|
||||
7
server/src/database/knex.js
Normal file
7
server/src/database/knex.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import Knex from 'knex';
|
||||
import knexfile from '@/../knexfile';
|
||||
|
||||
const config = knexfile[process.env.NODE_ENV];
|
||||
const knex = Knex(config);
|
||||
|
||||
export default knex;
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
exports.up = (knex) => knex.schema.createTable('roles', (table) => {
|
||||
table.increments();
|
||||
table.string('name');
|
||||
table.string('description');
|
||||
table.boolean('predefined').default(false);
|
||||
table.timestamps();
|
||||
});
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTable('roles');
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema.createTable('users', (table) => {
|
||||
table.increments();
|
||||
table.string('first_name');
|
||||
table.string('last_name');
|
||||
table.string('email').unique();
|
||||
table.string('phone_number').unique();
|
||||
table.string('password');
|
||||
table.boolean('active');
|
||||
table.integer('role_id').unique();
|
||||
table.string('language');
|
||||
table.date('last_login_at');
|
||||
table.timestamps();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(knex) {
|
||||
return knex.schema.dropTableIfExists('users');
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema.createTable('oauth_tokens', table => {
|
||||
table.increments();
|
||||
table.string('access_token');
|
||||
table.date('access_token_expires_on');
|
||||
table.integer('client_id').unsigned();
|
||||
table.string('refresh_token');
|
||||
table.date('refresh_token_expires_on');
|
||||
table.integer('user_id').unsigned().references('id').inTable('users');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(knex) {
|
||||
return knex.schema.dropTableIfExists('oauth_tokens');
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema.createTable('oauth_clients', table => {
|
||||
table.increments();
|
||||
table.integer('client_id').unsigned();
|
||||
table.string('client_secret');
|
||||
table.string('redirect_uri');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('oauth_clients');
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema.createTable('settings', table => {
|
||||
table.increments();
|
||||
table.integer('user_id').unsigned().references('id').inTable('users');
|
||||
table.string('key');
|
||||
table.string('value');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('settings');
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('items', (table) => {
|
||||
table.increments();
|
||||
table.string('name');
|
||||
table.integer('type_id').unsigned();
|
||||
table.decimal('cost_price').unsigned();
|
||||
table.decimal('sell_price').unsigned();
|
||||
table.string('currency_code', 3);
|
||||
table.string('picture_uri');
|
||||
table.integer('cost_account_id').unsigned();
|
||||
table.integer('sell_account_id').unsigned();
|
||||
table.text('note').nullable();
|
||||
table.integer('category_id').unsigned();
|
||||
table.integer('user_id').unsigned();
|
||||
table.timestamps();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('items');
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('accounts', (table) => {
|
||||
table.increments();
|
||||
table.string('name');
|
||||
table.string('type');
|
||||
table.integer('parent_account_id');
|
||||
table.string('code', 10);
|
||||
table.text('description');
|
||||
table.timestamps();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('accounts');
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('account_balance', (table) => {
|
||||
table.increments();
|
||||
table.integer('account_id');
|
||||
table.decimal('amount');
|
||||
table.string('currency_code', 3);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('account_balance');
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('items_categories', (table) => {
|
||||
table.increments();
|
||||
table.string('label');
|
||||
table.integer('parent_category_id').unsigned();
|
||||
table.text('description');
|
||||
table.integer('user_id').unsigned();
|
||||
table.timestamps();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('items_categories');
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('items_metadata', (table) => {
|
||||
table.increments();
|
||||
table.string('key');
|
||||
table.string('value');
|
||||
table.integer('item_id').unsigned();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = (knex) => knex.schema.dropTableIfExists('items_metadata');
|
||||
Reference in New Issue
Block a user