Добавлен новый компонент для отображения бизнес-процессов в интерфейсе управления. Обновлен компонент UIKitSection для интеграции нового демо и улучшения навигации. Оптимизирована логика отображения данных и улучшена читаемость кода. Исправлены текстовые метки для повышения удобства использования.
This commit is contained in:
@ -398,14 +398,18 @@ export const resolvers = {
|
||||
|
||||
const suppliers = await prisma.supplySupplier.findMany({
|
||||
where: { organizationId: currentUser.organization.id },
|
||||
orderBy: { createdAt: 'desc' }
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return suppliers;
|
||||
},
|
||||
|
||||
// Логистика конкретной организации
|
||||
organizationLogistics: async (_: unknown, args: { organizationId: string }, context: Context) => {
|
||||
organizationLogistics: async (
|
||||
_: unknown,
|
||||
args: { organizationId: string },
|
||||
context: Context
|
||||
) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError("Требуется авторизация", {
|
||||
extensions: { code: "UNAUTHENTICATED" },
|
||||
@ -3259,38 +3263,38 @@ export const resolvers = {
|
||||
totalItems: totalItems,
|
||||
organizationId: currentUser.organization.id,
|
||||
fulfillmentCenterId: fulfillmentCenterId,
|
||||
status: initialStatus as any,
|
||||
status: initialStatus,
|
||||
items: {
|
||||
create: orderItems,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
partner: {
|
||||
include: {
|
||||
users: true,
|
||||
include: {
|
||||
partner: {
|
||||
include: {
|
||||
users: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
organization: {
|
||||
include: {
|
||||
users: true,
|
||||
organization: {
|
||||
include: {
|
||||
users: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
fulfillmentCenter: {
|
||||
include: {
|
||||
users: true,
|
||||
fulfillmentCenter: {
|
||||
include: {
|
||||
users: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
items: {
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
category: true,
|
||||
organization: true,
|
||||
items: {
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
category: true,
|
||||
organization: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Создаем расходники на основе заказанных товаров
|
||||
@ -4643,6 +4647,182 @@ export const resolvers = {
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
// Обновить статус заказа поставки
|
||||
updateSupplyOrderStatus: async (
|
||||
_: unknown,
|
||||
args: {
|
||||
id: string;
|
||||
status:
|
||||
| "PENDING"
|
||||
| "CONFIRMED"
|
||||
| "IN_TRANSIT"
|
||||
| "DELIVERED"
|
||||
| "CANCELLED";
|
||||
},
|
||||
context: Context
|
||||
) => {
|
||||
if (!context.user) {
|
||||
throw new GraphQLError("Требуется авторизация", {
|
||||
extensions: { code: "UNAUTHENTICATED" },
|
||||
});
|
||||
}
|
||||
|
||||
const currentUser = await prisma.user.findUnique({
|
||||
where: { id: context.user.id },
|
||||
include: { organization: true },
|
||||
});
|
||||
|
||||
if (!currentUser?.organization) {
|
||||
throw new GraphQLError("У пользователя нет организации");
|
||||
}
|
||||
|
||||
try {
|
||||
// Находим заказ поставки
|
||||
const existingOrder = await prisma.supplyOrder.findFirst({
|
||||
where: {
|
||||
id: args.id,
|
||||
OR: [
|
||||
{ organizationId: currentUser.organization.id }, // Создатель заказа
|
||||
{ partnerId: currentUser.organization.id }, // Поставщик
|
||||
{ fulfillmentCenterId: currentUser.organization.id }, // Фулфилмент-центр
|
||||
],
|
||||
},
|
||||
include: {
|
||||
items: {
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
category: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
partner: true,
|
||||
fulfillmentCenter: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!existingOrder) {
|
||||
throw new GraphQLError("Заказ поставки не найден или нет доступа");
|
||||
}
|
||||
|
||||
// Обновляем статус заказа
|
||||
const updatedOrder = await prisma.supplyOrder.update({
|
||||
where: { id: args.id },
|
||||
data: { status: args.status },
|
||||
include: {
|
||||
partner: true,
|
||||
items: {
|
||||
include: {
|
||||
product: {
|
||||
include: {
|
||||
category: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Если статус изменился на DELIVERED, обновляем склад фулфилмента
|
||||
if (args.status === "DELIVERED" && existingOrder.fulfillmentCenterId) {
|
||||
console.log("🚚 Обновляем склад фулфилмента:", {
|
||||
fulfillmentCenterId: existingOrder.fulfillmentCenterId,
|
||||
itemsCount: existingOrder.items.length,
|
||||
items: existingOrder.items.map((item) => ({
|
||||
productName: item.product.name,
|
||||
quantity: item.quantity,
|
||||
})),
|
||||
});
|
||||
|
||||
// Обновляем расходники фулфилмента
|
||||
for (const item of existingOrder.items) {
|
||||
console.log("📦 Обрабатываем товар:", {
|
||||
productName: item.product.name,
|
||||
quantity: item.quantity,
|
||||
fulfillmentCenterId: existingOrder.fulfillmentCenterId,
|
||||
});
|
||||
|
||||
// Ищем существующий расходник
|
||||
const existingSupply = await prisma.supply.findFirst({
|
||||
where: {
|
||||
name: item.product.name,
|
||||
organizationId: existingOrder.fulfillmentCenterId,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("🔍 Найден существующий расходник:", !!existingSupply);
|
||||
|
||||
if (existingSupply) {
|
||||
console.log("📈 Обновляем существующий расходник:", {
|
||||
id: existingSupply.id,
|
||||
oldStock: existingSupply.currentStock,
|
||||
newStock: existingSupply.currentStock + item.quantity,
|
||||
});
|
||||
|
||||
// Обновляем количество существующего расходника
|
||||
await prisma.supply.update({
|
||||
where: { id: existingSupply.id },
|
||||
data: {
|
||||
currentStock: existingSupply.currentStock + item.quantity,
|
||||
status: "available", // Меняем статус на "доступен"
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log("➕ Создаем новый расходник:", {
|
||||
name: item.product.name,
|
||||
quantity: item.quantity,
|
||||
organizationId: existingOrder.fulfillmentCenterId,
|
||||
});
|
||||
|
||||
// Создаем новый расходник
|
||||
const newSupply = await prisma.supply.create({
|
||||
data: {
|
||||
name: item.product.name,
|
||||
description:
|
||||
item.product.description ||
|
||||
`Поставка от ${existingOrder.partner.name}`,
|
||||
price: item.price,
|
||||
quantity: item.quantity,
|
||||
unit: "шт",
|
||||
category: item.product.category?.name || "Упаковка",
|
||||
status: "available",
|
||||
date: new Date(),
|
||||
supplier:
|
||||
existingOrder.partner.name ||
|
||||
existingOrder.partner.fullName ||
|
||||
"Не указан",
|
||||
minStock: Math.round(item.quantity * 0.1),
|
||||
currentStock: item.quantity,
|
||||
organizationId: existingOrder.fulfillmentCenterId,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("✅ Создан новый расходник:", {
|
||||
id: newSupply.id,
|
||||
name: newSupply.name,
|
||||
currentStock: newSupply.currentStock,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log("🎉 Склад фулфилмента успешно обновлен!");
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Статус заказа поставки обновлен на "${args.status}"`,
|
||||
order: updatedOrder,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error updating supply order status:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Ошибка при обновлении статуса заказа поставки",
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
// Резолверы типов
|
||||
|
Reference in New Issue
Block a user