From 758bb03a26098a867f9e2eb4f7f0ce5084cef6a2 Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Mon, 18 May 2026 13:20:33 +0330 Subject: [PATCH] feat: add update password functionality and DTO for partner service --- .../business-activities-query.service.ts | 2 - src/common/utils/http-client.util.ts | 2 - src/modules/auth/auth.service.ts | 2 - .../dto/update-password-request.dto.ts | 8 ++++ src/modules/partners/partners.controller.ts | 30 +++++++++++--- src/modules/partners/partners.service.ts | 41 ++++++++++++++++--- 6 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/modules/partners/dto/update-password-request.dto.ts diff --git a/src/common/services/businessActivities/business-activities-query.service.ts b/src/common/services/businessActivities/business-activities-query.service.ts index 3bbef07..6b67cd3 100644 --- a/src/common/services/businessActivities/business-activities-query.service.ts +++ b/src/common/services/businessActivities/business-activities-query.service.ts @@ -37,8 +37,6 @@ export class BusinessActivitiesQueryService { select: QUERY_CONSTANTS.BUSINESS_ACTIVITIES.select, }) - console.log('businessActivity', businessActivity) - return QUERY_CONSTANTS.BUSINESS_ACTIVITIES.mappedData(businessActivity) } } diff --git a/src/common/utils/http-client.util.ts b/src/common/utils/http-client.util.ts index 3995418..56e7912 100644 --- a/src/common/utils/http-client.util.ts +++ b/src/common/utils/http-client.util.ts @@ -29,8 +29,6 @@ export class HttpClientUtil { continue } response = await interceptor.onResponse(context, response) - console.log('response') - console.log(response) } return response diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index e20048b..ecf7b1a 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -59,8 +59,6 @@ export class AuthService { include: accountInclude, }) - console.log('account', account) - if (!account) { throw new NotFoundException('اطلاعات ورودی شما اشتباه است') } diff --git a/src/modules/partners/dto/update-password-request.dto.ts b/src/modules/partners/dto/update-password-request.dto.ts new file mode 100644 index 0000000..d1f2a23 --- /dev/null +++ b/src/modules/partners/dto/update-password-request.dto.ts @@ -0,0 +1,8 @@ +import { ApiProperty } from '@nestjs/swagger' +import { IsString } from 'class-validator' + +export class UpdatePartnerPasswordDto { + @IsString() + @ApiProperty({ required: true }) + password: string +} diff --git a/src/modules/partners/partners.controller.ts b/src/modules/partners/partners.controller.ts index 855e97a..ea36a95 100644 --- a/src/modules/partners/partners.controller.ts +++ b/src/modules/partners/partners.controller.ts @@ -1,16 +1,24 @@ import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator' +import type { IPartnerPayload } from '@/common/models/partnerPayload.model' import { multerImageOptions } from '@/multer.config' import { Body, Controller, Get, Patch, + Put, UploadedFile, UseInterceptors, } from '@nestjs/common' import { FileInterceptor } from '@nestjs/platform-express' import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger' import { UpdatePartnerProfileDto } from './dto/partner.dto' +import { + PartnerServiceGetInfoResponseDto, + PartnerServiceMeResponseDto, + PartnerServiceUpdateInfoResponseDto, +} from './dto/partners-response.dto' +import { UpdatePartnerPasswordDto } from './dto/update-password-request.dto' import { PartnerService } from './partners.service' @ApiTags('Partner') @@ -19,16 +27,20 @@ export class PartnerController { constructor(private service: PartnerService) {} @Get('') - async me(@PartnerInfo() { id, account_id }: IPartnerPayload): Promise { + async me( + @PartnerInfo() { id, account_id }: IPartnerPayload, + ): Promise { return this.service.me(id, account_id) } @Get('info') - async getInfo(@PartnerInfo('id') partnerId: string): Promise { + async getInfo( + @PartnerInfo('id') partnerId: string, + ): Promise { return this.service.getInfo(partnerId) } - @Patch('profile') + @Patch('') @UseInterceptors(FileInterceptor('logo', multerImageOptions)) @ApiConsumes('multipart/form-data') @ApiBody({ @@ -46,7 +58,13 @@ export class PartnerController { ): Promise { return this.service.updateInfo(partnerId, data, logo) } -} -import type { IPartnerPayload } from '@/common/models/partnerPayload.model' -import type { PartnerServiceGetInfoResponseDto, PartnerServiceMeResponseDto, PartnerServiceUpdateInfoResponseDto } from './dto/partners-response.dto' \ No newline at end of file + @Put('update-password') + async updatePassword( + @PartnerInfo('id') partnerId: string, + @PartnerInfo('account_id') accountId: string, + @Body() data: UpdatePartnerPasswordDto, + ) { + return this.service.updatePassword(partnerId, accountId, data) + } +} diff --git a/src/modules/partners/partners.service.ts b/src/modules/partners/partners.service.ts index c49903b..5754c93 100644 --- a/src/modules/partners/partners.service.ts +++ b/src/modules/partners/partners.service.ts @@ -1,10 +1,11 @@ import { UploadedFileTypes } from '@/common/enums/enums' import { ResponseMapper } from '@/common/response/response-mapper' -import { PartnerAccountSelect } from '@/generated/prisma/models' +import { PasswordUtil } from '@/common/utils' import { UploaderService } from '@/modules/uploader/uploader.service' import { PrismaService } from '@/prisma/prisma.service' import { Injectable } from '@nestjs/common' import { UpdatePartnerProfileDto } from './dto/partner.dto' +import { UpdatePartnerPasswordDto } from './dto/update-password-request.dto' @Injectable() export class PartnerService { @@ -13,10 +14,8 @@ export class PartnerService { private readonly uploaderService: UploaderService, ) {} - private readonly defaultSelect: PartnerAccountSelect = {} - async me(partner_id: string, account_id: string) { - const partner = await this.prisma.partnerAccount.findUniqueOrThrow({ + const partnerAccount = await this.prisma.partnerAccount.findUniqueOrThrow({ where: { id: account_id, partner_id, @@ -33,12 +32,21 @@ export class PartnerService { select: { id: true, name: true, + code: true, + logo_url: true, }, }, }, }) - return ResponseMapper.single(partner) + return ResponseMapper.single({ + ...partnerAccount.partner, + account: { + role: partnerAccount.role, + id: partnerAccount.id, + username: partnerAccount.account.username, + }, + }) } async getInfo(partner_id: string) { @@ -234,10 +242,31 @@ export class PartnerService { ...rest, ...(logo_url ? { logo_url } : {}), }, - select: this.defaultSelect, }) }) return ResponseMapper.single(updatedPartner) } + + async updatePassword( + partner_id: string, + accountId: string, + data: UpdatePartnerPasswordDto, + ) { + const partnerAccount = await this.prisma.partnerAccount.update({ + where: { + id: accountId, + partner_id, + }, + data: { + account: { + update: { + password: await PasswordUtil.hash(data.password), + }, + }, + }, + }) + + return ResponseMapper.update(partnerAccount) + } }