business
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { CreateBusinessDto } from './dto/create-business.dto';
|
import { CreateBusinessDto } from './dto/create-business.dto';
|
||||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||||
|
import { EntityManager } from '@mikro-orm/postgresql';
|
||||||
|
import { Business } from './entities/business.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BusinessService {
|
export class BusinessService {
|
||||||
create(createBusinessDto: CreateBusinessDto) {
|
constructor(
|
||||||
return 'This action adds a new business';
|
private readonly em: EntityManager,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
create(dto: CreateBusinessDto) {
|
||||||
|
const business = this.em.create(Business, dto)
|
||||||
|
return this.em.persistAndFlush(business)
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll() {
|
||||||
|
|||||||
@@ -1 +1,23 @@
|
|||||||
export class CreateBusinessDto {}
|
|
||||||
|
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum } from 'class-validator';
|
||||||
|
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
|
|
||||||
|
export class CreateBusinessDto {
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ example: 'ایرانی' })
|
||||||
|
danakSubscriptionId: string;
|
||||||
|
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty()
|
||||||
|
slug: string;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1,56 @@
|
|||||||
export class Business {}
|
import { Cascade, Collection, Entity, EntityRepositoryType, OneToMany, Opt, Property, Unique } from "@mikro-orm/core";
|
||||||
|
|
||||||
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||||
|
import { Catalogue } from "src/modules/catalogue/entities/catalogue.entity";
|
||||||
|
import { BusinessRepository } from "../repositories/business.repository";
|
||||||
|
|
||||||
|
@Entity({ repository: () => BusinessRepository })
|
||||||
|
export class Business extends BaseEntity {
|
||||||
|
@Unique()
|
||||||
|
@Property({ type: "uuid", nullable: false })
|
||||||
|
danakSubscriptionId!: string;
|
||||||
|
|
||||||
|
@Property({ type: "varchar", length: 255, nullable: false })
|
||||||
|
name!: string;
|
||||||
|
|
||||||
|
@Property({ type: "varchar", length: 255, nullable: false })
|
||||||
|
slug!: string;
|
||||||
|
|
||||||
|
@Property({ type: "varchar", length: 255, nullable: true })
|
||||||
|
domain?: string;
|
||||||
|
|
||||||
|
@Property({ type: "boolean", default: false })
|
||||||
|
isDomainVerified: boolean & Opt;
|
||||||
|
|
||||||
|
@Property({ type: "varchar", length: 255, nullable: true })
|
||||||
|
domainVerificationToken?: string;
|
||||||
|
|
||||||
|
@Property({ type: "datetime", nullable: true })
|
||||||
|
domainVerifiedAt?: Date;
|
||||||
|
|
||||||
|
@Property({ type: "varchar", length: 255, nullable: true })
|
||||||
|
logoUrl?: string;
|
||||||
|
|
||||||
|
|
||||||
|
//=========================
|
||||||
|
|
||||||
|
@OneToMany(() => Catalogue, (catalogue) => catalogue.business, { cascade: [Cascade.ALL] })
|
||||||
|
companies = new Collection<Catalogue>(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// @OneToMany(() => Ticket, (ticket) => ticket.business)
|
||||||
|
// tickets = new Collection<Ticket>(this);
|
||||||
|
|
||||||
|
// @OneToMany(() => Announcement, (announcement) => announcement.business)
|
||||||
|
// announcements = new Collection<Announcement>(this);
|
||||||
|
|
||||||
|
// @OneToMany(() => Criticism, (criticism) => criticism.business)
|
||||||
|
// criticisms = new Collection<Criticism>(this);
|
||||||
|
|
||||||
|
|
||||||
|
// @OneToMany(() => User, (user) => user.business)
|
||||||
|
// users = new Collection<User>(this);
|
||||||
|
|
||||||
|
[EntityRepositoryType]?: BusinessRepository;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { EntityRepository } from "@mikro-orm/postgresql";
|
||||||
|
|
||||||
|
import { Business } from "../entities/business.entity";
|
||||||
|
|
||||||
|
export class BusinessRepository extends EntityRepository<Business> {}
|
||||||
@@ -1,11 +1,23 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import { CreateCatalogueDto } from './dto/create-catalogue.dto';
|
import { CreateCatalogueDto } from './dto/create-catalogue.dto';
|
||||||
import { UpdateCatalogueDto } from './dto/update-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()
|
@Injectable()
|
||||||
export class CatalogueService {
|
export class CatalogueService {
|
||||||
create(createCatalogueDto: CreateCatalogueDto) {
|
constructor(
|
||||||
return 'This action adds a new catalogue';
|
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() {
|
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"],
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ import { PaymentsModule } from '../payments/payments.module';
|
|||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { OrderRepository } from './repositories/order.repository';
|
import { OrderRepository } from './repositories/order.repository';
|
||||||
import { OrderListeners } from './listeners/order.listeners';
|
import { OrderListeners } from './listeners/order.listeners';
|
||||||
import { OrdersCrone } from './crone/order.crone';
|
|
||||||
import { AdminModule } from '../admin/admin.module';
|
import { AdminModule } from '../admin/admin.module';
|
||||||
import { NotificationsModule } from '../notifications/notifications.module';
|
import { NotificationsModule } from '../notifications/notifications.module';
|
||||||
import { InventoryModule } from '../inventory/inventory.module';
|
import { InventoryModule } from '../inventory/inventory.module';
|
||||||
@@ -36,7 +35,7 @@ import { UserModule } from '../users/user.module';
|
|||||||
forwardRef(() => UserModule)
|
forwardRef(() => UserModule)
|
||||||
],
|
],
|
||||||
controllers: [OrdersController],
|
controllers: [OrdersController],
|
||||||
providers: [OrdersService, OrderRepository, OrderListeners, OrdersCrone],
|
providers: [OrdersService, OrderRepository, OrderListeners],
|
||||||
exports: [OrderRepository, OrdersService],
|
exports: [OrderRepository, OrdersService],
|
||||||
})
|
})
|
||||||
export class OrdersModule { }
|
export class OrdersModule { }
|
||||||
|
|||||||
Reference in New Issue
Block a user