This commit is contained in:
@@ -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.
|
||||||
@@ -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
|
||||||
|
---
|
||||||
@@ -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.
|
||||||
@@ -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
|
||||||
|
---
|
||||||
@@ -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
|
||||||
|
---
|
||||||
@@ -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.
|
||||||
@@ -82,9 +82,9 @@ export class FieldService {
|
|||||||
|
|
||||||
findAll(entityId: string) {
|
findAll(entityId: string) {
|
||||||
return this.fieldRepository.find({
|
return this.fieldRepository.find({
|
||||||
entityId
|
entityId,
|
||||||
},
|
},
|
||||||
{ populate: ['options'] });
|
{ populate: ['options'], orderBy: { order: 'ASC' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByIds(dto: FindFieldsGroupDto) {
|
async findAllByIds(dto: FindFieldsGroupDto) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class PrintService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<PrintWithFields[]> {
|
async findAll(): Promise<PrintWithFields[]> {
|
||||||
const sections = await this.printRepository.findAll();
|
const sections = await this.printRepository.findAll({ orderBy: { order: 'ASC' } });
|
||||||
|
|
||||||
const promises = sections.map(async (section) => {
|
const promises = sections.map(async (section) => {
|
||||||
const fields = await this.fieldService.findAll(section.id)
|
const fields = await this.fieldService.findAll(section.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user