تغییرات کلی در backend و frontend

This commit is contained in:
parsa aghaei committed 2026-07-11 12:30:17 +03:30
1 parent a74f4bda48
commit 3dedc89ee1
41 files changed
+2373 -1957

No files matched your search

@@ -0,0 +1,24 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsString, IsOptional } from 'class-validator';
export class CreateHealthLogDto {
@ApiProperty({ description: 'وضعیت اشتها', example: 'عالی' })
@IsNotEmpty()
@IsString()
appetite: string;
@ApiProperty({ description: 'وضعیت انرژی', example: 'نرمال' })
@IsNotEmpty()
@IsString()
energy: string;
@ApiProperty({ description: 'وضعیت گوارش', example: 'نرمال' })
@IsNotEmpty()
@IsString()
digestion: string;
@ApiPropertyOptional({ description: 'یادداشت یا توضیح اضافی', example: 'امروز فعالیت خوبی داشت.' })
@IsOptional()
@IsString()
note?: string;
}
@@ -0,0 +1,24 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsString, IsOptional } from 'class-validator';
export class CreateReminderDto {
@ApiProperty({ description: 'عنوان یادآور', example: 'قرص کلسیم' })
@IsNotEmpty()
@IsString()
title: string;
@ApiProperty({ description: 'زمان یادآور (مثال: 08:30)', example: '08:30' })
@IsNotEmpty()
@IsString()
time: string;
@ApiProperty({ description: 'دوره زمانی (روزانه / هفتگی)', example: 'روزانه' })
@IsNotEmpty()
@IsString()
frequency: string;
@ApiPropertyOptional({ description: 'شناسه محصول مربوطه', example: 'a1b2c3d4-1234-5678-abcd-ef1234567890' })
@IsOptional()
@IsString()
productId?: string;
}
+33
View File
@@ -2,6 +2,8 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, Http
import { PetsService } from './pets.service';
import { CreatePetDto } from './dto/create-pet.dto';
import { UpdatePetDto } from './dto/update-pet.dto';
import { CreateReminderDto } from './dto/create-reminder.dto';
import { CreateHealthLogDto } from './dto/create-health-log.dto';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiBadRequestResponse, ApiNotFoundResponse } from '@nestjs/swagger';
import { PaginationDto } from '../common/dto/pagination.dto';
@@ -185,4 +187,35 @@ export class PetsController {
remove(@Req() req: any, @Param('id') id: string) {
return this.petsService.remove(id, req.user.id);
}
@Post(':petId/reminders')
@ApiOperation({ summary: 'ثبت یادآور جدید برای پت' })
addReminder(
@Req() req: any,
@Param('petId') petId: string,
@Body() createReminderDto: CreateReminderDto,
) {
return this.petsService.addReminder(req.user.id, petId, createReminderDto);
}
@Post(':petId/reminders/:reminderId/toggle')
@ApiOperation({ summary: 'تغییر وضعیت انجام یادآور در یک تاریخ خاص' })
toggleReminder(
@Req() req: any,
@Param('petId') petId: string,
@Param('reminderId') reminderId: string,
@Body('date') date: string,
) {
return this.petsService.toggleReminder(req.user.id, petId, reminderId, date);
}
@Post(':petId/health-logs')
@ApiOperation({ summary: 'ثبت لاگ سلامت جدید برای پت' })
addHealthLog(
@Req() req: any,
@Param('petId') petId: string,
@Body() createHealthLogDto: CreateHealthLogDto,
) {
return this.petsService.addHealthLog(req.user.id, petId, createHealthLogDto);
}
}
+65
View File
@@ -103,4 +103,69 @@ export class PetsService {
where: { id },
});
}
async addReminder(userId: string, petId: string, data: any) {
await this.findOne(petId, userId);
return this.prisma.reminder.create({
data: {
petId,
productId: data.productId || null,
title: data.title,
time: data.time,
frequency: data.frequency,
},
});
}
async toggleReminder(userId: string, petId: string, reminderId: string, dateStr: string) {
await this.findOne(petId, userId);
const reminder = await this.prisma.reminder.findUnique({
where: { id: reminderId },
});
if (!reminder || reminder.petId !== petId) {
throw new NotFoundException('یادآور یافت نشد');
}
const dateParts = dateStr.split('-');
const completedDate = new Date(Date.UTC(Number(dateParts[0]), Number(dateParts[1]) - 1, Number(dateParts[2])));
const existingCompletion = await this.prisma.reminderCompletion.findUnique({
where: {
reminderId_completedDate: {
reminderId,
completedDate,
},
},
});
if (existingCompletion) {
await this.prisma.reminderCompletion.delete({
where: { id: existingCompletion.id },
});
return { completed: false };
} else {
await this.prisma.reminderCompletion.create({
data: {
reminderId,
completedDate,
},
});
return { completed: true };
}
}
async addHealthLog(userId: string, petId: string, data: any) {
await this.findOne(petId, userId);
return this.prisma.healthLog.create({
data: {
petId,
appetite: data.appetite,
energy: data.energy,
digestion: data.digestion,
note: data.note || null,
loggedDate: new Date(),
},
});
}
}