buy catalogue
This commit is contained in:
@@ -7,6 +7,7 @@ import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||
import { BusinessId } from 'src/common/decorators';
|
||||
import { AdminId } from 'src/common/decorators';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { PurchaseCatalogueDto } from './dto/purchase-catalogue.dto';
|
||||
|
||||
@Controller()
|
||||
@ApiBearerAuth()
|
||||
@@ -33,6 +34,12 @@ export class CatalogueController {
|
||||
return this.catalogueService.create(dto, businessId);
|
||||
}
|
||||
|
||||
@Post('admin/catalogue/purchase')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
purchaseCatalogues(@Body() dto: PurchaseCatalogueDto, @BusinessId() businessId: string) {
|
||||
return this.catalogueService.createExternalInvoice(dto, businessId);
|
||||
}
|
||||
|
||||
@Get('admin/catalogue')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAll(@Query() queryDto: FindCataloguesDto, @BusinessId() businessId: string) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { CreateCatalogueDto } from './dto/create-catalogue.dto';
|
||||
import { UpdateCatalogueDto } from './dto/update-catalogue.dto';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
@@ -7,13 +7,21 @@ import { CatalogueStatus } from './enums/company-status.enum';
|
||||
import { CatalogueRepository } from './repositories/catalogue.repository';
|
||||
import { FindCataloguesDto } from './dto/find-catalogues.dto';
|
||||
import { BusinessService } from '../business/business.service';
|
||||
import { PurchaseCatalogueDto } from './dto/purchase-catalogue.dto';
|
||||
// import { HttpService } from '@nestjs/axios';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogueService {
|
||||
private readonly logger = new Logger(CatalogueService.name);
|
||||
// constructor(
|
||||
// @Inject(DPAGE_CONFIG) private readonly config: IDPageConfig,
|
||||
// private readonly subscriptionService: SubscriptionsService,
|
||||
// ) { }
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
private readonly catalogueRepository: CatalogueRepository,
|
||||
private readonly businessService: BusinessService,
|
||||
// private readonly httpService: HttpService,
|
||||
) { }
|
||||
|
||||
async create(dto: CreateCatalogueDto, businessId: string) {
|
||||
@@ -24,7 +32,7 @@ export class CatalogueService {
|
||||
if (createdCataloguesCount >= business.maxCataloguesCount) {
|
||||
throw new BadRequestException("شما از حداکثر تعداد کاتالوگ استفاده کرده اید و نمیتوانید کاتالوگ جدیدی بسازید")
|
||||
}
|
||||
|
||||
|
||||
const catalogue = this.em.create(Catalogue,
|
||||
{ ...dto, business, status: CatalogueStatus.PENDING })
|
||||
|
||||
@@ -74,4 +82,13 @@ export class CatalogueService {
|
||||
const count = await this.catalogueRepository.count({ business: { id: businessId }, deletedAt: null })
|
||||
return count ?? 0
|
||||
}
|
||||
|
||||
async createExternalInvoice(dto: PurchaseCatalogueDto, businessId: string) {
|
||||
const { count } = dto
|
||||
|
||||
const business = await this.businessService.findByIdOrFail(businessId)
|
||||
|
||||
// create external invoice
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
import { ApiProperty, ApiPropertyOptional, OmitType } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { ArrayMinSize, IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, Length, ValidateNested } from "class-validator";
|
||||
|
||||
export enum RecurringPeriodEnum {
|
||||
WEEKLY = 1, // هفتگی
|
||||
MONTHLY, // ماهانه
|
||||
QUARTERLY, // سهماهه
|
||||
SEMIANNUALLY, // ششماهه
|
||||
ANNUALLY, // سالانه
|
||||
}
|
||||
|
||||
|
||||
export class InvoiceItemDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@Length(1, 150,)
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
@ApiProperty({ type: Number, description: "Item count", example: 2 })
|
||||
count: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
@ApiProperty({ description: "Item unit price", example: 100_000 })
|
||||
unitPrice: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
@ApiProperty({ description: "Item discount", example: 10 })
|
||||
discount: number;
|
||||
}
|
||||
|
||||
export class CreateInvoiceDto {
|
||||
@IsNotEmpty()
|
||||
@IsUUID("4",)
|
||||
@ApiProperty({ description: "User id", example: "123e4567-e89b-12d3-a456-426614174000" })
|
||||
userId: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: [InvoiceItemDto],
|
||||
description: "Invoice items",
|
||||
example: [{ name: "item1", count: 2, unitPrice: 100_000, discount: 10 }],
|
||||
})
|
||||
@ValidateNested({ each: true })
|
||||
@ArrayMinSize(1)
|
||||
@Type(() => InvoiceItemDto)
|
||||
items: InvoiceItemDto[];
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiProperty({ description: "Is this a recurring invoice", example: false, default: false })
|
||||
isRecurring?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsEnum(RecurringPeriodEnum)
|
||||
@ApiPropertyOptional({
|
||||
description: "Recurring period (daily, weekly, monthly, quarterly, yearly)",
|
||||
example: RecurringPeriodEnum.QUARTERLY,
|
||||
enum: RecurringPeriodEnum,
|
||||
})
|
||||
recurringPeriod?: RecurringPeriodEnum;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@ApiPropertyOptional({ description: "Maximum number of recurring cycles (0 for unlimited)", example: 12, default: 0 })
|
||||
maxRecurringCycles?: number;
|
||||
}
|
||||
|
||||
export class CreateExternalInvoiceDto extends OmitType(CreateInvoiceDto, ["userId"]) {
|
||||
@IsNotEmpty()
|
||||
@IsUUID("4",)
|
||||
@ApiProperty()
|
||||
danakSubscriptionId: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ description: "Business id", example: "123e4567-e89b-12d3-a456-426614174000" })
|
||||
businessId: string;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
import { IsString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class PurchaseCatalogueDto {
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
count: string;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user