feat: add parent_business_id to link activities to businesses
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
import { supabase } from '@/supabase'
|
import { supabase } from '@/supabase'
|
||||||
import type { Business } from '@/types'
|
import type { Business } from '@/types'
|
||||||
|
|
||||||
const SELECT_FIELDS = 'id, name, address, phone, image_url, social_media, category, latitude, longitude, area, description, website, supplier_name, supplier_description, schedule, whatsapp, instagram, facebook, gallery_images, updated_at, is_featured'
|
const SELECT_FIELDS = 'id, name, address, phone, image_url, social_media, category, latitude, longitude, area, description, website, supplier_name, supplier_description, schedule, whatsapp, instagram, facebook, gallery_images, updated_at, is_featured, parent_business_id'
|
||||||
|
|
||||||
export const businessService = {
|
export const businessService = {
|
||||||
/** Helper to upload file to supabase storage */
|
/** Helper to upload file to supabase storage */
|
||||||
@ -43,12 +43,14 @@ export const businessService = {
|
|||||||
} else if (key === 'gallery_images' && typeof value === 'string') {
|
} else if (key === 'gallery_images' && typeof value === 'string') {
|
||||||
// Comes as JSON string from the form
|
// Comes as JSON string from the form
|
||||||
try { payload[key] = JSON.parse(value) } catch { /* ignore */ }
|
try { payload[key] = JSON.parse(value) } catch { /* ignore */ }
|
||||||
} else if (value !== 'null' && value !== '' && key !== 'file' && key !== 'image') {
|
} else if (key !== 'file' && key !== 'image') {
|
||||||
if (value === 'true') {
|
if (value === 'null') {
|
||||||
|
payload[key] = null
|
||||||
|
} else if (value === 'true') {
|
||||||
payload[key] = true
|
payload[key] = true
|
||||||
} else if (value === 'false') {
|
} else if (value === 'false') {
|
||||||
payload[key] = false
|
payload[key] = false
|
||||||
} else {
|
} else if (value !== '') {
|
||||||
payload[key] = value
|
payload[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,6 +103,7 @@ export interface Business {
|
|||||||
supplier_name?: string | null // Name of the business/operator
|
supplier_name?: string | null // Name of the business/operator
|
||||||
supplier_description?: string | null // Info about the business/operator
|
supplier_description?: string | null // Info about the business/operator
|
||||||
is_featured?: boolean // To show on Map
|
is_featured?: boolean // To show on Map
|
||||||
|
parent_business_id?: string | null // Link to parent company/business
|
||||||
// Template/Mold fields
|
// Template/Mold fields
|
||||||
schedule?: string | null // "Lun-Sáb 8am-10pm"
|
schedule?: string | null // "Lun-Sáb 8am-10pm"
|
||||||
whatsapp?: string | null // WhatsApp number
|
whatsapp?: string | null // WhatsApp number
|
||||||
|
|||||||
@ -10,7 +10,8 @@ const route = useRoute();
|
|||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const isEditing = ref(false);
|
const isEditing = ref(false);
|
||||||
const showMessage = ref({ text: '', type: '' });
|
const showMessage = ref({ text: '', type: '' as 'success' | 'error' | '' });
|
||||||
|
const parentOptions = ref<any[]>([]);
|
||||||
|
|
||||||
const selectedFile = ref<File | null>(null);
|
const selectedFile = ref<File | null>(null);
|
||||||
const selectedFileName = ref('');
|
const selectedFileName = ref('');
|
||||||
@ -32,17 +33,23 @@ const businessForm = ref<Partial<Business>>({
|
|||||||
website: '',
|
website: '',
|
||||||
schedule: '',
|
schedule: '',
|
||||||
whatsapp: '',
|
whatsapp: '',
|
||||||
instagram: '',
|
|
||||||
facebook: '',
|
facebook: '',
|
||||||
supplier_name: '',
|
supplier_name: '',
|
||||||
supplier_description: '',
|
supplier_description: '',
|
||||||
is_featured: false,
|
is_featured: false,
|
||||||
|
parent_business_id: null,
|
||||||
gallery_images: []
|
gallery_images: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const previewImageUrl = ref('https://images.unsplash.com/photo-1555396273-367ea4eb4db5?q=80&w=2074&auto=format&fit=crop');
|
const previewImageUrl = ref('https://images.unsplash.com/photo-1555396273-367ea4eb4db5?q=80&w=2074&auto=format&fit=crop');
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const allBiz = await businessService.getAllBusinesses();
|
||||||
|
const routeId = route.params.id as string;
|
||||||
|
parentOptions.value = allBiz.filter(b => b.id !== routeId);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
const id = route.params.id as string;
|
const id = route.params.id as string;
|
||||||
if (id && id !== 'new') {
|
if (id && id !== 'new') {
|
||||||
isEditing.value = true;
|
isEditing.value = true;
|
||||||
@ -120,12 +127,16 @@ async function saveBusiness() {
|
|||||||
formData.append('schedule', businessForm.value.schedule || '');
|
formData.append('schedule', businessForm.value.schedule || '');
|
||||||
formData.append('whatsapp', businessForm.value.whatsapp || '');
|
formData.append('whatsapp', businessForm.value.whatsapp || '');
|
||||||
formData.append('instagram', businessForm.value.instagram || '');
|
formData.append('instagram', businessForm.value.instagram || '');
|
||||||
formData.append('facebook', businessForm.value.facebook || '');
|
|
||||||
formData.append('supplier_name', businessForm.value.supplier_name || '');
|
formData.append('supplier_name', businessForm.value.supplier_name || '');
|
||||||
formData.append('supplier_description', businessForm.value.supplier_description || '');
|
formData.append('supplier_description', businessForm.value.supplier_description || '');
|
||||||
formData.append('is_featured', String(businessForm.value.is_featured === true));
|
formData.append('is_featured', String(businessForm.value.is_featured === true));
|
||||||
|
|
||||||
|
|
||||||
|
if (businessForm.value.parent_business_id) {
|
||||||
|
formData.append('parent_business_id', businessForm.value.parent_business_id);
|
||||||
|
} else {
|
||||||
|
formData.append('parent_business_id', 'null');
|
||||||
|
}
|
||||||
|
|
||||||
if (businessForm.value.gallery_images?.length) {
|
if (businessForm.value.gallery_images?.length) {
|
||||||
formData.append('gallery_images', JSON.stringify(businessForm.value.gallery_images));
|
formData.append('gallery_images', JSON.stringify(businessForm.value.gallery_images));
|
||||||
}
|
}
|
||||||
@ -272,6 +283,17 @@ const catEmoji = computed(() => CATEGORY_EMOJI[businessForm.value.category || ''
|
|||||||
|
|
||||||
<div class="form-section-label mt-4">Detalles del Proveedor / Operador</div>
|
<div class="form-section-label mt-4">Detalles del Proveedor / Operador</div>
|
||||||
|
|
||||||
|
<div class="form-group" style="margin-top: 12px;">
|
||||||
|
<label>Empresa Matriz / Local Asociado (Opcional)</label>
|
||||||
|
<select v-model="businessForm.parent_business_id" class="nexus-select">
|
||||||
|
<option :value="null">-- Ninguna (Es un registro independiente o es una Empresa Matriz) --</option>
|
||||||
|
<option v-for="biz in parentOptions" :key="biz.id" :value="biz.id">
|
||||||
|
{{ biz.name }} ({{ biz.category }})
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<p style="font-size: 0.75rem; color: #94a3b8; margin-top: 4px;">Útil si estás creando una 'Actividad' que pertenece a un 'Restaurante' o 'Local' existente en SIBU.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group grid-row" style="margin-top: 12px;">
|
<div class="form-group grid-row" style="margin-top: 12px;">
|
||||||
<div class="input-box">
|
<div class="input-box">
|
||||||
<label>Nombre del Operador / Empresa</label>
|
<label>Nombre del Operador / Empresa</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user