ec27228a8e
Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
|
|
const CHUNK_SIZE = 500
|
|
|
|
/**
|
|
* Bulk-mark posted journal entries as "Inget underlag krävs" (no supporting
|
|
* document required) by inserting rows into journal_entry_no_doc_required.
|
|
*
|
|
* The flag lives in a sidecar table so the verifikation itself stays immutable
|
|
* per BFL: same write the single-entry route performs, just batched. Inserts
|
|
* are chunked (Postgres/PostgREST payload safety) and idempotent: rows that
|
|
* already exist are left untouched (`ignoreDuplicates`).
|
|
*
|
|
* The caller is responsible for passing only entry IDs that belong to
|
|
* `companyId` and are eligible (posted, document-requiring source type); RLS on
|
|
* the table is the security backstop. Used by the SIE-import opt-in auto-exempt
|
|
* flow and the batch-mark endpoint.
|
|
*
|
|
* @returns the number of entry IDs processed (deduped), not the number of new rows.
|
|
*/
|
|
export async function markEntriesNoDocRequired(
|
|
supabase: SupabaseClient,
|
|
companyId: string,
|
|
userId: string,
|
|
entryIds: string[],
|
|
reason: string | null,
|
|
): Promise<number> {
|
|
if (entryIds.length === 0) return 0
|
|
|
|
// De-dupe so a chunk can never carry the same id twice (ON CONFLICT target).
|
|
const uniqueIds = Array.from(new Set(entryIds))
|
|
|
|
for (let i = 0; i < uniqueIds.length; i += CHUNK_SIZE) {
|
|
const chunk = uniqueIds.slice(i, i + CHUNK_SIZE)
|
|
const rows = chunk.map((journal_entry_id) => ({
|
|
journal_entry_id,
|
|
company_id: companyId,
|
|
user_id: userId,
|
|
reason: reason ?? null,
|
|
}))
|
|
|
|
const { error } = await supabase
|
|
.from('journal_entry_no_doc_required')
|
|
.upsert(rows, { onConflict: 'journal_entry_id', ignoreDuplicates: true })
|
|
|
|
if (error) throw new Error(error.message)
|
|
}
|
|
|
|
return uniqueIds.length
|
|
}
|