fix: alinhamento fixo de agendamentos por data real no modo semana da agenda
Build and Deploy (Gitea Actions) / build-and-deploy (push) Failing after 45s
Details
Build and Deploy (Gitea Actions) / build-and-deploy (push) Failing after 45s
Details
This commit is contained in:
parent
8ce7a4340e
commit
99bfca0072
|
|
@ -6,6 +6,10 @@ export async function GET(req: NextRequest) {
|
||||||
const { searchParams } = new URL(req.url);
|
const { searchParams } = new URL(req.url);
|
||||||
const slug = searchParams.get('slug');
|
const slug = searchParams.get('slug');
|
||||||
|
|
||||||
|
const dateParam = searchParams.get('date');
|
||||||
|
const startDateParam = searchParams.get('startDate');
|
||||||
|
const endDateParam = searchParams.get('endDate');
|
||||||
|
|
||||||
if (!slug) {
|
if (!slug) {
|
||||||
return NextResponse.json({ error: 'Missing tenant slug' }, { status: 400 });
|
return NextResponse.json({ error: 'Missing tenant slug' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
@ -17,10 +21,21 @@ export async function GET(req: NextRequest) {
|
||||||
|
|
||||||
const profsRes = await query(`SELECT id, name FROM users WHERE tenant_id = $1 AND role = 'professional'`, [tenantId]);
|
const profsRes = await query(`SELECT id, name FROM users WHERE tenant_id = $1 AND role = 'professional'`, [tenantId]);
|
||||||
|
|
||||||
// In PostgreSQL, DATE columns return as Date objects or strings depending on driver. Let's cast to text.
|
let dateWhereClause = '';
|
||||||
|
const queryParams: any[] = [tenantId];
|
||||||
|
|
||||||
|
if (startDateParam && endDateParam) {
|
||||||
|
queryParams.push(startDateParam, endDateParam);
|
||||||
|
dateWhereClause = `AND a.date >= $2 AND a.date <= $3`;
|
||||||
|
} else if (dateParam) {
|
||||||
|
queryParams.push(dateParam);
|
||||||
|
dateWhereClause = `AND a.date = $2`;
|
||||||
|
}
|
||||||
|
|
||||||
const apptsRes = await query(`
|
const apptsRes = await query(`
|
||||||
SELECT
|
SELECT
|
||||||
a.id, a.professional_id as "professionalId",
|
a.id, a.professional_id as "professionalId",
|
||||||
|
TO_CHAR(a.date, 'YYYY-MM-DD') as date,
|
||||||
COALESCE(c.name, a.client_name, 'Cliente Avulso') as client,
|
COALESCE(c.name, a.client_name, 'Cliente Avulso') as client,
|
||||||
COALESCE(s.name, 'Serviço Personalizado') as service,
|
COALESCE(s.name, 'Serviço Personalizado') as service,
|
||||||
EXTRACT(HOUR FROM a.start_time) as "startHour",
|
EXTRACT(HOUR FROM a.start_time) as "startHour",
|
||||||
|
|
@ -30,8 +45,9 @@ export async function GET(req: NextRequest) {
|
||||||
FROM appointments a
|
FROM appointments a
|
||||||
LEFT JOIN clients c ON a.client_id = c.id
|
LEFT JOIN clients c ON a.client_id = c.id
|
||||||
LEFT JOIN services s ON a.service_id = s.id
|
LEFT JOIN services s ON a.service_id = s.id
|
||||||
WHERE a.tenant_id = $1 AND a.date = CURRENT_DATE
|
WHERE a.tenant_id = $1 ${dateWhereClause}
|
||||||
`, [tenantId]);
|
ORDER BY a.date ASC, a.start_time ASC
|
||||||
|
`, queryParams);
|
||||||
|
|
||||||
const colors = ['#6C63FF', '#a855f7', '#10b981', '#f59e0b', '#ef4444'];
|
const colors = ['#6C63FF', '#a855f7', '#10b981', '#f59e0b', '#ef4444'];
|
||||||
const professionals = profsRes.rows.map((p, i) => ({
|
const professionals = profsRes.rows.map((p, i) => ({
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,11 @@ export default function Agenda() {
|
||||||
const fetchAgenda = async () => {
|
const fetchAgenda = async () => {
|
||||||
try {
|
try {
|
||||||
const slug = localStorage.getItem('agendapro_tenant_slug') || 'barbearia-premium';
|
const slug = localStorage.getItem('agendapro_tenant_slug') || 'barbearia-premium';
|
||||||
|
const startOfWeekStr = weekDays[0].toISOString().split('T')[0];
|
||||||
|
const endOfWeekStr = weekDays[6].toISOString().split('T')[0];
|
||||||
|
|
||||||
const [agendaRes, servicesRes] = await Promise.all([
|
const [agendaRes, servicesRes] = await Promise.all([
|
||||||
fetch(`/api/tenant/agenda?slug=${slug}`),
|
fetch(`/api/tenant/agenda?slug=${slug}&startDate=${startOfWeekStr}&endDate=${endOfWeekStr}`),
|
||||||
fetch(`/api/tenant/services?slug=${slug}`)
|
fetch(`/api/tenant/services?slug=${slug}`)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -210,7 +213,8 @@ export default function Agenda() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{professionals.map(prof => {
|
{professionals.map(prof => {
|
||||||
const visibleAppointments = appointments.filter(a => a.professionalId === prof.id);
|
const selectedDateStr = currentDate.toISOString().split('T')[0];
|
||||||
|
const visibleAppointments = appointments.filter(a => a.professionalId === prof.id && (a.date === selectedDateStr || !a.date));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={prof.id} style={{ position: 'relative', borderRight: '1px solid var(--border-color)' }}>
|
<div key={prof.id} style={{ position: 'relative', borderRight: '1px solid var(--border-color)' }}>
|
||||||
|
|
@ -290,9 +294,7 @@ export default function Agenda() {
|
||||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(7, minmax(140px, 1fr))', minHeight: '380px' }}>
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(7, minmax(140px, 1fr))', minHeight: '380px' }}>
|
||||||
{weekDays.map(day => {
|
{weekDays.map(day => {
|
||||||
const dayStr = day.toISOString().split('T')[0];
|
const dayStr = day.toISOString().split('T')[0];
|
||||||
// Para homologação estática, os agendamentos do dia ativo usam a data selecionada
|
const dayApts = appointments.filter(a => a.date === dayStr);
|
||||||
const isSelected = day.toDateString() === currentDate.toDateString();
|
|
||||||
const dayApts = isSelected ? appointments : [];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={day.toISOString()} style={{ padding: '10px', borderRight: '1px solid var(--border-color)', background: 'var(--bg-primary)' }}>
|
<div key={day.toISOString()} style={{ padding: '10px', borderRight: '1px solid var(--border-color)', background: 'var(--bg-primary)' }}>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue