This commit is contained in:
Bivekich
2025-07-28 13:19:28 +03:00
18 changed files with 1561 additions and 538 deletions

View File

@ -1,4 +1,4 @@
import { gql } from 'graphql-tag'
import { gql } from "graphql-tag";
export const GET_ME = gql`
query GetMe {
@ -49,7 +49,7 @@ export const GET_ME = gql`
}
}
}
`
`;
export const GET_MY_SERVICES = gql`
query GetMyServices {
@ -63,7 +63,7 @@ export const GET_MY_SERVICES = gql`
updatedAt
}
}
`
`;
export const GET_MY_SUPPLIES = gql`
query GetMySupplies {
@ -85,7 +85,7 @@ export const GET_MY_SUPPLIES = gql`
updatedAt
}
}
`
`;
export const GET_MY_LOGISTICS = gql`
query GetMyLogistics {
@ -100,7 +100,7 @@ export const GET_MY_LOGISTICS = gql`
updatedAt
}
}
`
`;
export const GET_MY_PRODUCTS = gql`
query GetMyProducts {
@ -129,7 +129,41 @@ export const GET_MY_PRODUCTS = gql`
updatedAt
}
}
`
`;
export const GET_WAREHOUSE_PRODUCTS = gql`
query GetWarehouseProducts {
warehouseProducts {
id
name
article
description
price
quantity
type
category {
id
name
}
brand
color
size
weight
dimensions
material
images
mainImage
isActive
organization {
id
name
fullName
}
createdAt
updatedAt
}
}
`;
// Запросы для контрагентов
export const SEARCH_ORGANIZATIONS = gql`
@ -155,7 +189,7 @@ export const SEARCH_ORGANIZATIONS = gql`
}
}
}
`
`;
export const GET_MY_COUNTERPARTIES = gql`
query GetMyCounterparties {
@ -177,7 +211,7 @@ export const GET_MY_COUNTERPARTIES = gql`
}
}
}
`
`;
export const GET_SUPPLY_SUPPLIERS = gql`
query GetSupplySuppliers {
@ -193,7 +227,7 @@ export const GET_SUPPLY_SUPPLIERS = gql`
createdAt
}
}
`
`;
export const GET_ORGANIZATION_LOGISTICS = gql`
query GetOrganizationLogistics($organizationId: ID!) {
@ -206,7 +240,7 @@ export const GET_ORGANIZATION_LOGISTICS = gql`
description
}
}
`
`;
export const GET_INCOMING_REQUESTS = gql`
query GetIncomingRequests {
@ -243,7 +277,7 @@ export const GET_INCOMING_REQUESTS = gql`
}
}
}
`
`;
export const GET_OUTGOING_REQUESTS = gql`
query GetOutgoingRequests {
@ -280,7 +314,7 @@ export const GET_OUTGOING_REQUESTS = gql`
}
}
}
`
`;
export const GET_ORGANIZATION = gql`
query GetOrganization($id: ID!) {
@ -304,7 +338,7 @@ export const GET_ORGANIZATION = gql`
updatedAt
}
}
`
`;
// Запросы для сообщений
export const GET_MESSAGES = gql`
@ -347,7 +381,7 @@ export const GET_MESSAGES = gql`
updatedAt
}
}
`
`;
export const GET_CONVERSATIONS = gql`
query GetConversations {
@ -384,7 +418,7 @@ export const GET_CONVERSATIONS = gql`
updatedAt
}
}
`
`;
export const GET_CATEGORIES = gql`
query GetCategories {
@ -395,7 +429,7 @@ export const GET_CATEGORIES = gql`
updatedAt
}
}
`
`;
export const GET_ALL_PRODUCTS = gql`
query GetAllProducts($search: String, $category: String) {
@ -438,7 +472,7 @@ export const GET_ALL_PRODUCTS = gql`
}
}
}
`
`;
export const GET_MY_CART = gql`
query GetMyCart {
@ -492,7 +526,7 @@ export const GET_MY_CART = gql`
updatedAt
}
}
`
`;
export const GET_MY_FAVORITES = gql`
query GetMyFavorites {
@ -532,7 +566,7 @@ export const GET_MY_FAVORITES = gql`
}
}
}
`
`;
// Запросы для сотрудников
export const GET_MY_EMPLOYEES = gql`
@ -565,7 +599,7 @@ export const GET_MY_EMPLOYEES = gql`
updatedAt
}
}
`
`;
export const GET_EMPLOYEE = gql`
query GetEmployee($id: ID!) {
@ -594,7 +628,7 @@ export const GET_EMPLOYEE = gql`
updatedAt
}
}
`
`;
export const GET_EMPLOYEE_SCHEDULE = gql`
query GetEmployeeSchedule($employeeId: ID!, $year: Int!, $month: Int!) {
@ -609,7 +643,7 @@ export const GET_EMPLOYEE_SCHEDULE = gql`
}
}
}
`
`;
export const GET_MY_WILDBERRIES_SUPPLIES = gql`
query GetMyWildberriesSupplies {
@ -640,7 +674,7 @@ export const GET_MY_WILDBERRIES_SUPPLIES = gql`
}
}
}
`
`;
// Запросы для получения услуг и расходников от конкретных организаций-контрагентов
export const GET_COUNTERPARTY_SERVICES = gql`
@ -655,7 +689,7 @@ export const GET_COUNTERPARTY_SERVICES = gql`
updatedAt
}
}
`
`;
export const GET_COUNTERPARTY_SUPPLIES = gql`
query GetCounterpartySupplies($organizationId: ID!) {
@ -673,12 +707,20 @@ export const GET_COUNTERPARTY_SUPPLIES = gql`
updatedAt
}
}
`
`;
// Wildberries запросы
export const GET_WILDBERRIES_STATISTICS = gql`
query GetWildberriesStatistics($period: String, $startDate: String, $endDate: String) {
getWildberriesStatistics(period: $period, startDate: $startDate, endDate: $endDate) {
query GetWildberriesStatistics(
$period: String
$startDate: String
$endDate: String
) {
getWildberriesStatistics(
period: $period
startDate: $startDate
endDate: $endDate
) {
success
message
data {
@ -693,7 +735,7 @@ export const GET_WILDBERRIES_STATISTICS = gql`
}
}
}
`
`;
export const GET_WILDBERRIES_CAMPAIGN_STATS = gql`
query GetWildberriesCampaignStats($input: WildberriesCampaignStatsInput!) {
@ -764,7 +806,7 @@ export const GET_WILDBERRIES_CAMPAIGN_STATS = gql`
}
}
}
`
`;
export const GET_WILDBERRIES_CAMPAIGNS_LIST = gql`
query GetWildberriesCampaignsList {
@ -800,7 +842,7 @@ export const ADMIN_ME = gql`
updatedAt
}
}
`
`;
export const ALL_USERS = gql`
query AllUsers($search: String, $limit: Int, $offset: Int) {
@ -826,7 +868,7 @@ export const ALL_USERS = gql`
hasMore
}
}
`
`;
export const GET_SUPPLY_ORDERS = gql`
query GetSupplyOrders {
@ -889,4 +931,4 @@ export const GET_PENDING_SUPPLIES_COUNT = gql`
total
}
}
`;
`;

