fix: Bug fixed für alle Seiten und das Profil und label
This commit is contained in:
1 parent
133edcd5ba
commit
0a52b29c57
52 files changed
+1290
-129
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { PartialType, PickType } from '@nestjs/swagger';
|
||||
import { CreateStockItemDto } from './create-stock-item.dto';
|
||||
|
||||
export class UpdateStockItemDto extends PartialType(
|
||||
PickType(CreateStockItemDto, [
|
||||
'name',
|
||||
'category',
|
||||
'unit',
|
||||
'minThreshold',
|
||||
'notes',
|
||||
] as const),
|
||||
) {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { PartialType, PickType } from '@nestjs/swagger';
|
||||
import { CreateStorageContainerDto } from './create-storage-container.dto';
|
||||
|
||||
export class UpdateStorageContainerDto extends PartialType(
|
||||
PickType(CreateStorageContainerDto, [
|
||||
'containerType',
|
||||
'capacity',
|
||||
'location',
|
||||
] as const),
|
||||
) {}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
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 { CreateStorageContainerDto } from './dto/create-storage-container.dto';
|
||||
import { UpdateStorageContainerDto } from './dto/update-storage-container.dto';
|
||||
import { CreateStockItemDto } from './dto/create-stock-item.dto';
|
||||
import { UpdateStockItemDto } from './dto/update-stock-item.dto';
|
||||
import { CreateStockMovementDto } from './dto/create-stock-movement.dto';
|
||||
import { StorageService } from './storage.service';
|
||||
|
||||
@@ -29,6 +31,16 @@ export class StorageController {
|
||||
return this.storageService.createContainer(dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('storage:update')
|
||||
@Patch('storage-containers/:id')
|
||||
updateContainer(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateStorageContainerDto,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
) {
|
||||
return this.storageService.updateContainer(id, dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('storage:read')
|
||||
@Get('stock-items')
|
||||
findAllStockItems() {
|
||||
@@ -50,6 +62,16 @@ export class StorageController {
|
||||
return this.storageService.createStockItem(dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('storage:update')
|
||||
@Patch('stock-items/:id')
|
||||
updateStockItem(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateStockItemDto,
|
||||
@CurrentUser() actor: AuthenticatedUser,
|
||||
) {
|
||||
return this.storageService.updateStockItem(id, dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('storage:move')
|
||||
@Post('stock-items/:id/movements')
|
||||
addMovement(
|
||||
|
||||
@@ -4,7 +4,9 @@ import { AuditLogService } from '../audit/audit-log.service';
|
||||
import { WebhooksService } from '../webhooks/webhooks.service';
|
||||
import { StockItem, StorageContainer } from '../../generated/prisma';
|
||||
import { CreateStorageContainerDto } from './dto/create-storage-container.dto';
|
||||
import { UpdateStorageContainerDto } from './dto/update-storage-container.dto';
|
||||
import { CreateStockItemDto } from './dto/create-stock-item.dto';
|
||||
import { UpdateStockItemDto } from './dto/update-stock-item.dto';
|
||||
import { CreateStockMovementDto } from './dto/create-stock-movement.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -36,6 +38,32 @@ export class StorageService {
|
||||
return container;
|
||||
}
|
||||
|
||||
async updateContainer(
|
||||
id: string,
|
||||
dto: UpdateStorageContainerDto,
|
||||
actingUserId: string,
|
||||
): Promise<StorageContainer> {
|
||||
const before = await this.prisma.storageContainer.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (!before) {
|
||||
throw new NotFoundException('Storage container not found');
|
||||
}
|
||||
const container = await this.prisma.storageContainer.update({
|
||||
where: { id },
|
||||
data: { ...dto },
|
||||
});
|
||||
await this.auditLog.record({
|
||||
entityType: 'StorageContainer',
|
||||
entityId: id,
|
||||
action: 'UPDATE',
|
||||
userId: actingUserId,
|
||||
beforeData: before,
|
||||
afterData: container,
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
async findAllStockItems(): Promise<StockItem[]> {
|
||||
return this.prisma.stockItem.findMany({ orderBy: { name: 'asc' } });
|
||||
}
|
||||
@@ -66,6 +94,27 @@ export class StorageService {
|
||||
return stockItem;
|
||||
}
|
||||
|
||||
async updateStockItem(
|
||||
id: string,
|
||||
dto: UpdateStockItemDto,
|
||||
actingUserId: string,
|
||||
): Promise<StockItem> {
|
||||
const before = await this.findStockItemById(id);
|
||||
const stockItem = await this.prisma.stockItem.update({
|
||||
where: { id },
|
||||
data: { ...dto },
|
||||
});
|
||||
await this.auditLog.record({
|
||||
entityType: 'StockItem',
|
||||
entityId: id,
|
||||
action: 'UPDATE',
|
||||
userId: actingUserId,
|
||||
beforeData: before,
|
||||
afterData: stockItem,
|
||||
});
|
||||
return stockItem;
|
||||
}
|
||||
|
||||
async addMovement(
|
||||
id: string,
|
||||
dto: CreateStockMovementDto,
|
||||
|
||||
Reference in new issue
Block a user