Fix admin settings save 400 and remove JSON socials editor.
Send only whitelisted fields and let operators edit social links as simple label/url rows. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import { Body, Controller, Get, Param, Put, UseGuards } from "@nestjs/common";
|
||||
import { ContentService } from "./content.service";
|
||||
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
||||
import { IsObject, IsOptional, IsString } from "class-validator";
|
||||
import { IsArray, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
|
||||
class SocialDto {
|
||||
@IsString()
|
||||
label!: string;
|
||||
|
||||
@IsString()
|
||||
url!: string;
|
||||
}
|
||||
|
||||
class UpdateSettingsDto {
|
||||
@IsOptional() @IsString() brandName?: string;
|
||||
@@ -10,8 +19,12 @@ class UpdateSettingsDto {
|
||||
@IsOptional() @IsString() phone?: string;
|
||||
@IsOptional() @IsString() address?: string;
|
||||
@IsOptional() @IsString() timezone?: string;
|
||||
@IsOptional() socials?: object;
|
||||
@IsOptional() @IsString() logoUrl?: string;
|
||||
@IsOptional() @IsString() logoUrl?: string | null;
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => SocialDto)
|
||||
socials?: SocialDto[];
|
||||
}
|
||||
|
||||
class UpsertSectionDto {
|
||||
|
||||
@@ -19,7 +19,14 @@ export class ContentService {
|
||||
socials?: object;
|
||||
logoUrl?: string | null;
|
||||
}) {
|
||||
return this.prisma.siteSettings.update({ where: { id: "default" }, data });
|
||||
const { logoUrl, ...rest } = data;
|
||||
return this.prisma.siteSettings.update({
|
||||
where: { id: "default" },
|
||||
data: {
|
||||
...rest,
|
||||
...(logoUrl !== undefined ? { logoUrl: logoUrl || null } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async listSections() {
|
||||
|
||||
Reference in New Issue
Block a user