Fix landing 500 from invalid Asia/Esfahan timezone.

Normalize Iran city aliases to Asia/Tehran, harden the clock, and make settings timezone a safe select.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-30 21:25:45 +03:30
co-authored by Cursor
parent 183ebf5e7f
commit e9eafdaabc
7 changed files with 98 additions and 12 deletions
+15 -2
View File
@@ -1,4 +1,5 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { resolveTimezone } from "@montech/shared";
import { PrismaService } from "../prisma/prisma.service";
@Injectable()
@@ -19,11 +20,12 @@ export class ContentService {
socials?: object;
logoUrl?: string | null;
}) {
const { logoUrl, ...rest } = data;
const { logoUrl, timezone, ...rest } = data;
return this.prisma.siteSettings.update({
where: { id: "default" },
data: {
...rest,
...(timezone !== undefined ? { timezone: resolveTimezone(timezone) } : {}),
...(logoUrl !== undefined ? { logoUrl: logoUrl || null } : {}),
},
});
@@ -48,11 +50,22 @@ export class ContentService {
}
async getPublicSite() {
const [settings, sections, pages] = await Promise.all([
const [settingsRaw, sections, pages] = await Promise.all([
this.getSettings(),
this.listSections(),
this.prisma.page.findMany({ include: { seo: true } }),
]);
const settings = {
...settingsRaw,
timezone: resolveTimezone(settingsRaw.timezone),
};
// heal invalid timezone stored in DB (e.g. Asia/Esfahan)
if (settingsRaw.timezone !== settings.timezone) {
await this.prisma.siteSettings.update({
where: { id: "default" },
data: { timezone: settings.timezone },
});
}
const sectionMap: Record<string, unknown> = {};
for (const s of sections) sectionMap[s.key] = s.data;
return { settings, sections: sectionMap, pages };