mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-11 18:30:30 +00:00
refactor(nestjs): contacts module
This commit is contained in:
45
packages/server/src/modules/Contacts/Contacts.controller.ts
Normal file
45
packages/server/src/modules/Contacts/Contacts.controller.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
Param,
|
||||
Post,
|
||||
ParseIntPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiParam } from '@nestjs/swagger';
|
||||
import { GetContactsAutoCompleteQuery } from './dtos/GetContactsAutoCompleteQuery.dto';
|
||||
import { GetAutoCompleteContactsService } from './queries/GetAutoCompleteContacts.service';
|
||||
import { ActivateContactService } from './commands/ActivateContact.service';
|
||||
import { InactivateContactService } from './commands/InactivateContact.service';
|
||||
|
||||
@Controller('contacts')
|
||||
@ApiTags('contacts')
|
||||
export class ContactsController {
|
||||
constructor(
|
||||
private readonly getAutoCompleteService: GetAutoCompleteContactsService,
|
||||
private readonly activateContactService: ActivateContactService,
|
||||
private readonly inactivateContactService: InactivateContactService,
|
||||
) {}
|
||||
|
||||
@Get('auto-complete')
|
||||
@ApiOperation({ summary: 'Get the auto-complete contacts' })
|
||||
getAutoComplete(@Query() query: GetContactsAutoCompleteQuery) {
|
||||
return this.getAutoCompleteService.autocompleteContacts(query);
|
||||
}
|
||||
|
||||
@Post(':id/activate')
|
||||
@ApiOperation({ summary: 'Activate a contact' })
|
||||
@ApiParam({ name: 'id', type: 'number', description: 'Contact ID' })
|
||||
async activateContact(@Param('id', ParseIntPipe) contactId: number) {
|
||||
await this.activateContactService.activateContact(contactId);
|
||||
return { id: contactId, activated: true };
|
||||
}
|
||||
|
||||
@Post(':id/inactivate')
|
||||
@ApiOperation({ summary: 'Inactivate a contact' })
|
||||
@ApiParam({ name: 'id', type: 'number', description: 'Contact ID' })
|
||||
async inactivateContact(@Param('id', ParseIntPipe) contactId: number) {
|
||||
await this.inactivateContactService.inactivateContact(contactId);
|
||||
return { id: contactId, inactivated: true };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user