mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
79 lines
1.4 KiB
JavaScript
79 lines
1.4 KiB
JavaScript
import { Model, QueryBuilder } from 'objection';
|
|
import TenantModel from 'models/TenantModel';
|
|
import PaginationQueryBuilder from './Pagination';
|
|
|
|
class VendorQueryBuilder extends PaginationQueryBuilder {
|
|
constructor(...args) {
|
|
super(...args);
|
|
|
|
this.onBuild((builder) => {
|
|
if (builder.isFind() || builder.isDelete() || builder.isUpdate()) {
|
|
builder.where('contact_service', 'vendor');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export default class Vendor extends TenantModel {
|
|
/**
|
|
* Query builder.
|
|
*/
|
|
static get QueryBuilder() {
|
|
return VendorQueryBuilder;
|
|
}
|
|
|
|
/**
|
|
* Table name
|
|
*/
|
|
static get tableName() {
|
|
return 'contacts';
|
|
}
|
|
|
|
/**
|
|
* Model timestamps.
|
|
*/
|
|
get timestamps() {
|
|
return ['createdAt', 'updatedAt'];
|
|
}
|
|
|
|
/**
|
|
* Defined virtual attributes.
|
|
*/
|
|
static get virtualAttributes() {
|
|
return ['closingBalance'];
|
|
}
|
|
|
|
/**
|
|
* Closing balance attribute.
|
|
*/
|
|
get closingBalance() {
|
|
return this.openingBalance + this.balance;
|
|
}
|
|
|
|
/**
|
|
* Relationship mapping.
|
|
*/
|
|
static get relationMappings() {
|
|
const Bill = require('models/Bill');
|
|
|
|
return {
|
|
bills: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: Bill.default,
|
|
join: {
|
|
from: 'contacts.id',
|
|
to: 'bills.vendorId',
|
|
},
|
|
}
|
|
};
|
|
}
|
|
|
|
static get fields() {
|
|
return {
|
|
created_at: {
|
|
column: 'created_at',
|
|
}
|
|
};
|
|
}
|
|
}
|