mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
refactor(nestjs): contacts module
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { Contact } from '../models/Contact';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ERRORS } from '../Contacts.constants';
|
||||
|
||||
@Injectable()
|
||||
export class ActivateContactService {
|
||||
constructor(
|
||||
@Inject(Contact.name)
|
||||
private readonly contactModel: TenantModelProxy<typeof Contact>,
|
||||
) {}
|
||||
|
||||
async activateContact(contactId: number) {
|
||||
const contact = await this.contactModel()
|
||||
.query()
|
||||
.findById(contactId)
|
||||
.throwIfNotFound();
|
||||
|
||||
if (contact.active) {
|
||||
throw new ServiceError(ERRORS.CONTACT_ALREADY_ACTIVE);
|
||||
}
|
||||
await this.contactModel()
|
||||
.query()
|
||||
.findById(contactId)
|
||||
.update({ active: true });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||
import { Contact } from '../models/Contact';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { ERRORS } from '../Contacts.constants';
|
||||
|
||||
@Injectable()
|
||||
export class InactivateContactService {
|
||||
constructor(
|
||||
@Inject(Contact.name)
|
||||
private readonly contactModel: TenantModelProxy<typeof Contact>,
|
||||
) {}
|
||||
|
||||
async inactivateContact(contactId: number) {
|
||||
const contact = await this.contactModel()
|
||||
.query()
|
||||
.findById(contactId)
|
||||
.throwIfNotFound();
|
||||
|
||||
if (!contact.active) {
|
||||
throw new ServiceError(ERRORS.CONTACT_ALREADY_INACTIVE);
|
||||
}
|
||||
await this.contactModel()
|
||||
.query()
|
||||
.findById(contactId)
|
||||
.update({ active: false });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user