mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-27 18:19:48 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import { Model } from 'objection';
|
||||
import { InventoryAdjustmentEntry } from './InventoryAdjustmentEntry';
|
||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
export class InventoryAdjustment extends TenantBaseModel {
|
||||
public readonly date!: string;
|
||||
public readonly type!: string;
|
||||
public readonly adjustmentAccountId!: number;
|
||||
public readonly reason?: string;
|
||||
public readonly referenceNo!: string;
|
||||
public readonly description?: string;
|
||||
public readonly userId!: number;
|
||||
public readonly publishedAt?: string;
|
||||
|
||||
public readonly branchId!: number;
|
||||
public readonly warehouseId!: number;
|
||||
|
||||
public readonly createdAt!: Date | string;
|
||||
|
||||
public readonly entries: InventoryAdjustmentEntry[];
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'inventory_adjustments';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps(): Array<string> {
|
||||
return ['created_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes(): Array<string> {
|
||||
return ['formattedType', 'inventoryDirection', 'isPublished'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve formatted adjustment type.
|
||||
*/
|
||||
get formattedType(): string {
|
||||
return InventoryAdjustment.getFormattedType(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve formatted reference type.
|
||||
*/
|
||||
get inventoryDirection(): string {
|
||||
return InventoryAdjustment.getInventoryDirection(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the adjustment is published.
|
||||
* @return {boolean}
|
||||
*/
|
||||
get isPublished(): boolean {
|
||||
return !!this.publishedAt;
|
||||
}
|
||||
|
||||
static getInventoryDirection(type) {
|
||||
const directions = {
|
||||
increment: 'IN',
|
||||
decrement: 'OUT',
|
||||
};
|
||||
return directions[type] || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the formatted adjustment type of the given type.
|
||||
* @param {string} type
|
||||
* @returns {string}
|
||||
*/
|
||||
static getFormattedType(type) {
|
||||
const types = {
|
||||
increment: 'inventory_adjustment.type.increment',
|
||||
decrement: 'inventory_adjustment.type.decrement',
|
||||
};
|
||||
return types[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const { InventoryAdjustmentEntry } = require('./InventoryAdjustmentEntry');
|
||||
const { Account } = require('../../Accounts/models/Account.model');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Adjustment entries.
|
||||
*/
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: InventoryAdjustmentEntry,
|
||||
join: {
|
||||
from: 'inventory_adjustments.id',
|
||||
to: 'inventory_adjustments_entries.adjustmentId',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Inventory adjustment account.
|
||||
*/
|
||||
adjustmentAccount: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account,
|
||||
join: {
|
||||
from: 'inventory_adjustments.adjustmentAccountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Model settings.
|
||||
*/
|
||||
// static get meta() {
|
||||
// return InventoryAdjustmentSettings;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Model } from 'objection';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
import { Item } from '@/modules/Items/models/Item';
|
||||
// import TenantModel from 'models/TenantModel';
|
||||
|
||||
export class InventoryAdjustmentEntry extends BaseModel {
|
||||
adjustmentId!: number;
|
||||
index!: number;
|
||||
itemId!: number;
|
||||
quantity!: number;
|
||||
cost!: number;
|
||||
value!: number;
|
||||
|
||||
item!: Item;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'inventory_adjustments_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const { InventoryAdjustment } = require('./InventoryAdjustment');
|
||||
const { Item } = require('../../Items/models/Item');
|
||||
|
||||
return {
|
||||
inventoryAdjustment: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: InventoryAdjustment,
|
||||
join: {
|
||||
from: 'inventory_adjustments_entries.adjustmentId',
|
||||
to: 'inventory_adjustments.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Entry item.
|
||||
*/
|
||||
item: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Item,
|
||||
join: {
|
||||
from: 'inventory_adjustments_entries.itemId',
|
||||
to: 'items.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user