Files
accounted/app/api/settings/booking-templates/[id]/touch/route.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

39 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
/**
* POST /api/settings/booking-templates/[id]/touch
*
* Record that this template was applied by the current company. Upserts the
* (template_id, company_id) row in booking_template_usage, refreshing
* last_used_at. Used by the template pickers to drive MRU ordering.
*
* Fire-and-forget from the client: errors are non-fatal.
*/
export const POST = withRouteContext<{ params: Promise<{ id: string }> }>(
'booking_template.touch',
async (_request, ctx, { params }) => {
const { id } = await params
const { supabase, companyId } = ctx
const { error } = await supabase
.from('booking_template_usage')
.upsert(
{
template_id: id,
company_id: companyId,
last_used_at: new Date().toISOString(),
},
{ onConflict: 'template_id,company_id' },
)
if (error) {
return NextResponse.json({ error: getUserErrorMessage(error) }, { status: 500 })
}
return NextResponse.json({ data: { success: true } })
},
{ requireWrite: true },
)