fix: update company

This commit is contained in:
2026-02-16 16:35:30 +03:30
parent f21f858b44
commit eaffe6f8b0
2 changed files with 23 additions and 5 deletions
@@ -1,5 +1,5 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseInterceptors } from "@nestjs/common";
import { ApiOperation } from "@nestjs/swagger";
import { ApiHeader, ApiOperation } from "@nestjs/swagger";
import { CompanyListPublicQueryDto, CompanyListQueryDto } from "./DTO/company-list-query.dto";
import { ChangeCompanyRequestStatusDto, CreateCompanyDto, CreateCompanyRequestDto } from "./DTO/create-company.dto";
@@ -27,6 +27,7 @@ export class CompaniesController {
@Patch(":id")
@AuthGuards()
@ApiHeader({ name: "x-business-id" })
@ApiOperation({ summary: "update company (admin)" })
update(@Param() paramDto: ParamDto, @Body() updateCompanyDto: UpdateCompanyDto, @BusinessDec("id") businessId: string) {
return this.companiesService.updateCompanyById(paramDto.id, updateCompanyDto, businessId);
+21 -4
View File
@@ -95,21 +95,38 @@ export class UsersService {
/*******************************/
async updateUser(userId: string, updateData: Partial<User>, em: EntityManager) {
const user = await em.findOne(User, { id: userId, deletedAt: null });
const user = await em.findOne(User, { id: userId, deletedAt: null }, { populate: ["business"] });
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
const businessId = user.business.id;
if (updateData.phone) {
const existingUser = await em.findOne(User, { phone: updateData.phone, deletedAt: null, id: { $ne: userId } });
const existingUser = await em.findOne(User, {
phone: updateData.phone,
deletedAt: null,
id: { $ne: userId },
business: { id: businessId },
});
if (existingUser) throw new BadRequestException(UserMessage.PHONE_EXIST);
}
if (updateData.email) {
const existingUser = await em.findOne(User, { email: updateData.email, deletedAt: null, id: { $ne: userId } });
const existingUser = await em.findOne(User, {
email: updateData.email,
deletedAt: null,
id: { $ne: userId },
business: { id: businessId },
});
if (existingUser) throw new BadRequestException(UserMessage.EMAIL_EXIST);
}
if (updateData.nationalCode) {
const existingUser = await em.findOne(User, { nationalCode: updateData.nationalCode, deletedAt: null, id: { $ne: userId } });
const existingUser = await em.findOne(User, {
nationalCode: updateData.nationalCode,
deletedAt: null,
id: { $ne: userId },
business: { id: businessId },
});
if (existingUser) throw new BadRequestException(UserMessage.NATIONAL_CODE_EXIST);
}