From a8a6f085d025a38b84c099faf24bbd368fd663e3 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 2 Jul 2026 15:53:23 +0330 Subject: [PATCH] add cursor rules --- .cursor/rules/architecture.mdc | 14 +++++++++++ .cursor/rules/mikroorm.mdc | 22 ++++++++++++++++ .cursor/rules/nestjs.mdc | 25 +++++++++++++++++++ .cursor/rules/performance.mdc | 14 +++++++++++ .cursor/rules/postgres.mdc | 15 +++++++++++ .cursor/rules/typescript.mdc | 14 +++++++++++ .../form-builder/provider/field.service.ts | 4 +-- src/modules/print/provider/print.service.ts | 2 +- 8 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 .cursor/rules/architecture.mdc create mode 100644 .cursor/rules/mikroorm.mdc create mode 100644 .cursor/rules/nestjs.mdc create mode 100644 .cursor/rules/performance.mdc create mode 100644 .cursor/rules/postgres.mdc create mode 100644 .cursor/rules/typescript.mdc diff --git a/.cursor/rules/architecture.mdc b/.cursor/rules/architecture.mdc new file mode 100644 index 0000000..acc485d --- /dev/null +++ b/.cursor/rules/architecture.mdc @@ -0,0 +1,14 @@ +--- +description: Architecture +alwaysApply: true +--- + +Before generating code: + +- Search for existing implementations. +- Reuse existing services. +- Reuse existing DTOs. +- Follow naming conventions. +- Match the project's coding style. +- Never duplicate logic. +- Prefer extending existing modules. \ No newline at end of file diff --git a/.cursor/rules/mikroorm.mdc b/.cursor/rules/mikroorm.mdc new file mode 100644 index 0000000..2aa315d --- /dev/null +++ b/.cursor/rules/mikroorm.mdc @@ -0,0 +1,22 @@ +--- +description: MikroORM +globs: + - "src/**/*.entity.ts" + - "src/**/*.service.ts" +alwaysApply: true +--- + +Use MikroORM best practices. + +- Never write raw SQL unless necessary. +- Prefer EntityRepository. +- Use populate instead of manual joins. +- Use wrap(entity).assign() for updates. +- Use transactions when updating multiple entities. +- Use Collection for OneToMany relations. +- Use references when appropriate. +- Avoid N+1 queries. +- Always type repository injections. +- Use indexes where needed.--- +alwaysApply: true +--- diff --git a/.cursor/rules/nestjs.mdc b/.cursor/rules/nestjs.mdc new file mode 100644 index 0000000..5d9a725 --- /dev/null +++ b/.cursor/rules/nestjs.mdc @@ -0,0 +1,25 @@ +--- +description: NestJS Backend Rules +globs: + - "src/**/*.ts" +alwaysApply: true +--- + +You are an expert NestJS developer. + +Rules: + +- Use dependency injection. +- Use constructor injection instead of manually creating services. +- Follow the existing folder structure. +- Keep controllers thin. +- Business logic belongs in services. +- DTOs must use class-validator. +- Always create DTOs for request bodies. +- Return typed responses. +- Use async/await. +- Never use any. +- Prefer readonly where possible. +- Use ConfigService instead of process.env directly. +- Throw NestJS HttpExceptions. +- Write clean, maintainable TypeScript. \ No newline at end of file diff --git a/.cursor/rules/performance.mdc b/.cursor/rules/performance.mdc new file mode 100644 index 0000000..60dae4d --- /dev/null +++ b/.cursor/rules/performance.mdc @@ -0,0 +1,14 @@ +--- +description: Performance +alwaysApply: true +--- + +Optimize for performance. + +- Minimize database queries. +- Batch database operations. +- Avoid N+1. +- Paginate large datasets. +- Select only required columns.--- +alwaysApply: true +--- diff --git a/.cursor/rules/postgres.mdc b/.cursor/rules/postgres.mdc new file mode 100644 index 0000000..f91b16f --- /dev/null +++ b/.cursor/rules/postgres.mdc @@ -0,0 +1,15 @@ +--- +description: PostgreSQL +alwaysApply: true +--- + +Database rules: + +- Prefer UUID primary keys. +- Index foreign keys. +- Avoid SELECT *. +- Design queries to use indexes. +- Use migrations instead of synchronize. +- Never remove data unless explicitly requested.--- +alwaysApply: true +--- diff --git a/.cursor/rules/typescript.mdc b/.cursor/rules/typescript.mdc new file mode 100644 index 0000000..720b25e --- /dev/null +++ b/.cursor/rules/typescript.mdc @@ -0,0 +1,14 @@ +--- +description: TypeScript +alwaysApply: true +--- + +Code quality: + +- Never use any. +- Prefer unknown over any. +- Use interfaces for DTOs. +- Use enums only when appropriate. +- Use strict typing. +- Add return types to exported functions. +- Keep functions under 40 lines when possible. \ No newline at end of file diff --git a/src/modules/form-builder/provider/field.service.ts b/src/modules/form-builder/provider/field.service.ts index 6e49745..3514b93 100644 --- a/src/modules/form-builder/provider/field.service.ts +++ b/src/modules/form-builder/provider/field.service.ts @@ -82,9 +82,9 @@ export class FieldService { findAll(entityId: string) { return this.fieldRepository.find({ - entityId + entityId, }, - { populate: ['options'] }); + { populate: ['options'], orderBy: { order: 'ASC' } }); } async findAllByIds(dto: FindFieldsGroupDto) { diff --git a/src/modules/print/provider/print.service.ts b/src/modules/print/provider/print.service.ts index 6b4953d..3fda12a 100644 --- a/src/modules/print/provider/print.service.ts +++ b/src/modules/print/provider/print.service.ts @@ -48,7 +48,7 @@ export class PrintService { } async findAll(): Promise { - const sections = await this.printRepository.findAll(); + const sections = await this.printRepository.findAll({ orderBy: { order: 'ASC' } }); const promises = sections.map(async (section) => { const fields = await this.fieldService.findAll(section.id)