View File

@ -789,13 +789,25 @@ export const resolvers = {
throw new GraphQLError("У пользователя нет организации");
}
// Считаем заказы поставок со статусом PENDING где мы поставщики или получатели
// Считаем заказы поставок, требующие действий
const pendingSupplyOrders = await prisma.supplyOrder.count({
where: {
status: "PENDING",
OR: [
{ partnerId: currentUser.organization.id }, // Заказы где мы - поставщик (нужно подтвердить)
{ fulfillmentCenterId: currentUser.organization.id }, // Заказы где мы - получатель ФФ (нужно подтвердить)
// Заказы со статусом PENDING где мы - поставщик (нужно подтвердить)
{
status: "PENDING",
partnerId: currentUser.organization.id,
},
// Заказы со статусом PENDING где мы - получатель ФФ (нужно подтвердить)
{
status: "PENDING",
fulfillmentCenterId: currentUser.organization.id,
},
// Заказы со статусом IN_TRANSIT где мы - получатель ФФ (нужно подтвердить получение)
{
status: "IN_TRANSIT",
fulfillmentCenterId: currentUser.organization.id,
},
],
},
});
@ -902,6 +914,108 @@ export const resolvers = {
});
},
// Товары на складе фулфилмента (из доставленных заказов поставок)
warehouseProducts: async (_: unknown, __: unknown, 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("У пользователя нет организации");
}
// Проверяем, что это фулфилмент центр
if (currentUser.organization.type !== "FULFILLMENT") {
throw new GraphQLError(
"Товары склада доступны только для фулфилмент центров"
);
}
// Получаем все доставленные заказы поставок, где этот фулфилмент центр является получателем
const deliveredSupplyOrders = await prisma.supplyOrder.findMany({
where: {
fulfillmentCenterId: currentUser.organization.id,
status: "DELIVERED", // Только доставленные заказы
},
include: {
items: {
include: {
product: {
include: {
category: true,
organization: true, // Включаем информацию о поставщике
},
},
},
},
organization: true, // Селлер, который сделал заказ
partner: true, // Поставщик товаров
},
});
// Собираем все товары из доставленных заказов
const allProducts: any[] = [];
console.log("🔍 Резолвер warehouseProducts (доставленные заказы):", {
currentUserId: currentUser.id,
organizationId: currentUser.organization.id,
organizationType: currentUser.organization.type,
deliveredOrdersCount: deliveredSupplyOrders.length,
orders: deliveredSupplyOrders.map((order) => ({
id: order.id,
sellerName: order.organization.name || order.organization.fullName,
supplierName: order.partner.name || order.partner.fullName,
status: order.status,
itemsCount: order.items.length,
deliveryDate: order.deliveryDate,
})),
});
for (const order of deliveredSupplyOrders) {
console.log(
`📦 Заказ от селлера ${order.organization.name} у поставщика ${order.partner.name}:`,
order.items.map((item) => ({
productId: item.product.id,
productName: item.product.name,
article: item.product.article,
orderedQuantity: item.quantity,
price: item.price,
}))
);
for (const item of order.items) {
// Добавляем товар на склад с информацией о заказе
allProducts.push({
...item.product,
// Дополнительная информация о заказе
orderedQuantity: item.quantity,
orderedPrice: item.price,
orderId: order.id,
orderDate: order.deliveryDate,
seller: order.organization, // Селлер, который заказал
supplier: order.partner, // Поставщик товара
// Для совместимости с существующим интерфейсом
organization: order.organization, // Указываем селлера как владельца
});
}
}
console.log(
"✅ Итого товаров на складе фулфилмента (из доставленных заказов):",
allProducts.length
);
return allProducts;
},
// Все товары всех поставщиков для маркета
allProducts: async (
_: unknown,
@ -3386,7 +3500,7 @@ export const resolvers = {
price: product.price,
quantity: item.quantity,
unit: "шт",
category: productWithCategory?.category?.name || "Упаковка",
category: productWithCategory?.category?.name || "Расходники",
status: "in-transit", // Статус "в пути" так как заказ только создан
date: new Date(args.input.deliveryDate),
supplier: partner.name || partner.fullName || "Не указан",
@ -4866,7 +4980,7 @@ export const resolvers = {
price: item.price,
quantity: item.quantity,
unit: "шт",
category: item.product.category?.name || "Упаковка",
category: item.product.category?.name || "Расходники",
status: "available",
date: new Date(),
supplier:

View File

@ -55,6 +55,9 @@ export const typeDefs = gql`
# Товары поставщика
myProducts: [Product!]!
# Товары на складе фулфилмента
warehouseProducts: [Product!]!
# Все товары всех поставщиков для маркета
allProducts(search: String, category: String): [Product!]!