mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: activate/inactive contacts.
This commit is contained in:
@@ -12,13 +12,10 @@ import {
|
||||
IContactsAutoCompleteFilter,
|
||||
} from 'interfaces';
|
||||
import JournalPoster from '../Accounting/JournalPoster';
|
||||
import { ERRORS } from './constants';
|
||||
|
||||
type TContactService = 'customer' | 'vendor';
|
||||
|
||||
const ERRORS = {
|
||||
OPENING_BALANCE_DATE_REQUIRED: 'OPENING_BALANCE_DATE_REQUIRED',
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class ContactsService {
|
||||
@Inject()
|
||||
@@ -361,4 +358,34 @@ export default class ContactsService {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inactive the given contact.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number} contactId - Contact id.
|
||||
*/
|
||||
async inactivateContact(tenantId: number, contactId: number): Promise<void> {
|
||||
const { Contact } = this.tenancy.models(tenantId);
|
||||
const contact = await this.getContactByIdOrThrowError(tenantId, contactId);
|
||||
|
||||
if(!contact.active) {
|
||||
throw new ServiceError(ERRORS.CONTACT_ALREADY_INACTIVE);
|
||||
}
|
||||
await Contact.query().findById(contactId).update({ active: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Inactive the given contact.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number} contactId - Contact id.
|
||||
*/
|
||||
async activateContact(tenantId: number, contactId: number): Promise<void> {
|
||||
const { Contact } = this.tenancy.models(tenantId);
|
||||
const contact = await this.getContactByIdOrThrowError(tenantId, contactId);
|
||||
|
||||
if(contact.active) {
|
||||
throw new ServiceError(ERRORS.CONTACT_ALREADY_ACTIVE);
|
||||
}
|
||||
await Contact.query().findById(contactId).update({ active: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,3 +20,10 @@ export const DEFAULT_VIEWS = [
|
||||
columns: DEFAULT_VIEW_COLUMNS,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export const ERRORS = {
|
||||
OPENING_BALANCE_DATE_REQUIRED: 'OPENING_BALANCE_DATE_REQUIRED',
|
||||
CONTACT_ALREADY_INACTIVE: 'CONTACT_ALREADY_INACTIVE',
|
||||
CONTACT_ALREADY_ACTIVE: 'CONTACT_ALREADY_ACTIVE'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user