business
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { CreateCatalogueDto } from './dto/create-catalogue.dto';
|
||||
import { UpdateCatalogueDto } from './dto/update-catalogue.dto';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Catalogue } from './entities/catalogue.entity';
|
||||
import { Business } from '../business/entities/business.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogueService {
|
||||
create(createCatalogueDto: CreateCatalogueDto) {
|
||||
return 'This action adds a new catalogue';
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
async create(dto: CreateCatalogueDto) {
|
||||
const business = await this.em.findOne(Business, {})
|
||||
if (!business) {
|
||||
throw new BadRequestException()
|
||||
}
|
||||
const catalogue = this.em.create(Catalogue, { ...dto, business })
|
||||
return this.em.persistAndFlush(catalogue)
|
||||
}
|
||||
|
||||
findAll() {
|
||||
|
||||
@@ -1 +1,27 @@
|
||||
export class CreateCatalogueDto {}
|
||||
|
||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum } from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { CatalogueSize, CatalogueStatus } from '../enums/company-status.enum';
|
||||
|
||||
export class CreateCatalogueDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'ایرانی' })
|
||||
name: string;
|
||||
|
||||
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
content: string;
|
||||
|
||||
|
||||
@IsEnum(() => CatalogueStatus)
|
||||
@ApiProperty()
|
||||
status: CatalogueStatus;
|
||||
|
||||
|
||||
@IsEnum(() => CatalogueSize)
|
||||
@ApiProperty()
|
||||
size: CatalogueSize;
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +1,33 @@
|
||||
export class Catalogue {}
|
||||
import {
|
||||
Cascade, Collection, Entity, EntityRepositoryType, Enum,
|
||||
ManyToOne, OneToMany, OneToOne, Opt, Property
|
||||
} from "@mikro-orm/core";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { Business } from "src/modules/business/entities/business.entity";
|
||||
import { CatalogueSize, CatalogueStatus } from "../enums/company-status.enum";
|
||||
import { CatalogueRepository } from "../repositories/catalogue.repository";
|
||||
|
||||
@Entity({ repository: () => CatalogueRepository })
|
||||
export class Catalogue extends BaseEntity {
|
||||
@Property({ type: "varchar", length: 255, unique: true })
|
||||
name!: string;
|
||||
|
||||
@Property({ type: "json" })
|
||||
content!: string;
|
||||
|
||||
@Enum({ items: () => CatalogueStatus, nullable: false })
|
||||
status!: CatalogueStatus;
|
||||
|
||||
@Enum({ items: () => CatalogueSize, nullable: false })
|
||||
size!: CatalogueSize;
|
||||
|
||||
//-----------------------------------
|
||||
|
||||
@ManyToOne(() => Business, { deleteRule: "restrict" })
|
||||
business!: Business;
|
||||
|
||||
//-----------------------------------
|
||||
|
||||
[EntityRepositoryType]?: CatalogueRepository;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export enum CatalogueStatus {
|
||||
APPROVED = "APPROVED",
|
||||
PENDING = "PENDING",
|
||||
REJECTED = "REJECTED",
|
||||
}
|
||||
|
||||
|
||||
export enum CatalogueSize {
|
||||
A4 = 'a4',
|
||||
A3 = 'a3',
|
||||
A5 = 'a5'
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { EntityRepository, FilterQuery } from "@mikro-orm/postgresql";
|
||||
|
||||
|
||||
import { Catalogue } from "../entities/catalogue.entity";
|
||||
import { CatalogueStatus } from "../enums/company-status.enum";
|
||||
export class CatalogueRepository extends EntityRepository<Catalogue> {
|
||||
//
|
||||
// async getCataloguesForAdmin(queryDto: CompanyListQueryDto, businessId: string) {
|
||||
// const { } = queryDto
|
||||
|
||||
// const where: FilterQuery<Catalogue> = {
|
||||
// deletedAt: null,
|
||||
// business: { id: businessId },
|
||||
// };
|
||||
|
||||
// if (queryDto.status) {
|
||||
// where.status = queryDto.status;
|
||||
// }
|
||||
// if (queryDto.isActive !== undefined) {
|
||||
// where.isActive = queryDto.isActive === 1;
|
||||
// }
|
||||
// if (queryDto.q) {
|
||||
// where.name = { $ilike: `%${queryDto.q}%` };
|
||||
// }
|
||||
|
||||
// if (queryDto.registrationDate) {
|
||||
// where.createdAt = {
|
||||
// $gte: queryDto.registrationDate,
|
||||
// $lte: queryDto.registrationDate,
|
||||
// };
|
||||
// }
|
||||
// if (queryDto.name) {
|
||||
// where.name = { $ilike: `%${queryDto.name}%` };
|
||||
// }
|
||||
|
||||
// return this.findAndCount(where, {
|
||||
// populate: [],
|
||||
// limit,
|
||||
// offset: skip,
|
||||
// orderBy: { createdAt: "DESC" },
|
||||
// fields: [
|
||||
// "id",
|
||||
// "name",
|
||||
// "isActive",
|
||||
// "dateOfEstablishment",
|
||||
// "status",
|
||||
// "createdAt",
|
||||
// ],
|
||||
// });
|
||||
// }
|
||||
|
||||
// async getCataloguesForPublic(queryDto: CompanyListPublicQueryDto, businessId: string) {
|
||||
// const where: FilterQuery<Catalogue> = {
|
||||
// deletedAt: null,
|
||||
// business: { id: businessId },
|
||||
// isActive: true,
|
||||
// status: CatalogueStatus.APPROVED,
|
||||
// };
|
||||
|
||||
|
||||
// return this.find(where, {
|
||||
// populate: [],
|
||||
// orderBy: { createdAt: "DESC" },
|
||||
// fields: ["id", "name", "description", "profileImageUrl", "coverImageUrl", "createdAt"],
|
||||
// });
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user