RELEASE V.4.0.0 : VERSION LONG SUPPORT (LTS)
--> Imports de ligne via fichier GTFS --> Extrapolation possible des données --> Générateur de fiches horaires
This commit is contained in:
1 parent
37ab831aac
commit
1c68740e41
25 files changed
+13372
-535
No files matched your search
@@ -0,0 +1,128 @@
|
||||
import supabase from '../supabaseClient';
|
||||
|
||||
function applyRegionFilter(query, regionId) {
|
||||
if (!regionId) return query;
|
||||
return query.eq('region_id', regionId);
|
||||
}
|
||||
|
||||
export async function getAllInfosSillons(regionId = null) {
|
||||
try {
|
||||
const query = applyRegionFilter(
|
||||
supabase.from('infos_sillons').select('*').order('created_at', { ascending: false }),
|
||||
regionId
|
||||
);
|
||||
const { data, error } = await query;
|
||||
if (error) {
|
||||
console.error('[API InfosSillons] getAllInfosSillons error:', error);
|
||||
return { data: null, error };
|
||||
}
|
||||
return { data: data || [], error: null };
|
||||
} catch (err) {
|
||||
console.error('[API InfosSillons] getAllInfosSillons exception:', err);
|
||||
return { data: null, error: { message: 'Erreur lors du chargement des infos sillons' } };
|
||||
}
|
||||
}
|
||||
|
||||
export async function createInfoSillon(infoData) {
|
||||
const sanitized = {
|
||||
titre: infoData.titre?.trim() || '',
|
||||
description: infoData.description || null,
|
||||
type: infoData.type || 'information',
|
||||
ligne_id: infoData.ligne_id || null,
|
||||
ligne_nom: infoData.ligne_nom || null,
|
||||
travaux_id: infoData.travaux_id || null,
|
||||
date_debut: infoData.date_debut || null,
|
||||
date_fin: infoData.date_fin || null,
|
||||
actif: infoData.actif !== false,
|
||||
auto_generated: infoData.auto_generated === true,
|
||||
region_id: infoData.region_id || null
|
||||
};
|
||||
|
||||
if (!sanitized.titre) {
|
||||
return { data: null, error: { message: 'Le titre est requis' } };
|
||||
}
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('infos_sillons')
|
||||
.insert(sanitized)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
console.error('[API InfosSillons] createInfoSillon error:', error);
|
||||
return { data: null, error };
|
||||
}
|
||||
return { data, error: null };
|
||||
} catch (err) {
|
||||
console.error('[API InfosSillons] createInfoSillon exception:', err);
|
||||
return { data: null, error: { message: 'Erreur lors de la création' } };
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateInfoSillon(id, infoData) {
|
||||
if (!id) return { data: null, error: { message: 'ID manquant' } };
|
||||
|
||||
const sanitized = {
|
||||
titre: infoData.titre?.trim() || '',
|
||||
description: infoData.description || null,
|
||||
type: infoData.type || 'information',
|
||||
ligne_id: infoData.ligne_id || null,
|
||||
ligne_nom: infoData.ligne_nom || null,
|
||||
travaux_id: infoData.travaux_id || null,
|
||||
date_debut: infoData.date_debut || null,
|
||||
date_fin: infoData.date_fin || null,
|
||||
actif: infoData.actif !== false,
|
||||
auto_generated: infoData.auto_generated === true,
|
||||
region_id: infoData.region_id || null
|
||||
};
|
||||
|
||||
if (!sanitized.titre) {
|
||||
return { data: null, error: { message: 'Le titre est requis' } };
|
||||
}
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('infos_sillons')
|
||||
.update(sanitized)
|
||||
.eq('id', id)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
console.error('[API InfosSillons] updateInfoSillon error:', error);
|
||||
return { data: null, error };
|
||||
}
|
||||
return { data, error: null };
|
||||
} catch (err) {
|
||||
console.error('[API InfosSillons] updateInfoSillon exception:', err);
|
||||
return { data: null, error: { message: 'Erreur lors de la mise à jour' } };
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteInfoSillon(id) {
|
||||
if (!id) return { data: null, error: { message: 'ID manquant' } };
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('infos_sillons')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
.select('id')
|
||||
.maybeSingle();
|
||||
|
||||
if (error) {
|
||||
console.error('[API InfosSillons] deleteInfoSillon error:', error);
|
||||
return { data: null, error };
|
||||
}
|
||||
|
||||
if (!data?.id) {
|
||||
return { data: null, error: { message: 'Suppression impossible: élément introuvable.' } };
|
||||
}
|
||||
|
||||
return { data: { id: data.id, deleted: true }, error: null };
|
||||
} catch (err) {
|
||||
console.error('[API InfosSillons] deleteInfoSillon exception:', err);
|
||||
return { data: null, error: { message: 'Erreur lors de la suppression' } };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user