- LabelTemplate bekommt columns/rows (optional, leer = automatisch passend), plus konfigurierbare Raender/Abstaende - damit ein Etikett exakt auf das vorgedruckte Raster eines physischen Etikettenbogens (z.B. Avery) gelegt werden kann statt nur automatisch berechnet - Startposition beim Drucken waehlbar, fuer bereits angebrochene Boegen (erste Seite startet ab der gewaehlten Position, Folgeseiten wieder von vorne)
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
Res,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import type { Response } from 'express';
|
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
|
import { CreateLabelTemplateDto } from './dto/create-label-template.dto';
|
|
import { UpdateLabelTemplateDto } from './dto/update-label-template.dto';
|
|
import { LabelTemplatesService } from './label-templates.service';
|
|
|
|
@ApiTags('label-templates')
|
|
@ApiBearerAuth()
|
|
@Controller('label-templates')
|
|
export class LabelTemplatesController {
|
|
constructor(private readonly labelTemplatesService: LabelTemplatesService) {}
|
|
|
|
@RequirePermission('label-templates:read')
|
|
@Get()
|
|
findAll() {
|
|
return this.labelTemplatesService.findAll();
|
|
}
|
|
|
|
@RequirePermission('label-templates:read')
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.labelTemplatesService.findById(id);
|
|
}
|
|
|
|
@RequirePermission('label-templates:create')
|
|
@Post()
|
|
create(
|
|
@Body() dto: CreateLabelTemplateDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.labelTemplatesService.create(dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('label-templates:update')
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateLabelTemplateDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.labelTemplatesService.update(id, dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('label-templates:deactivate')
|
|
@Delete(':id')
|
|
deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
|
return this.labelTemplatesService.deactivate(id, actor.id);
|
|
}
|
|
|
|
@RequirePermission('label-templates:print')
|
|
@Get(':id/print/:bottlingBatchId')
|
|
async print(
|
|
@Param('id') id: string,
|
|
@Param('bottlingBatchId') bottlingBatchId: string,
|
|
@Query('startPosition', new ParseIntPipe({ optional: true }))
|
|
startPosition: number | undefined,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const pdf = await this.labelTemplatesService.renderLabelsPdf(
|
|
id,
|
|
bottlingBatchId,
|
|
startPosition,
|
|
);
|
|
res.setHeader('Content-Type', 'application/pdf');
|
|
res.setHeader(
|
|
'Content-Disposition',
|
|
'attachment; filename="etiketten.pdf"',
|
|
);
|
|
res.send(pdf);
|
|
}
|
|
}
|