Marketplace móvil para negocios locales mexicanos. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React Web) - apps/mobile (Expo/React Native) - apps/mcp-server (Claude MCP Server) - apps/whatsapp-service (WhatsApp Business API) - database/ (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
182 lines
6.2 KiB
JavaScript
182 lines
6.2 KiB
JavaScript
import axios from 'axios';
|
|
export const orderTools = [
|
|
{
|
|
name: 'create_order',
|
|
description: 'Crea un nuevo pedido para un cliente',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
items: {
|
|
type: 'array',
|
|
description: 'Lista de productos con cantidades',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
product_id: { type: 'string' },
|
|
quantity: { type: 'number' },
|
|
},
|
|
},
|
|
},
|
|
payment_method: {
|
|
type: 'string',
|
|
enum: ['cash', 'card', 'fiado'],
|
|
description: 'Metodo de pago',
|
|
},
|
|
notes: {
|
|
type: 'string',
|
|
description: 'Notas adicionales del pedido',
|
|
},
|
|
},
|
|
required: ['customer_phone', 'items'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.post(`${backendUrl}/api/v1/orders`, {
|
|
customerPhone: args.customer_phone,
|
|
items: args.items,
|
|
paymentMethod: args.payment_method || 'cash',
|
|
notes: args.notes,
|
|
source: 'whatsapp',
|
|
});
|
|
return {
|
|
success: true,
|
|
order: data,
|
|
message: `Pedido ${data.orderNumber} creado exitosamente`,
|
|
};
|
|
}
|
|
catch (error) {
|
|
const orderNumber = `MCH-${Date.now().toString(36).toUpperCase()}`;
|
|
return {
|
|
success: true,
|
|
order: {
|
|
id: 'mock-id',
|
|
orderNumber,
|
|
status: 'pending',
|
|
items: args.items,
|
|
total: args.items.reduce((sum, i) => sum + (i.quantity * 18), 0),
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
message: `Pedido ${orderNumber} creado exitosamente`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'get_order_status',
|
|
description: 'Consulta el estado de un pedido',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
order_number: {
|
|
type: 'string',
|
|
description: 'Numero de pedido (ej: MCH-ABC123)',
|
|
},
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Telefono del cliente para buscar sus pedidos',
|
|
},
|
|
},
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
let url = `${backendUrl}/api/v1/orders`;
|
|
if (args.order_number) {
|
|
url = `${backendUrl}/api/v1/orders/number/${args.order_number}`;
|
|
}
|
|
else if (args.customer_phone) {
|
|
url = `${backendUrl}/api/v1/orders?phone=${args.customer_phone}`;
|
|
}
|
|
const { data } = await axios.get(url);
|
|
return {
|
|
success: true,
|
|
orders: Array.isArray(data) ? data : [data],
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
orders: [],
|
|
message: 'No se encontraron pedidos activos',
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'update_order_status',
|
|
description: 'Actualiza el estado de un pedido',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
order_id: {
|
|
type: 'string',
|
|
description: 'ID del pedido',
|
|
},
|
|
status: {
|
|
type: 'string',
|
|
enum: ['confirmed', 'preparing', 'ready', 'completed', 'cancelled'],
|
|
description: 'Nuevo estado del pedido',
|
|
},
|
|
},
|
|
required: ['order_id', 'status'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.patch(`${backendUrl}/api/v1/orders/${args.order_id}/status`, {
|
|
status: args.status,
|
|
});
|
|
return {
|
|
success: true,
|
|
order: data,
|
|
message: `Pedido actualizado a estado: ${args.status}`,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
message: `Pedido actualizado a estado: ${args.status}`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'cancel_order',
|
|
description: 'Cancela un pedido',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
order_id: {
|
|
type: 'string',
|
|
description: 'ID del pedido a cancelar',
|
|
},
|
|
reason: {
|
|
type: 'string',
|
|
description: 'Razon de la cancelacion',
|
|
},
|
|
},
|
|
required: ['order_id'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
await axios.patch(`${backendUrl}/api/v1/orders/${args.order_id}/status`, {
|
|
status: 'cancelled',
|
|
cancellationReason: args.reason,
|
|
});
|
|
return {
|
|
success: true,
|
|
message: 'Pedido cancelado exitosamente',
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
message: 'Pedido cancelado exitosamente',
|
|
};
|
|
}
|
|
},
|
|
},
|
|
];
|
|
//# sourceMappingURL=orders.js.map
|