chore(format): Prettier auf lead.ts anwenden

Alt-Bestand nie formatiert — isolierter Format-Lauf vor der dueFollowUps-Query.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Raffael SheikhandClaude Opus 4.8 committed 2026-06-07 12:18:25 +02:00
1 parent 7dd1f2fb20
commit 3d9b739d25
1 file changed
+59 -53
+59 -53
View File
@@ -61,11 +61,13 @@ export const leadRouter = router({
.where(eq(leadTouchpoint.leadId, l.id)) .where(eq(leadTouchpoint.leadId, l.id))
.orderBy(desc(leadTouchpoint.datum), desc(leadTouchpoint.createdAt)); .orderBy(desc(leadTouchpoint.datum), desc(leadTouchpoint.createdAt));
const linkedProject = l.projectId const linkedProject = l.projectId
? (await ctx.db ? ((
.select({ id: project.id, name: project.name }) await ctx.db
.from(project) .select({ id: project.id, name: project.name })
.where(eq(project.id, l.projectId)) .from(project)
.limit(1))[0] ?? null .where(eq(project.id, l.projectId))
.limit(1)
)[0] ?? null)
: null; : null;
return { return {
lead: l, lead: l,
@@ -75,58 +77,55 @@ export const leadRouter = router({
}; };
}), }),
create: protectedProcedure create: protectedProcedure.input(LeadSchemas.createLeadInput).mutation(async ({ ctx, input }) => {
.input(LeadSchemas.createLeadInput) const areaId = await getSalesAreaId(ctx.db);
.mutation(async ({ ctx, input }) => { const [created] = await ctx.db
const areaId = await getSalesAreaId(ctx.db); .insert(lead)
const [created] = await ctx.db .values({
.insert(lead) areaId,
.values({ firma: input.firma,
areaId, status: input.status,
firma: input.firma, score: input.score,
status: input.status, ownerUserId: input.ownerUserId ?? null,
score: input.score, projectId: input.projectId ?? null,
ownerUserId: input.ownerUserId ?? null, branche: input.branche ?? null,
projectId: input.projectId ?? null, subSegment: input.subSegment ?? null,
branche: input.branche ?? null, website: input.website ?? null,
subSegment: input.subSegment ?? null, quelle: input.quelle ?? null,
website: input.website ?? null, createdBy: ctx.user.id,
quelle: input.quelle ?? null, })
createdBy: ctx.user.id, .returning();
}) if (!created) throw new Error('Lead konnte nicht angelegt werden.');
.returning(); return created;
if (!created) throw new Error('Lead konnte nicht angelegt werden.'); }),
return created;
}),
update: protectedProcedure update: protectedProcedure.input(LeadSchemas.updateLeadInput).mutation(async ({ ctx, input }) => {
.input(LeadSchemas.updateLeadInput) const { id, ...patch } = input;
.mutation(async ({ ctx, input }) => { if (Object.keys(patch).length === 0) {
const { id, ...patch } = input; const existing = (await ctx.db.select().from(lead).where(eq(lead.id, id)).limit(1))[0];
if (Object.keys(patch).length === 0) { if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
const existing = (await ctx.db.select().from(lead).where(eq(lead.id, id)).limit(1))[0]; return existing;
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' }); }
return existing; const [updated] = await ctx.db
} .update(lead)
const [updated] = await ctx.db .set({ ...patch, updatedAt: new Date() })
.update(lead) .where(eq(lead.id, id))
.set({ ...patch, updatedAt: new Date() }) .returning();
.where(eq(lead.id, id)) if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' });
.returning(); return updated;
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Lead nicht gefunden.' }); }),
return updated;
}),
// Kontaktpersonen ----------------------------------------------------------- // Kontaktpersonen -----------------------------------------------------------
addContact: protectedProcedure addContact: protectedProcedure
.input(LeadSchemas.addContactInput) .input(LeadSchemas.addContactInput)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
const count = ( const count =
await ctx.db (
.select({ c: sql<number>`count(*)::int` }) await ctx.db
.from(leadContact) .select({ c: sql<number>`count(*)::int` })
.where(eq(leadContact.leadId, input.leadId)) .from(leadContact)
)[0]?.c ?? 0; .where(eq(leadContact.leadId, input.leadId))
)[0]?.c ?? 0;
const [created] = await ctx.db const [created] = await ctx.db
.insert(leadContact) .insert(leadContact)
.values({ .values({
@@ -222,7 +221,13 @@ export const leadRouter = router({
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
const areaId = await getSalesAreaId(ctx.db); const areaId = await getSalesAreaId(ctx.db);
const rows = parseCsv(input.csv); const rows = parseCsv(input.csv);
const summary = { created: 0, skippedEmpty: 0, skippedDuplicate: 0, contacts: 0, touchpoints: 0 }; const summary = {
created: 0,
skippedEmpty: 0,
skippedDuplicate: 0,
contacts: 0,
touchpoints: 0,
};
if (rows.length < 2 || !rows[0]) return summary; if (rows.length < 2 || !rows[0]) return summary;
const header = rows[0].map(normalizeHeader); const header = rows[0].map(normalizeHeader);
@@ -243,7 +248,8 @@ export const leadRouter = router({
branche: col('branche'), branche: col('branche'),
notizen: col('notizen'), notizen: col('notizen'),
}; };
const get = (row: string[], i: number) => (i >= 0 && i < row.length ? (row[i] ?? '').trim() : ''); const get = (row: string[], i: number) =>
i >= 0 && i < row.length ? (row[i] ?? '').trim() : '';
const existing = await ctx.db.select({ firma: lead.firma }).from(lead); const existing = await ctx.db.select({ firma: lead.firma }).from(lead);
const seen = new Set(existing.map((e) => e.firma.trim().toLowerCase())); const seen = new Set(existing.map((e) => e.firma.trim().toLowerCase()));