fix(seed): return numeric IDs from media upload helpers
Payload 3 + PostgreSQL rejects string IDs for upload field relationships; helpers were returning String(doc.id) which caused ValidationError on every location/post create that referenced an already-existing media record. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b2e03d1311
commit
958de340c1
1 changed files with 6 additions and 6 deletions
|
|
@ -16,7 +16,7 @@ async function uploadMedia(
|
|||
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||
filename: string,
|
||||
alt: string
|
||||
) {
|
||||
): Promise<number | null> {
|
||||
const filePath = path.join(process.cwd(), 'public/images/figma', filename)
|
||||
if (!fs.existsSync(filePath)) return null
|
||||
try {
|
||||
|
|
@ -27,7 +27,7 @@ async function uploadMedia(
|
|||
file: { data: buffer, mimetype: getMimeType(filename), name: filename, size: buffer.length },
|
||||
overrideAccess: true,
|
||||
})
|
||||
return String(doc.id)
|
||||
return doc.id as number
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ async function findOrUploadMedia(
|
|||
filename: string,
|
||||
localPath: string,
|
||||
alt?: string
|
||||
): Promise<string | null> {
|
||||
): Promise<number | null> {
|
||||
try {
|
||||
const existing = await payload.find({
|
||||
collection: 'media',
|
||||
|
|
@ -47,7 +47,7 @@ async function findOrUploadMedia(
|
|||
limit: 1,
|
||||
overrideAccess: true,
|
||||
})
|
||||
if (existing.docs.length > 0) return String(existing.docs[0]!.id)
|
||||
if (existing.docs.length > 0) return existing.docs[0]!.id as number
|
||||
const fullPath = path.resolve(process.cwd(), localPath)
|
||||
if (!fs.existsSync(fullPath)) return null
|
||||
const buffer = fs.readFileSync(fullPath)
|
||||
|
|
@ -57,7 +57,7 @@ async function findOrUploadMedia(
|
|||
file: { data: buffer, mimetype: getMimeType(filename), name: filename, size: buffer.length },
|
||||
overrideAccess: true,
|
||||
})
|
||||
return String(doc.id)
|
||||
return doc.id as number
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
|
@ -417,7 +417,7 @@ export async function POST(req: NextRequest) {
|
|||
},
|
||||
gallery: {
|
||||
images: galleryMediaIds
|
||||
.filter((id): id is string => !!id)
|
||||
.filter((id): id is number => !!id)
|
||||
.map((id, i) => ({ image: id, alt: `Шуміленд фото ${i + 1}` })),
|
||||
},
|
||||
video: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue