feat: complete settings sync, standard UI inputs, prescriptions flow, pet profile and checkout enhancements
Deploy Canina / deploy (push) Failing after 51s

This commit is contained in:
parsa aghaei committed 2026-08-17 11:46:49 +03:30
1 parent b3c60a1a7d
commit 6df92f03d7
32 files changed
+61750 -59151

No files matched your search

+10
View File
@@ -36,6 +36,16 @@ export class PetsService {
mobile: true,
},
},
medicalConditions: true,
reminders: true,
healthLogs: {
orderBy: { createdAt: 'desc' },
take: 10,
},
prescriptions: {
orderBy: { createdAt: 'desc' },
take: 5,
},
},
}),
this.prisma.pet.count({ where }),
@@ -2,11 +2,12 @@ import { Module } from '@nestjs/common';
import { PrescriptionsController } from './prescriptions.controller';
import { PrescriptionsService } from './prescriptions.service';
import { PrismaModule } from '../prisma/prisma.module';
import { SmsService } from '../common/services/sms.service';
@Module({
imports: [PrismaModule],
controllers: [PrescriptionsController],
providers: [PrescriptionsService],
providers: [PrescriptionsService, SmsService],
exports: [PrescriptionsService],
})
export class PrescriptionsModule {}
@@ -2,18 +2,29 @@ import {
Injectable,
NotFoundException,
ForbiddenException,
Logger,
} from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { SmsService } from '../common/services/sms.service';
@Injectable()
export class PrescriptionsService {
constructor(private prisma: PrismaService) {}
private readonly logger = new Logger(PrescriptionsService.name);
constructor(
private prisma: PrismaService,
private smsService: SmsService,
) {}
async create(
userId: string | null,
data: {
petId?: string;
petName?: string;
petType?: string;
petBreed?: string;
petAge?: number;
petWeight?: number;
phone?: string;
fileUrl: string;
notes?: string;
@@ -30,7 +41,6 @@ export class PrescriptionsService {
});
if (!user) {
// Create user with default role Customer
user = await this.prisma.user.create({
data: {
mobile: cleanPhone,
@@ -57,10 +67,10 @@ export class PrescriptionsService {
data: {
userId: user.id,
name: cleanPetName,
type: 'سگ', // Default pet type for prescription consultation
breed: 'نامشخص',
age: 1,
weight: 5.0,
type: data.petType || 'سگ',
breed: data.petBreed || 'نامشخص',
age: data.petAge !== undefined ? data.petAge : 0,
weight: data.petWeight !== undefined ? data.petWeight : 0,
activityLevel: 'متوسط',
},
});
@@ -119,11 +129,15 @@ export class PrescriptionsService {
adminNotes?: string;
},
) {
const item = await this.prisma.prescription.findUnique({ where: { id } });
const item = await this.prisma.prescription.findUnique({
where: { id },
include: { user: true, pet: true },
});
if (!item) {
throw new NotFoundException(`Prescription with ID ${id} not found`);
}
return this.prisma.prescription.update({
const updated = await this.prisma.prescription.update({
where: { id },
data: {
status: reviewData.status,
@@ -131,5 +145,18 @@ export class PrescriptionsService {
},
include: { user: true, pet: true },
});
// Send SMS notification if prescription was reviewed/approved and user has mobile
if (item.user?.mobile && reviewData.status === 'APPROVED') {
const petTitle = item.pet?.name ? ` برای «${item.pet.name}»` : '';
const smsText = `کنینا: نسخه پزشکی شما${petTitle} توسط تیم تخصصی بررسی و تایید شد. جهت مشاهده تجویز پزشک و سفارش مکمل‌ها به پنل کاربری خود در canina.ir مراجعه کنید.`;
try {
await this.smsService.sendSms(item.user.mobile, smsText);
} catch (smsErr) {
this.logger.warn(`Failed to send prescription SMS to ${item.user.mobile}:`, smsErr);
}
}
return updated;
}
}
+19 -2
View File
@@ -126,12 +126,29 @@ export class ProductsService {
}
async findOne(idOrSlug: string, userRole?: string) {
if (!idOrSlug) return null;
const decoded = decodeURIComponent(idOrSlug).trim();
const cleanId = idOrSlug.trim();
const isUuid =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(
idOrSlug,
cleanId,
);
const product = await this.prisma.product.findFirst({
where: isUuid ? { id: idOrSlug } : { slug: idOrSlug },
where: isUuid
? { id: cleanId }
: {
OR: [
{ slug: cleanId },
{ slug: decoded },
{ artNo: cleanId },
{ artNo: decoded },
{ nameFa: cleanId },
{ nameFa: decoded },
{ nameEn: cleanId },
{ nameEn: decoded },
],
},
include: {
ingredientList: true,
symptoms: true,
+40 -16
View File
@@ -300,6 +300,24 @@ export class SettingsService implements OnModuleInit {
}
async getCategorySetting(category: string) {
if (category === 'system') {
const texts = await this.getUiTexts();
const map = new Map<string, string>();
texts.forEach((t) => map.set(t.key, t.value));
const isMaintenance = map.get('MAINTENANCE_MODE') === 'true' || map.get('maintenance_mode') === 'true' || map.get('maintenanceMode') === 'true';
const allowGuestCheckout = map.get('allowGuestCheckout') !== 'false';
const b2bRegistrationOpen = map.get('b2bRegistrationOpen') !== 'false' && map.get('b2b_enabled') !== 'false';
const supportPhone = map.get('CONTACT_PHONE') || map.get('contact_phone') || map.get('supportPhone') || '۰۲۱-۸۸۸۸۴۴۴۴';
return {
maintenanceMode: isMaintenance,
allowGuestCheckout,
b2bRegistrationOpen,
supportPhone,
};
}
const setting = await this.prisma.setting.findFirst({
where: { category },
});
@@ -317,23 +335,29 @@ export class SettingsService implements OnModuleInit {
// If system config is updated, also sync individual keys into uiText for fast & reliable lookup
if (category === 'system' && typeof value === 'object' && value !== null) {
const obj = value as Record<string, any>;
const promises: Promise<any>[] = [];
if ('b2bRegistrationOpen' in obj) {
const valStr = String(obj.b2bRegistrationOpen);
promises.push(
this.prisma.uiText.upsert({
where: { key: 'b2bRegistrationOpen' },
update: { value: valStr },
create: { key: 'b2bRegistrationOpen', value: valStr },
}),
this.prisma.uiText.upsert({
where: { key: 'b2b_enabled' },
update: { value: valStr },
create: { key: 'b2b_enabled', value: valStr },
}),
);
const updates: Record<string, string> = {};
if ('maintenanceMode' in obj) {
const valStr = String(Boolean(obj.maintenanceMode));
updates['MAINTENANCE_MODE'] = valStr;
updates['maintenance_mode'] = valStr;
updates['maintenanceMode'] = valStr;
}
await Promise.all(promises);
if ('supportPhone' in obj) {
updates['CONTACT_PHONE'] = String(obj.supportPhone);
updates['contact_phone'] = String(obj.supportPhone);
updates['supportPhone'] = String(obj.supportPhone);
}
if ('b2bRegistrationOpen' in obj) {
const valStr = String(Boolean(obj.b2bRegistrationOpen));
updates['b2bRegistrationOpen'] = valStr;
updates['b2b_enabled'] = valStr;
}
if ('allowGuestCheckout' in obj) {
updates['allowGuestCheckout'] = String(Boolean(obj.allowGuestCheckout));
}
await this.updateBulkUiTexts(updates);
}
return res;