chore: add business update
This commit is contained in:
@@ -604,4 +604,12 @@ export const enum BusinessMessage {
|
||||
DOMAIN_REQUIRED = "دامنه مورد نیاز است",
|
||||
DOMAIN_MUST_BE_STRING = "دامنه باید یک رشته باشد",
|
||||
STAFF_NOT_FOUND = "کاربر ادمین یافت نشد",
|
||||
ZARINPAL_MERCHANT_ID_REQUIRED = "شناسه مرچنت زرین پال مورد نیاز است",
|
||||
ZARINPAL_MERCHANT_ID_STRING = "شناسه مرچنت زرین پال باید یک رشته باشد",
|
||||
LOGO_URL_REQUIRED = "آدرس تصویر لوگو مورد نیاز است",
|
||||
LOGO_URL_STRING = "آدرس تصویر لوگو باید یک رشته باشد",
|
||||
LOGO_URL_INVALID = "آدرس تصویر لوگو معتبر نیست",
|
||||
BUSINESS_SETTINGS_UPDATED = "تنظیمات کسب و کار با موفقیت به روز رسانی شد",
|
||||
NAME_REQUIRED = "نام کسب و کار مورد نیاز است",
|
||||
NAME_STRING = "نام کسب و کار باید یک رشته باشد",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsOptional, IsString, IsUrl } from "class-validator";
|
||||
|
||||
import { BusinessMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class UpdateBusinessSettingsDto {
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: BusinessMessage.ZARINPAL_MERCHANT_ID_REQUIRED })
|
||||
@IsString({ message: BusinessMessage.ZARINPAL_MERCHANT_ID_STRING })
|
||||
@ApiProperty({ description: "Zarinpal merchant id", example: "1234567890" })
|
||||
zarinpalMerchantId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: BusinessMessage.LOGO_URL_REQUIRED })
|
||||
@IsString({ message: BusinessMessage.LOGO_URL_STRING })
|
||||
@IsUrl({ protocols: ["https"] }, { message: BusinessMessage.LOGO_URL_INVALID })
|
||||
@ApiProperty({ description: "Logo url", example: "https://example.com/logo.png" })
|
||||
logoUrl?: string;
|
||||
|
||||
// @IsOptional()
|
||||
// @IsNotEmpty({ message: BusinessMessage.NAME_REQUIRED })
|
||||
// @IsString({ message: BusinessMessage.NAME_STRING })
|
||||
// @ApiProperty({ description: "Name", example: "Example" })
|
||||
// name?: string;
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
import { Body, Controller, Get, Param, Post } from "@nestjs/common";
|
||||
import { Body, Controller, Get, Param, Patch, Post, UseInterceptors } from "@nestjs/common";
|
||||
import { ApiHeader, ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { UpdateBusinessDomainDto } from "./DTO/business-domain.dto";
|
||||
import { BusinessSlugParamDto } from "./DTO/business-slug-param.dto";
|
||||
import { UpdateBusinessSettingsDto } from "./DTO/update-business-settings.dto";
|
||||
import { Business } from "./entities/business.entity";
|
||||
import { BusinessesService } from "./services/businesses.service";
|
||||
import { DomainVerificationService } from "./services/domain-verification.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { BusinessDec } from "../../common/decorators/business.decorator";
|
||||
import { BusinessInterceptor } from "../../core/interceptors/business.interceptor";
|
||||
|
||||
@Controller("business")
|
||||
@ApiHeader({ name: "x-business-id", description: "Business ID" })
|
||||
@UseInterceptors(BusinessInterceptor)
|
||||
export class BusinessesController {
|
||||
constructor(
|
||||
private readonly businessesService: BusinessesService,
|
||||
@@ -23,6 +26,20 @@ export class BusinessesController {
|
||||
return this.businessesService.getBusinessBySlug(params.slug);
|
||||
}
|
||||
|
||||
@Patch("settings")
|
||||
@ApiOperation({ summary: "Update business settings" })
|
||||
@AuthGuards()
|
||||
async updateBusinessSettings(@BusinessDec("id") businessId: string, @Body() settingsDto: UpdateBusinessSettingsDto) {
|
||||
return this.businessesService.updateBusinessSettings(businessId, settingsDto);
|
||||
}
|
||||
|
||||
@Get("settings")
|
||||
@ApiOperation({ summary: "Get business settings" })
|
||||
@AuthGuards()
|
||||
async getBusinessSettings(@BusinessDec("id") businessId: string) {
|
||||
return this.businessesService.getBusinessSettings(businessId);
|
||||
}
|
||||
|
||||
@Post("domain")
|
||||
@ApiOperation({ summary: "Update business domain" })
|
||||
@AuthGuards()
|
||||
|
||||
@@ -2,6 +2,7 @@ import { EntityManager } from "@mikro-orm/postgresql";
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
|
||||
import { BusinessMessage } from "../../../common/enums/message.enum";
|
||||
import { UpdateBusinessSettingsDto } from "../DTO/update-business-settings.dto";
|
||||
import { BusinessStaff } from "../entities/business-staff.entity";
|
||||
import { BusinessRepository } from "../repositories/business.repository";
|
||||
|
||||
@@ -18,6 +19,7 @@ export class BusinessesService {
|
||||
|
||||
return business;
|
||||
}
|
||||
//************************************************** */
|
||||
|
||||
async getBusinessBySlug(slug: string) {
|
||||
const business = await this.businessRepository.findOne({ slug, deletedAt: null });
|
||||
@@ -25,6 +27,28 @@ export class BusinessesService {
|
||||
|
||||
return { business };
|
||||
}
|
||||
//************************************************** */
|
||||
async updateBusinessSettings(businessId: string, settingsDto: UpdateBusinessSettingsDto) {
|
||||
const business = await this.businessRepository.findOne({ id: businessId, deletedAt: null });
|
||||
if (!business) throw new BadRequestException(BusinessMessage.NOT_FOUND);
|
||||
|
||||
this.businessRepository.assign(business, settingsDto);
|
||||
await this.em.flush();
|
||||
|
||||
return {
|
||||
message: BusinessMessage.BUSINESS_SETTINGS_UPDATED,
|
||||
business,
|
||||
};
|
||||
}
|
||||
//************************************************** */
|
||||
|
||||
async getBusinessSettings(businessId: string) {
|
||||
const business = await this.businessRepository.findOne({ id: businessId, deletedAt: null });
|
||||
if (!business) throw new BadRequestException(BusinessMessage.NOT_FOUND);
|
||||
|
||||
return { business };
|
||||
}
|
||||
//************************************************** */
|
||||
|
||||
async getBusinessById(id: string) {
|
||||
const business = await this.businessRepository.findOne({ id, deletedAt: null });
|
||||
@@ -33,7 +57,7 @@ export class BusinessesService {
|
||||
return business;
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
//************************************************** */
|
||||
|
||||
async findAdminWithLeastTickets() {
|
||||
// First query to get the ID of the business staff with the least tickets
|
||||
|
||||
Reference in New Issue
Block a user