diff --git a/backend/src/contact/contact.service.spec.ts b/backend/src/contact/contact.service.spec.ts
index 8bb2c859..0ad0a8c6 100644
--- a/backend/src/contact/contact.service.spec.ts
+++ b/backend/src/contact/contact.service.spec.ts
@@ -13,9 +13,8 @@ describe("ContactService", () => {
count: jest.fn(),
update: jest.fn(),
},
- contactInfo: {
+ setting: {
findMany: jest.fn(),
- upsert: jest.fn(),
},
};
@@ -82,26 +81,27 @@ describe("ContactService", () => {
});
describe("getContactInfo", () => {
- it("should return contact items if they already exist", async () => {
- const items = [
- { id: "1", key: "branch_info", title: "تلفن", value: "021" },
- ];
- mockPrisma.contactInfo.findMany.mockResolvedValue(items);
+ it("should return contact items from canonical settings", async () => {
+ mockPrisma.setting.findMany.mockResolvedValue([
+ { key: "CONTACT_PHONE", value: "021-12345678" },
+ { key: "CONTACT_EMAIL", value: "support@example.test" },
+ { key: "CONTACT_ADDRESS", value: "آدرس تنظیمشده" },
+ ]);
const result = await service.getContactInfo();
- expect(result).toEqual(items);
- expect(mockPrisma.contactInfo.upsert).not.toHaveBeenCalled();
+ expect(result).toEqual([
+ { key: "phone", title: "تلفنهای تماس", value: "021-12345678", icon: "phone", order: 1 },
+ { key: "email", title: "پست الکترونیک", value: "support@example.test", icon: "mail", order: 2 },
+ { key: "address", title: "نشانی دفتر مرکزی", value: "آدرس تنظیمشده", icon: "map-pin", order: 3 },
+ ]);
+ expect(mockPrisma.setting.findMany).toHaveBeenCalled();
});
- it("should seed default items if empty", async () => {
- mockPrisma.contactInfo.findMany
- .mockResolvedValueOnce([])
- .mockResolvedValueOnce([{ key: "branch_info" }]);
-
- const result = await service.getContactInfo();
- expect(mockPrisma.contactInfo.upsert).toHaveBeenCalledTimes(3);
- expect(result).toHaveLength(1);
+ it("does not return hardcoded contact values when settings are empty", async () => {
+ mockPrisma.setting.findMany.mockResolvedValue([]);
+ expect(await service.getContactInfo()).toEqual([]);
});
+
});
describe("getAllSubmissions", () => {
diff --git a/backend/src/contact/contact.service.ts b/backend/src/contact/contact.service.ts
index fb69a3de..785c952e 100644
--- a/backend/src/contact/contact.service.ts
+++ b/backend/src/contact/contact.service.ts
@@ -65,51 +65,20 @@ export class ContactService {
}
async getContactInfo() {
- let items = await this.prisma.contactInfo.findMany({
- orderBy: { order: "asc" },
+ const settings = await this.prisma.setting.findMany({
+ where: { key: { in: ["CONTACT_PHONE", "contact_phone", "CONTACT_EMAIL", "contact_email", "CONTACT_ADDRESS", "contact_address"] } },
+ select: { key: true, value: true },
});
-
- if (items.length === 0) {
- // Seed default items if empty
- const defaultItems = [
- {
- key: "branch_info",
- title: "اطلاعات نمایندگی",
- value:
- "تلفنهای تماس\n۰۲۱-۸۸۸۸ ۴۴۴۴\n\nشنبه تا چهارشنبه ۹:۰۰ الی ۱۸:۰۰",
- icon: "phone",
- order: 1,
- },
- {
- key: "email_info",
- title: "پست الکترونیک",
- value: "info@canina.ir\n\nپاسخگویی در کمتر از ۲۴ ساعت کاری",
- icon: "mail",
- order: 2,
- },
- {
- key: "address_info",
- title: "نشانی دفتر مرکزی",
- value: "تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹",
- icon: "map-pin",
- order: 3,
- },
- ];
-
- for (const item of defaultItems) {
- await this.prisma.contactInfo.upsert({
- where: { key: item.key },
- update: {},
- create: item,
- });
- }
-
- items = await this.prisma.contactInfo.findMany({
- orderBy: { order: "asc" },
- });
- }
-
- return items;
+ const values = new Map(settings.map((item) => [item.key, String(item.value ?? "")]));
+ const read = (...keys: string[]) => keys.map((key) => values.get(key)).find((value) => value?.trim()) || "";
+ const phone = read("CONTACT_PHONE", "contact_phone");
+ const email = read("CONTACT_EMAIL", "contact_email");
+ const address = read("CONTACT_ADDRESS", "contact_address");
+ return [
+ { key: "phone", title: "تلفنهای تماس", value: phone, icon: "phone", order: 1 },
+ { key: "email", title: "پست الکترونیک", value: email, icon: "mail", order: 2 },
+ { key: "address", title: "نشانی دفتر مرکزی", value: address, icon: "map-pin", order: 3 },
+ ].filter((item) => item.value.trim());
}
async getAllSubmissions(page = 1, limit = 20, status?: string) {
diff --git a/frontend/application/app/contact/page.tsx b/frontend/application/app/contact/page.tsx
index b26c7273..b9e24e93 100644
--- a/frontend/application/app/contact/page.tsx
+++ b/frontend/application/app/contact/page.tsx
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import ContactFormClient from "@/components/ContactFormClient";
-import { getPageMetadata } from "@/lib/seo";
+import { getPageMetadata, getSeoConfig } from "@/lib/seo";
export async function generateMetadata(): Promise {getText('shop_promo_card_desc', 'اگر نمیدانید کدام ترکیب برای پت شما مناسب است، همین حالا با دامپزشکان ما تماس بگیرید.')}{getText('shop_promo_card_title', 'مشاوره رایگان')}
- ۰۲۱-۸۸۸۸ ۴۴۴۴ -
-- شنبه تا چهارشنبه ۹:۰۰ الی ۱۸:۰۰ -
-info@canina.ir
-- پاسخگویی در کمتر از ۲۴ ساعت کاری -
-- تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹ -
-{getText('footer_address_label', "دفتر مرکزی")}
-{getText('contact_address', "تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹")}
+{getText('contact_address', '')}