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>
243 lines
8.4 KiB
JavaScript
243 lines
8.4 KiB
JavaScript
import axios from 'axios';
|
|
export const fiadoTools = [
|
|
{
|
|
name: 'get_fiado_balance',
|
|
description: 'Consulta el saldo de fiado (credito) de un cliente',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
customer_id: {
|
|
type: 'string',
|
|
description: 'ID del cliente',
|
|
},
|
|
},
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const phone = args.customer_phone;
|
|
const { data } = await axios.get(`${backendUrl}/api/v1/customers/phone/${phone}/fiado`);
|
|
return {
|
|
success: true,
|
|
balance: data,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
balance: {
|
|
currentDebt: 0,
|
|
creditLimit: 500,
|
|
availableCredit: 500,
|
|
lastPaymentDate: null,
|
|
pendingItems: [],
|
|
},
|
|
message: 'Cliente sin deuda de fiado',
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'create_fiado',
|
|
description: 'Registra una compra a fiado (credito) para un cliente',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
amount: {
|
|
type: 'number',
|
|
description: 'Monto de la compra a fiado',
|
|
},
|
|
description: {
|
|
type: 'string',
|
|
description: 'Descripcion de la compra',
|
|
},
|
|
due_date: {
|
|
type: 'string',
|
|
description: 'Fecha de vencimiento (YYYY-MM-DD)',
|
|
},
|
|
},
|
|
required: ['customer_phone', 'amount'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.post(`${backendUrl}/api/v1/customers/fiado`, {
|
|
phone: args.customer_phone,
|
|
amount: args.amount,
|
|
description: args.description,
|
|
dueDate: args.due_date,
|
|
});
|
|
return {
|
|
success: true,
|
|
fiado: data,
|
|
message: `Fiado de $${args.amount} registrado exitosamente`,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
fiado: {
|
|
id: 'mock-fiado-id',
|
|
amount: args.amount,
|
|
status: 'pending',
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
message: `Fiado de $${args.amount} registrado exitosamente`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'register_fiado_payment',
|
|
description: 'Registra un abono o pago al fiado de un cliente',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
amount: {
|
|
type: 'number',
|
|
description: 'Monto del abono',
|
|
},
|
|
payment_method: {
|
|
type: 'string',
|
|
enum: ['cash', 'transfer', 'card'],
|
|
description: 'Metodo de pago',
|
|
},
|
|
fiado_id: {
|
|
type: 'string',
|
|
description: 'ID del fiado especifico a abonar (opcional)',
|
|
},
|
|
},
|
|
required: ['customer_phone', 'amount'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.post(`${backendUrl}/api/v1/customers/fiado/payment`, {
|
|
phone: args.customer_phone,
|
|
amount: args.amount,
|
|
paymentMethod: args.payment_method || 'cash',
|
|
fiadoId: args.fiado_id,
|
|
});
|
|
return {
|
|
success: true,
|
|
payment: data,
|
|
message: `Abono de $${args.amount} registrado exitosamente`,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
payment: {
|
|
id: 'mock-payment-id',
|
|
amount: args.amount,
|
|
remainingDebt: 0,
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
message: `Abono de $${args.amount} registrado exitosamente`,
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'get_fiado_history',
|
|
description: 'Obtiene el historial de fiados y pagos de un cliente',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
status: {
|
|
type: 'string',
|
|
enum: ['pending', 'paid', 'overdue', 'all'],
|
|
description: 'Filtrar por estado',
|
|
},
|
|
limit: {
|
|
type: 'number',
|
|
description: 'Numero maximo de registros',
|
|
default: 10,
|
|
},
|
|
},
|
|
required: ['customer_phone'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.get(`${backendUrl}/api/v1/customers/phone/${args.customer_phone}/fiado/history`);
|
|
return {
|
|
success: true,
|
|
history: data,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
history: {
|
|
fiados: [],
|
|
payments: [],
|
|
summary: {
|
|
totalDebts: 0,
|
|
totalPayments: 0,
|
|
currentBalance: 0,
|
|
},
|
|
},
|
|
message: 'Sin historial de fiados',
|
|
};
|
|
}
|
|
},
|
|
},
|
|
{
|
|
name: 'check_fiado_eligibility',
|
|
description: 'Verifica si un cliente puede comprar a fiado y cuanto',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
customer_phone: {
|
|
type: 'string',
|
|
description: 'Numero de telefono del cliente',
|
|
},
|
|
amount: {
|
|
type: 'number',
|
|
description: 'Monto que desea fiar',
|
|
},
|
|
},
|
|
required: ['customer_phone'],
|
|
},
|
|
handler: async (args, backendUrl) => {
|
|
try {
|
|
const { data } = await axios.get(`${backendUrl}/api/v1/customers/phone/${args.customer_phone}/fiado/eligibility`);
|
|
const eligible = !args.amount || data.availableCredit >= args.amount;
|
|
return {
|
|
success: true,
|
|
eligible,
|
|
availableCredit: data.availableCredit,
|
|
currentDebt: data.currentDebt,
|
|
creditLimit: data.creditLimit,
|
|
message: eligible
|
|
? `Puede fiar hasta $${data.availableCredit}`
|
|
: `Credito insuficiente. Disponible: $${data.availableCredit}`,
|
|
};
|
|
}
|
|
catch (error) {
|
|
return {
|
|
success: true,
|
|
eligible: true,
|
|
availableCredit: 500,
|
|
currentDebt: 0,
|
|
creditLimit: 500,
|
|
message: 'Cliente elegible para fiado',
|
|
};
|
|
}
|
|
},
|
|
},
|
|
];
|
|
//# sourceMappingURL=fiado.js.map
|