All files / quality quality.controller.ts

0% Statements 0/37
0% Branches 0/6
0% Functions 0/15
0% Lines 0/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                                                                                                                                                                                             
import { Controller, Get, Post, Put, Body, Param, Query, UseGuards } from '@nestjs/common';
import { QualityService } from './quality.service';
import { JwtAuthGuard } from '../../platform/auth/jwt-auth.guard';
 
@Controller('api/v1/quality')
@UseGuards(JwtAuthGuard)
export class QualityController {
  constructor(private readonly qualityService: QualityService) {}
 
  @Get('configuration')
  async getConfiguration(@Query('tenantId') tenantId: string) {
    return this.qualityService.getConfiguration(tenantId);
  }
 
  @Post('specifications')
  async createSpecification(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.qualityService.createSpecification(tenantId, body);
  }
 
  @Put('specifications/:id/approve')
  async approveSpecification(
    @Param('id') specId: string,
    @Query('tenantId') tenantId: string,
    @Query('approverId') approverId: string
  ) {
    return this.qualityService.approveSpecification(tenantId, specId, approverId);
  }
 
  @Put('specifications/:id')
  async updateSpecification(
    @Param('id') specId: string,
    @Query('tenantId') tenantId: string,
    @Body() body: any
  ) {
    return this.qualityService.updateSpecification(tenantId, specId, body);
  }
 
  @Post('inspections')
  async createInspectionLot(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.qualityService.createInspectionLot(tenantId, body);
  }
 
  @Put('inspections/:id/results')
  async recordInspectionResults(
    @Param('id') lotId: string,
    @Query('tenantId') tenantId: string,
    @Body() body: any
  ) {
    return this.qualityService.recordInspectionResults(tenantId, lotId, body.results || []);
  }
 
  @Post('ncr')
  async createNonConformance(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.qualityService.createNonConformance(tenantId, body);
  }
 
  @Post('capa')
  async createCapa(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.qualityService.createCapa(tenantId, body);
  }
 
  @Put('capa/:id/verify')
  async verifyCapaEffectiveness(@Param('id') capaId: string, @Query('tenantId') tenantId: string) {
    return this.qualityService.verifyCapaEffectiveness(tenantId, capaId);
  }
 
  @Put('capa/:id/close')
  async closeCapa(@Param('id') capaId: string, @Query('tenantId') tenantId: string) {
    return this.qualityService.closeCapa(tenantId, capaId);
  }
 
  @Post('audits')
  async createAudit(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.qualityService.createAudit(tenantId, body);
  }
 
  @Put('audits/:id/issue')
  async issueAuditFindings(@Param('id') auditId: string, @Query('tenantId') tenantId: string) {
    return this.qualityService.issueAuditFindings(tenantId, auditId);
  }
 
  @Put('audits/:id/checklist/:index')
  async updateAuditChecklistQuestion(
    @Param('id') auditId: string,
    @Param('index') indexStr: string,
    @Query('tenantId') tenantId: string,
    @Body() body: any
  ) {
    const idx = parseInt(indexStr, 10);
    return this.qualityService.updateAuditChecklistQuestion(tenantId, auditId, idx, body);
  }
 
  @Post('risk/fmea')
  async calculateFmea(@Query('tenantId') tenantId: string, @Body() body: any) {
    const score = await this.qualityService.calculateFmeaRPN(tenantId, {
      severity: body.severity,
      occurrence: body.occurrence,
      detection: body.detection
    });
    return { riskPriorityNumber: score };
  }
}