Add country mapping support for imports and geographic map
- Add normalizeCountryToCode utility to convert country names to ISO-2 codes - Support English, French and common alternate spellings - Update Typeform import to support country field mapping - Update Notion import to support country field mapping - Allow project.update to set/update country with automatic normalization - Fix geographic distribution map showing empty when country data exists Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
notifyProjectTeam,
|
||||
NotificationTypes,
|
||||
} from '../services/in-app-notification'
|
||||
import { normalizeCountryToCode } from '@/lib/countries'
|
||||
|
||||
export const projectRouter = router({
|
||||
/**
|
||||
@@ -324,6 +325,7 @@ export const projectRouter = router({
|
||||
title: z.string().min(1).max(500).optional(),
|
||||
teamName: z.string().optional().nullable(),
|
||||
description: z.string().optional().nullable(),
|
||||
country: z.string().optional().nullable(), // ISO-2 code or country name (will be normalized)
|
||||
// Status update requires roundId
|
||||
roundId: z.string().optional(),
|
||||
status: z
|
||||
@@ -341,13 +343,19 @@ export const projectRouter = router({
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { id, metadataJson, status, roundId, ...data } = input
|
||||
const { id, metadataJson, status, roundId, country, ...data } = input
|
||||
|
||||
// Normalize country to ISO-2 code if provided
|
||||
const normalizedCountry = country !== undefined
|
||||
? (country === null ? null : normalizeCountryToCode(country))
|
||||
: undefined
|
||||
|
||||
const project = await ctx.prisma.project.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...data,
|
||||
...(status && { status }),
|
||||
...(normalizedCountry !== undefined && { country: normalizedCountry }),
|
||||
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user