Fix Prisma JSON type error in settings-to-footer sync.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
import { resolveTimezone } from "@montech/shared";
|
import { resolveTimezone } from "@montech/shared";
|
||||||
import { PrismaService } from "../prisma/prisma.service";
|
import { PrismaService } from "../prisma/prisma.service";
|
||||||
|
|
||||||
@@ -36,21 +37,24 @@ export class ContentService {
|
|||||||
const prev = (footer.data || {}) as Record<string, unknown>;
|
const prev = (footer.data || {}) as Record<string, unknown>;
|
||||||
const addressLines = settings.address
|
const addressLines = settings.address
|
||||||
? settings.address.split(/\n|,/).map((s) => s.trim()).filter(Boolean)
|
? settings.address.split(/\n|,/).map((s) => s.trim()).filter(Boolean)
|
||||||
: (prev.address as string[]) || [];
|
: Array.isArray(prev.address)
|
||||||
const socials = Array.isArray(settings.socials)
|
? (prev.address as string[])
|
||||||
|
: [];
|
||||||
|
const socials: string[] = Array.isArray(settings.socials)
|
||||||
? (settings.socials as Array<{ label: string; url: string }>).map((s) => s.label).filter(Boolean)
|
? (settings.socials as Array<{ label: string; url: string }>).map((s) => s.label).filter(Boolean)
|
||||||
: prev.socials;
|
: Array.isArray(prev.socials)
|
||||||
|
? (prev.socials as string[])
|
||||||
|
: [];
|
||||||
|
const nextData: Prisma.InputJsonValue = {
|
||||||
|
...prev,
|
||||||
|
email: settings.email,
|
||||||
|
phone: settings.phone,
|
||||||
|
address: addressLines,
|
||||||
|
socials,
|
||||||
|
};
|
||||||
await this.prisma.sectionContent.update({
|
await this.prisma.sectionContent.update({
|
||||||
where: { key: "footer" },
|
where: { key: "footer" },
|
||||||
data: {
|
data: { data: nextData },
|
||||||
data: {
|
|
||||||
...prev,
|
|
||||||
email: settings.email,
|
|
||||||
phone: settings.phone,
|
|
||||||
address: addressLines,
|
|
||||||
socials,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user