mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiBody } from '@nestjs/swagger';
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Get,
|
||||
Body,
|
||||
Req,
|
||||
Res,
|
||||
Next,
|
||||
} from '@nestjs/common';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { BuildOrganizationService } from './commands/BuildOrganization.service';
|
||||
import {
|
||||
BuildOrganizationDto,
|
||||
UpdateOrganizationDto,
|
||||
} from './dtos/Organization.dto';
|
||||
import { GetCurrentOrganizationService } from './queries/GetCurrentOrganization.service';
|
||||
import { UpdateOrganizationService } from './commands/UpdateOrganization.service';
|
||||
import { IgnoreTenantInitializedRoute } from '../Tenancy/EnsureTenantIsInitialized.guard';
|
||||
import { IgnoreTenantSeededRoute } from '../Tenancy/EnsureTenantIsSeeded.guards';
|
||||
|
||||
@ApiTags('Organization')
|
||||
@Controller('organization')
|
||||
@IgnoreTenantInitializedRoute()
|
||||
@IgnoreTenantSeededRoute()
|
||||
export class OrganizationController {
|
||||
constructor(
|
||||
private readonly buildOrganizationService: BuildOrganizationService,
|
||||
private readonly getCurrentOrgService: GetCurrentOrganizationService,
|
||||
private readonly updateOrganizationService: UpdateOrganizationService,
|
||||
) {}
|
||||
|
||||
@Post('build')
|
||||
@ApiOperation({ summary: 'Build organization database' })
|
||||
@ApiBody({ type: BuildOrganizationDto })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'The organization database has been initialized',
|
||||
})
|
||||
async build(
|
||||
@Body() buildDTO: BuildOrganizationDto,
|
||||
@Req() req: Request,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const result = await this.buildOrganizationService.buildRunJob(buildDTO);
|
||||
|
||||
return res.status(200).send({
|
||||
type: 'success',
|
||||
code: 'ORGANIZATION.DATABASE.INITIALIZED',
|
||||
message: 'The organization database has been initialized.',
|
||||
data: result,
|
||||
});
|
||||
}
|
||||
|
||||
@Get('current')
|
||||
@ApiOperation({ summary: 'Get current organization' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Returns the current organization',
|
||||
})
|
||||
async currentOrganization(
|
||||
@Req() req: Request,
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
) {
|
||||
const organization =
|
||||
await this.getCurrentOrgService.getCurrentOrganization();
|
||||
|
||||
return res.status(200).send({ organization });
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update organization information' })
|
||||
@ApiBody({ type: UpdateOrganizationDto })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Organization information has been updated successfully',
|
||||
})
|
||||
async updateOrganization(
|
||||
@Body() updateDTO: UpdateOrganizationDto,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
await this.updateOrganizationService.execute(updateDTO);
|
||||
|
||||
return res.status(200).send({
|
||||
code: 200,
|
||||
message: 'Organization information has been updated successfully.',
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user