Add field management module with database schema and validation
- Introduced `FieldModule` to manage cycles and plans, including read and write controllers. - Created database migrations for `company_settings`, `cycles`, `cycle_weekdays`, `cycle_destinations`, `plans`, `plan_destinations`, `plan_invoices`, and `plan_packing_slips` tables, including constraints and unique indexes. - Developed service and repository layers for handling cycle and plan data operations. - Added unit tests for the cycles and plans services, repositories, and controllers to ensure functionality and correctness. - Updated application module to include the new `FieldModule` for better organization.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiForbiddenResponse,
|
||||
ApiNotFoundResponse,
|
||||
ApiOkResponse,
|
||||
ApiOperation,
|
||||
ApiTags,
|
||||
ApiUnauthorizedResponse,
|
||||
} from '@nestjs/swagger';
|
||||
import { CurrentUser } from '../../../common/decorators/current-user.decorator';
|
||||
import type { AuthUser } from '../../../common/auth/auth-user';
|
||||
import {
|
||||
Pagination,
|
||||
type PaginationResponse,
|
||||
PaginationMetaDto,
|
||||
} from '../../../common/http/response';
|
||||
import { BEARER_AUTH_NAME } from '../../../common/swagger/setup-swagger';
|
||||
import { RequireFieldPrivilege } from '../shared/field-privilege.decorator';
|
||||
import { FieldPrivilegeGuard } from '../shared/field-privilege.guard';
|
||||
import { CyclesService } from './cycles.service';
|
||||
import { CycleDto, ListCyclesQueryDto } from './dto/cycle.dto';
|
||||
|
||||
@ApiTags('cycles')
|
||||
@ApiBearerAuth(BEARER_AUTH_NAME)
|
||||
@UseGuards(FieldPrivilegeGuard)
|
||||
@Controller('cycles')
|
||||
export class CyclesReadController {
|
||||
constructor(private readonly cyclesService: CyclesService) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
@RequireFieldPrivilege('cycle', 'view')
|
||||
@ApiOperation({ summary: 'List cycles' })
|
||||
@ApiOkResponse({
|
||||
schema: {
|
||||
properties: {
|
||||
data: {
|
||||
type: 'array',
|
||||
items: { $ref: '#/components/schemas/CycleDto' },
|
||||
},
|
||||
meta: { $ref: '#/components/schemas/PaginationMetaDto' },
|
||||
},
|
||||
},
|
||||
})
|
||||
@ApiUnauthorizedResponse()
|
||||
@ApiForbiddenResponse()
|
||||
list(
|
||||
@Query() query: ListCyclesQueryDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
): Promise<PaginationResponse<CycleDto>> {
|
||||
return this.cyclesService.list(query, user);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@RequireFieldPrivilege('cycle', 'view')
|
||||
@ApiOperation({ summary: 'Get cycle detail' })
|
||||
@ApiOkResponse({ type: CycleDto })
|
||||
@ApiNotFoundResponse()
|
||||
@ApiUnauthorizedResponse()
|
||||
@ApiForbiddenResponse()
|
||||
findOne(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@CurrentUser() user: AuthUser,
|
||||
): Promise<CycleDto> {
|
||||
return this.cyclesService.findById(id, user);
|
||||
}
|
||||
}
|
||||
|
||||
void PaginationMetaDto;
|
||||
Reference in New Issue
Block a user