almeira-web/seed_appwrite_initial.js

291 lines
9.0 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { Client, Databases, ID, Query } = require('./node_modules/node-appwrite');
const client = new Client()
.setEndpoint('https://appwrite.almeira.com.co/v1')
.setProject('69b84df5003bd8957c5c')
.setKey('standard_cce3cdb866ea6433888d40cedd24dc45987372308fdc3dd0697de08648c0e5c7e04b02c3bcee271403fd656b00a5820f04c08b51631284a6e8a3582d8aed2aa33234f3c29cc777e9b162eb54810b789251b0d006a9a3b081ebc2da53b9baa94614b124b3508ad849fd9a4187cc6094f506d4b57f409b69d9562a74df594f3ec3');
const dbs = new Databases(client);
const DB_ID = 'sneakers_multistore_db';
const INITIAL_CITIES = [
{
id: 'city-cali',
name: 'Cali',
department: 'Valle del Cauca',
shippingCost: 0,
deliveryTime: 'Entrega en 24 Horas (Domicilio Local)',
allowsContraentrega: true,
firstExchangeFree: true,
exchangePolicyNote: '1er Cambio de Talla 100% GRATIS en Cali (posteriores con flete estándar)',
isActive: true
},
{
id: 'city-jamundi',
name: 'Jamundí',
department: 'Valle del Cauca',
shippingCost: 5000,
deliveryTime: 'Entrega en 24 Horas',
allowsContraentrega: true,
firstExchangeFree: true,
exchangePolicyNote: '1er Cambio de Talla 100% GRATIS en Jamundí (posteriores con flete estándar)',
isActive: true
},
{
id: 'city-palmira',
name: 'Palmira',
department: 'Valle del Cauca',
shippingCost: 7000,
deliveryTime: 'Entrega en 24 Horas',
allowsContraentrega: true,
firstExchangeFree: true,
exchangePolicyNote: '1er Cambio de Talla 100% GRATIS en Palmira (posteriores con flete estándar)',
isActive: true
},
{
id: 'city-yumbo',
name: 'Yumbo',
department: 'Valle del Cauca',
shippingCost: 5000,
deliveryTime: 'Entrega en 24 Horas',
allowsContraentrega: true,
firstExchangeFree: true,
exchangePolicyNote: '1er Cambio de Talla 100% GRATIS en Yumbo (posteriores con flete estándar)',
isActive: true
},
{
id: 'city-bogota',
name: 'Bogotá D.C.',
department: 'Cundinamarca',
shippingCost: 12000,
deliveryTime: '2 a 3 días hábiles',
allowsContraentrega: true,
firstExchangeFree: false,
exchangePolicyNote: 'Cambio de talla garantizado (flete logístico asumido por el cliente)',
isActive: true
},
{
id: 'city-medellin',
name: 'Medellín',
department: 'Antioquia',
shippingCost: 12000,
deliveryTime: '2 a 3 días hábiles',
allowsContraentrega: true,
firstExchangeFree: false,
exchangePolicyNote: 'Cambio de talla garantizado (flete logístico asumido por el cliente)',
isActive: true
},
{
id: 'city-barranquilla',
name: 'Barranquilla',
department: 'Atlántico',
shippingCost: 14000,
deliveryTime: '3 a 4 días hábiles',
allowsContraentrega: true,
firstExchangeFree: false,
exchangePolicyNote: 'Cambio de talla garantizado (flete logístico asumido por el cliente)',
isActive: true
},
{
id: 'city-nacional',
name: 'Otras Ciudades / Resto del País',
department: 'Colombia',
shippingCost: 15000,
deliveryTime: '2 a 5 días hábiles',
allowsContraentrega: false,
firstExchangeFree: false,
exchangePolicyNote: 'Cambio de talla garantizado (flete nacional asumido por el cliente)',
isActive: true
},
];
const INITIAL_PAYMENT_METHODS = [
{
id: 'pay-bold-link',
name: 'Bold.co • PSE, Tarjetas Débito/Crédito, Nequi o QR (Oficial)',
type: 'bold',
description: 'Paga de forma rápida y 100% segura con tu cuenta Bold. Acepta PSE, Tarjetas Visa/Mastercard y QR de cualquier banco.',
requiresDeposit: false,
depositAmount: 0,
boldPaymentLink: 'https://bold.co/p/carlos-lasso',
accountInfo: 'Pasarela Oficial Bold.co • PSE / Tarjetas / QR',
isActive: true,
},
{
id: 'pay-deposit-10k',
name: 'Separación con $10.000 + Saldo Contraentrega',
type: 'contraentrega',
description: 'Asegura tu talla con solo $10.000 COP vía Bold/Nequi/Daviplata y cancelas el saldo restante en efectivo o transferencia cuando el mensajero llegue a tu casa.',
requiresDeposit: true,
depositAmount: 10000,
accountInfo: 'Nequi / Daviplata Oficial: 316 745 5877 (Carlos Andrés Lasso)',
boldPaymentLink: 'https://bold.co/p/carlos-lasso',
isActive: true,
},
{
id: 'pay-cod-full',
name: 'Pago 100% Contraentrega (Cali y Alrededores)',
type: 'contraentrega',
description: 'Pagas el 100% del valor total al recibir en tu puerta (válido para entregas urbanas en 24 horas).',
requiresDeposit: false,
depositAmount: 0,
accountInfo: '',
boldPaymentLink: '',
isActive: true,
},
{
id: 'pay-nequi-full',
name: 'Transferencia Total Anticipada Nequi / Daviplata',
type: 'nequi',
description: 'Paga el 100% anticipado y recibe prioridad de despacho express en 24 horas.',
requiresDeposit: false,
depositAmount: 0,
accountInfo: 'Nequi / Daviplata: 316 745 5877 (Carlos Andrés Lasso)',
boldPaymentLink: '',
isActive: true,
},
];
const INITIAL_SUPPLIERS = [
{
id: 'sup-jovic',
name: '💎 2️⃣ DIFUSIÓN JOVIC STORE COLOMBIA🍀',
phone: '573167455877',
contactPerson: 'Asesor Jovic Store',
address: 'Centro / Bodega Cali',
notes: 'Proveedor oficial Nike, Jordan, Nocta y Vomero calidades Top.',
isActive: true
},
{
id: 'sup-ccmio',
name: 'EXCLUSIVE CC MÍO 3B',
phone: '573159876543',
contactPerson: 'Despachos CC MÍO 3B',
address: 'CC MÍO Local 3B, Cali',
notes: 'Especialista en Adidas, Coach, Timberland y Skatewear.',
isActive: true
},
{
id: 'sup-central',
name: 'BODEGA CENTRAL MAYORISTA',
phone: '573101234567',
contactPerson: 'Logística Despachos',
address: 'San Andresito / Cali',
notes: 'Despacho rápido en 24 horas para separación inmediata.',
isActive: true
}
];
const INITIAL_SETTINGS = {
storeName: 'DripZone',
slogan: 'Luxury Streetwear & Collectibles',
email: 'carlos.andres.lasso@gmail.com',
phone: '3167455877',
whatsappNumber: '573167455877',
instagramHandle: '@dripzone.co',
address: 'Bodega Central / Cali',
city: 'Cali, Colombia',
nequiAccount: '316 745 5877',
daviplataAccount: '316 745 5877',
accountHolder: 'Carlos Andrés Lasso',
boldPaymentLink: 'https://bold.co/p/carlos-lasso',
boldApiKey: '',
boldMerchantId: '',
boldQrUrl: '',
boldEnabled: true,
defaultProfitMargin: 35,
defaultDepositAmount: 10000,
};
async function seed() {
console.log('Seeding Appwrite database...');
// 1. Cities
console.log('Seeding cities...');
for (const c of INITIAL_CITIES) {
try {
await dbs.createDocument(DB_ID, 'cities', c.id, {
name: c.name,
department: c.department,
shippingCost: c.shippingCost,
deliveryTime: c.deliveryTime,
allowsContraentrega: c.allowsContraentrega,
firstExchangeFree: c.firstExchangeFree,
exchangePolicyNote: c.exchangePolicyNote,
isActive: c.isActive,
});
console.log(` + City ${c.name} (${c.id}) created.`);
} catch (e) {
if (e.code === 409) {
console.log(` . City ${c.id} already exists.`);
} else {
console.warn(` ! Error city ${c.id}:`, e.message);
}
}
}
// 2. Payment methods
console.log('Seeding payment methods...');
for (const pm of INITIAL_PAYMENT_METHODS) {
try {
await dbs.createDocument(DB_ID, 'payment_methods', pm.id, {
name: pm.name,
type: pm.type,
description: pm.description,
requiresDeposit: pm.requiresDeposit,
depositAmount: pm.depositAmount,
accountInfo: pm.accountInfo || '',
boldPaymentLink: pm.boldPaymentLink || '',
boldQrUrl: '',
isActive: pm.isActive,
});
console.log(` + Payment Method ${pm.name} (${pm.id}) created.`);
} catch (e) {
if (e.code === 409) {
console.log(` . Payment Method ${pm.id} already exists.`);
} else {
console.warn(` ! Error PM ${pm.id}:`, e.message);
}
}
}
// 3. Suppliers
console.log('Seeding suppliers...');
for (const s of INITIAL_SUPPLIERS) {
try {
await dbs.createDocument(DB_ID, 'suppliers', s.id, {
name: s.name,
phone: s.phone,
contactPerson: s.contactPerson || '',
address: s.address || '',
notes: s.notes || '',
isActive: s.isActive,
});
console.log(` + Supplier ${s.name} created.`);
} catch (e) {
if (e.code === 409) {
console.log(` . Supplier ${s.id} already exists.`);
} else {
console.warn(` ! Error supplier ${s.id}:`, e.message);
}
}
}
// 4. Store settings
console.log('Seeding store settings...');
try {
await dbs.createDocument(DB_ID, 'store_settings', 'main_settings', INITIAL_SETTINGS);
console.log(' + Main store settings created.');
} catch (e) {
if (e.code === 409) {
console.log(' . Main store settings already exists.');
} else {
console.warn(' ! Error settings:', e.message);
}
}
console.log('🎉 Seeding complete!');
}
seed().catch(console.error);