design request
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260607075945_addIndexToCatalogue extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`create index "catalogue_slug_index" on "catalogue" ("slug");`);
|
||||
this.addSql(`create index "catalogue_business_id_id_index" on "catalogue" ("business_id");`);
|
||||
this.addSql(`create unique index "catalogue_business_id_id_slug_unique" on "catalogue" ("business_id", slug);`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`drop index "catalogue_slug_index";`);
|
||||
this.addSql(`drop index "catalogue_business_id_id_index";`);
|
||||
this.addSql(`drop index "catalogue_business_id_id_slug_unique";`);
|
||||
}
|
||||
|
||||
}
|
||||
+6
-3
@@ -1,15 +1,18 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260607075148_addRequestDesign extends Migration {
|
||||
export class Migration20260607123000_addDesignRequests extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`create table "design_requests" ("id" char(26) not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "title" varchar(255) not null, "count" int not null default 1, "desc" text null, "expected_date" timestamptz null, "attachments" jsonb not null default '[]', "invoice_id" uuid not null, "paid_at" timestamptz null, "business_id" char(26) not null, constraint "design_requests_pkey" primary key ("id"));`);
|
||||
this.addSql(`create index "design_requests_created_at_index" on "design_requests" ("created_at");`);
|
||||
this.addSql(`create index "design_requests_deleted_at_index" on "design_requests" ("deleted_at");`);
|
||||
this.addSql(`create index "design_requests_business_id_id_index" on "design_requests" (("business_id"->>'id'));`);
|
||||
this.addSql(`create index "design_requests_business_id_id_index" on "design_requests" ("business_id");`);
|
||||
this.addSql(`create index "design_requests_invoice_id_index" on "design_requests" ("invoice_id");`);
|
||||
|
||||
this.addSql(`alter table "design_requests" add constraint "design_requests_business_id_foreign" foreign key ("business_id") references "business" ("id") on update cascade on delete restrict;`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`drop table if exists "design_requests" cascade;`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,9 +27,9 @@ export class CatalogueController {
|
||||
return this.catalogueService.findOne(id);
|
||||
}
|
||||
|
||||
@Get('public/catalogue/slug/:slug')
|
||||
findOneBySlugAsPublic(@Param('slug') slug: string) {
|
||||
return this.catalogueService.findOneOrFailBySlug(slug);
|
||||
@Get('public/catalogue/:businessSlug/:catalogueSlug')
|
||||
findOneBySlugAsPublic(@Param('businessSlug') businessSlug: string, @Param('catalogueSlug') catalogueSlug: string) {
|
||||
return this.catalogueService.findOneOrFailBySlug(businessSlug,catalogueSlug);
|
||||
}
|
||||
|
||||
// ============= Admin Routes ==============
|
||||
|
||||
@@ -67,8 +67,8 @@ export class CatalogueService {
|
||||
return catalogue
|
||||
}
|
||||
|
||||
async findOneOrFailBySlug(slug: string) {
|
||||
const catalogue = await this.catalogueRepository.findOne({ slug })
|
||||
async findOneOrFailBySlug(businessSlug: string, catalogueSlug: string) {
|
||||
const catalogue = await this.catalogueRepository.findOne({ business: { slug: businessSlug }, slug: catalogueSlug })
|
||||
if (!catalogue) {
|
||||
throw new NotFoundException("catalogue by slug not found")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
Cascade, Collection, Entity, EntityRepositoryType, Enum,
|
||||
ManyToOne, OneToMany, OneToOne, Opt, Property
|
||||
Index,
|
||||
ManyToOne, OneToMany, OneToOne, Opt, Property,
|
||||
Unique
|
||||
} from "@mikro-orm/core";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
@@ -9,6 +11,9 @@ import { CatalogueSize, CatalogueStatus } from "../enums/company-status.enum";
|
||||
import { CatalogueRepository } from "../repositories/catalogue.repository";
|
||||
|
||||
@Entity({ repository: () => CatalogueRepository })
|
||||
@Index({ properties: ['business.id'] })
|
||||
@Index({ properties: ['slug'] })
|
||||
@Unique({ properties: ['business.id', 'slug'] })
|
||||
export class Catalogue extends BaseEntity {
|
||||
@Property({ type: "varchar", length: 255})
|
||||
name!: string;
|
||||
|
||||
@@ -7,8 +7,10 @@ import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
|
||||
import { FinishDesignRequestDto } from './dto/finish-design-request.dto';
|
||||
import { FindDesignRequestsDto } from './dto/find-design-requests.dto';
|
||||
import { MarkDesignRequestPaidDto } from './dto/mark-design-request-paid.dto';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
|
||||
@Controller()
|
||||
@ApiBearerAuth()
|
||||
export class DesignRequestController {
|
||||
constructor(private readonly designRequestService: DesignRequestService) { }
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export class DesignRequestService {
|
||||
private readonly httpService: HttpService,
|
||||
@Inject(ConfigService)
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
private getDesignUnitPrice(count: number): number {
|
||||
if (count < 10) {
|
||||
@@ -59,7 +59,8 @@ export class DesignRequestService {
|
||||
],
|
||||
};
|
||||
|
||||
let invoiceData: { id: string };
|
||||
let invoiceData: { id: string } = { id: '' };
|
||||
|
||||
|
||||
try {
|
||||
const { data } = await firstValueFrom(
|
||||
@@ -77,8 +78,8 @@ export class DesignRequestService {
|
||||
}),
|
||||
),
|
||||
);
|
||||
invoiceData = data;
|
||||
} catch (error: unknown) {
|
||||
invoiceData = data.data.invoice
|
||||
} catch (error: unknown) {
|
||||
this.logger.error(
|
||||
`Error create invoice: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user