-
Notifications
You must be signed in to change notification settings - Fork 0
5 post api #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
5 post api #11
Changes from 7 commits
33562bb
3fa8073
e449cac
0f7055e
b2ec624
74d7fe8
bcfd635
dae3bae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,4 @@ model Product { | |
| size String? | ||
| description String? | ||
| createdAt DateTime @default(now()) @db.Timestamptz(6) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { IsNotEmpty, IsOptional, IsString, MaxLength } from '@nestjs/class-validator'; | ||
|
|
||
| export class CreateOrderDto { | ||
| @MaxLength(128) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| name: string; | ||
|
|
||
| @IsString() | ||
| @IsOptional() | ||
| size?: string; | ||
|
|
||
| @IsString() | ||
| @IsOptional() | ||
| description?: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { PartialType } from '@nestjs/swagger'; | ||
| import { CreateOrderDto } from './create-order.dto'; | ||
|
|
||
| export class UpdateOrderDto extends PartialType(CreateOrderDto) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export class Order {} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { OrdersController } from './orders.controller'; | ||
| import { OrdersService } from './orders.service'; | ||
|
|
||
| describe('OrdersController', () => { | ||
| let controller: OrdersController; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [OrdersController], | ||
| providers: [OrdersService], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<OrdersController>(OrdersController); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Controller, Post, Body, Patch, Param, Delete, Get } from '@nestjs/common'; | ||
| import { OrdersService } from './orders.service'; | ||
| import { CreateOrderDto } from './dto/create-order.dto'; | ||
| import { UpdateOrderDto } from './dto/update-order.dto'; | ||
|
|
||
| @Controller('orders') | ||
| export class OrdersController { | ||
| constructor(private readonly ordersService: OrdersService) {} | ||
|
|
||
| @Post() | ||
| create(@Body() createOrderDto: CreateOrderDto) { | ||
| return this.ordersService.create(createOrderDto); | ||
| } | ||
|
|
||
| @Get() | ||
| findAll() { | ||
| return this.ordersService.findAll(); | ||
| } | ||
|
|
||
| @Get(':id') | ||
| findOne(@Param('id') id: string) { | ||
| return this.ordersService.findOne(id); | ||
| } | ||
|
|
||
| @Patch(':id') | ||
| update(@Param('id') id: string, @Body() updateOrderDto: UpdateOrderDto) { | ||
| return this.ordersService.update(id, updateOrderDto); | ||
| } | ||
|
|
||
| @Delete(':id') | ||
| remove(@Param('id') id: string) { | ||
| return this.ordersService.remove(id); | ||
|
MCSwainConnor marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { OrdersService } from './orders.service'; | ||
| import { OrdersController } from './orders.controller'; | ||
| import { PrismaModule } from '../../prisma/prisma.module'; | ||
|
|
||
| @Module({ | ||
| imports: [PrismaModule], | ||
| controllers: [OrdersController], | ||
| providers: [OrdersService], | ||
| }) | ||
| export class OrdersModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { OrdersService } from './orders.service'; | ||
|
|
||
| describe('OrdersService', () => { | ||
| let service: OrdersService; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [OrdersService], | ||
| }).compile(); | ||
|
|
||
| service = module.get<OrdersService>(OrdersService); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(service).toBeDefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { PrismaService } from '../../prisma/prisma.service'; | ||
| import { CreateOrderDto } from './dto/create-order.dto'; | ||
| import { UpdateOrderDto } from './dto/update-order.dto'; | ||
|
|
||
| @Injectable() | ||
| export class OrdersService { | ||
| constructor(private readonly prisma: PrismaService) {} | ||
|
|
||
| create(createOrderDto: CreateOrderDto) { | ||
| const { name, size, description } = createOrderDto; | ||
| return this.prisma.create({ | ||
| name, | ||
| size, | ||
| description, | ||
| }); | ||
| } | ||
|
|
||
| findAll() { | ||
| return this.prisma.findAll(); | ||
| } | ||
|
|
||
| findOne(id: string) { | ||
| return this.prisma.findOne(id); | ||
| } | ||
|
|
||
| update(id: string, updateOrderDto: UpdateOrderDto) { | ||
| return this.prisma.update(id, updateOrderDto); | ||
| } | ||
|
|
||
| remove(id: string) { | ||
| return this.prisma.remove(id); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align The provided Prisma schema has 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { IsNotEmpty, IsOptional, IsString, MaxLength } from '@nestjs/class-validator'; | ||
|
|
||
| export class CreatePrismaDto { | ||
| @MaxLength(128) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| name: string; | ||
|
|
||
| @IsString() | ||
| @IsOptional() | ||
| size?: string; | ||
|
|
||
| @IsString() | ||
| @IsOptional() | ||
| description?: string; | ||
| } | ||
|
Comment on lines
+1
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd -t f "main.ts" src | xargs -I{} sh -c 'echo "=== {} ==="; cat "{}"'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 798 🏁 Script executed: cat -n package.jsonRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 3229 🏁 Script executed: fd -t f "schema.prisma" . | head -1 | xargs catRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 649 🏁 Script executed: fd -t f "*prisma.service.ts" src | xargs catRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 372 🏁 Script executed: fd -t f "*.controller.ts" src | xargs grep -l "prisma\|product" -iRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 371 🏁 Script executed: fd -g "*service.ts" src | head -20Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 236 🏁 Script executed: fd -g "*controller.ts" src | head -20Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 211 🏁 Script executed: rg "productsDelegate|PrismaService" src -A 2 -B 2 | head -50Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 3455 🏁 Script executed: rg "CreatePrismaDto|CreateProductDto" srcRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 771 🏁 Script executed: cat -n src/prisma/prisma.service.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2481 🏁 Script executed: cat -n src/prisma/prisma.controller.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 1234 🏁 Script executed: rg "@nestjs/class-validator" . --type-list | head -5Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 464 🏁 Script executed: rg "deprecated\|class-validator" . -i | head -20Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 57 🏁 Script executed: rg "class-validator" package.json -A 2 -B 2Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 245 🏁 Script executed: rg "deprecated" . --type jsonRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 361 🏁 Script executed: head -n 50 package.json | tail -n 30Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 1002 ValidationPipe must be registered in main.ts for decorators to take effect; naming contradicts NestJS conventions.
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { PartialType } from '@nestjs/swagger'; | ||
| import { CreatePrismaDto } from './create-prisma.dto'; | ||
|
|
||
| export class UpdatePrismaDto extends PartialType(CreatePrismaDto) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export class Prisma {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty placeholder entity — remove or populate.
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Test, TestingModule } from '@nestjs/testing'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { PrismaController } from './prisma.controller'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { PrismaService } from './prisma.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('PrismaController', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let controller: PrismaController; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const module: TestingModule = await Test.createTestingModule({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| controllers: [PrismaController], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providers: [PrismaService], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).compile(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| controller = module.get<PrismaController>(PrismaController); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should be defined', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(controller).toBeDefined(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect PrismaService to see whether it connects on init.
fd -t f "prisma.service.ts" | xargs -I{} sh -c 'echo "=== {} ==="; cat "{}"'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2658 Mock
Suggested fix- const module: TestingModule = await Test.createTestingModule({
- controllers: [PrismaController],
- providers: [PrismaService],
- }).compile();
+ const module: TestingModule = await Test.createTestingModule({
+ controllers: [PrismaController],
+ providers: [
+ {
+ provide: PrismaService,
+ useValue: {
+ create: jest.fn(),
+ findAll: jest.fn(),
+ findOne: jest.fn(),
+ update: jest.fn(),
+ remove: jest.fn(),
+ },
+ },
+ ],
+ }).compile();Additionally, the single 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { PrismaService } from './prisma.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CreatePrismaDto } from './dto/create-prisma.dto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UpdatePrismaDto } from './dto/update-prisma.dto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Controller('prisma') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class PrismaController { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(private readonly prismaService: PrismaService) {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Post() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create(@Body() createPrismaDto: CreatePrismaDto) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.prismaService.create(createPrismaDto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Get() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findAll() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.prismaService.findAll(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Get(':id') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findOne(@Param('id') id: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.prismaService.findOne(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Patch(':id') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update(@Param('id') id: string, @Body() updatePrismaDto: UpdatePrismaDto) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.prismaService.update(id, updatePrismaDto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Delete(':id') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remove(@Param('id') id: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.prismaService.remove(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify raw id params and UUID-backed schema fields.
rg -n -C2 --type=ts "@Param\\('id'\\) id: string|ParseUUIDPipe"
rg -n -C2 '@db\\.Uuid|@default\\(dbgenerated\\("gen_random_uuid\\(\\)"\\)\\)'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 1958 🏁 Script executed: # Find and examine the Prisma schema file
find . -name "*.prisma" -type fRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 97 🏁 Script executed: # Check the current imports in prisma.controller.ts
sed -n '1,10p' src/prisma/prisma.controller.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 456 🏁 Script executed: # Search for UUID field definitions in schema
rg -n "id.*@db\.Uuid|UUID" --type prismaRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 105 🏁 Script executed: # Check all controllers for similar patterns
rg -l "findOne.*@Param\('id'\)" --type tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 146 🏁 Script executed: # Read the Prisma schema to check ID field types
cat prisma/schema.prismaRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 649 🏁 Script executed: # Check orders.controller.ts imports
sed -n '1,10p' src/modules/orders/orders.controller.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 452 Add UUID validation to route parameters. The Prisma schema defines UUID IDs ( Proposed fix (src/prisma/prisma.controller.ts)-import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
+import { Controller, Get, Post, Body, Patch, Param, Delete, ParseUUIDPipe } from '@nestjs/common';
`@Get`(':id')
- findOne(`@Param`('id') id: string) {
+ findOne(`@Param`('id', ParseUUIDPipe) id: string) {
return this.prismaService.findOne(id);
}
`@Patch`(':id')
- update(`@Param`('id') id: string, `@Body`() updatePrismaDto: UpdatePrismaDto) {
+ update(`@Param`('id', ParseUUIDPipe) id: string, `@Body`() updatePrismaDto: UpdatePrismaDto) {
return this.prismaService.update(id, updatePrismaDto);
}
`@Delete`(':id')
- remove(`@Param`('id') id: string) {
+ remove(`@Param`('id', ParseUUIDPipe) id: string) {
return this.prismaService.remove(id);
}Apply the same changes to 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify where the Prisma controller is registered and imported.
rg -n -C3 --type=ts "@Controller\\('prisma'\\)|controllers:\\s*\\[PrismaController\\]|imports:\\s*\\[PrismaModule\\]"Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2284 Remove PrismaController from the module's controllers array. The 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -nP --type=ts -C2 '\bPrismaController\b'
rg -nP --type=ts -C3 'controllers\s*:\s*\[' src/prisma src/app.module.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 3178 Misleading naming and unauthenticated CRUD surface. The
However, a design concern remains:
If 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { PrismaService } from './prisma.service'; | ||
| import { PrismaController } from './prisma.controller'; | ||
|
|
||
| @Module({ | ||
| controllers: [PrismaController], | ||
| providers: [PrismaService], | ||
| exports: [PrismaService], | ||
| }) | ||
| export class PrismaModule {} | ||
|
Comment on lines
+1
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Mixing infrastructure and feature concerns in one module.
Also consider marking 🔧 Suggested shape import { Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';
-import { PrismaController } from './prisma.controller';
+@Global()
`@Module`({
- controllers: [PrismaController],
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}(and move the controller to a new 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { PrismaService } from './prisma.service'; | ||
|
|
||
| describe('PrismaService', () => { | ||
| let service: PrismaService; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [PrismaService], | ||
| }).compile(); | ||
|
|
||
| service = module.get<PrismaService>(PrismaService); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(service).toBeDefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // src/prisma/prisma.service.ts | ||
| import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; | ||
| import { PrismaClient } from '../generated/prisma/client'; | ||
| import { PrismaPg } from '@prisma/adapter-pg'; | ||
| import { CreatePrismaDto } from './dto/create-prisma.dto'; | ||
| import { UpdatePrismaDto } from './dto/update-prisma.dto'; | ||
|
|
||
| type ProductRecord = { | ||
| id: string; | ||
| name: string; | ||
| size: string | null; | ||
| description: string | null; | ||
| createdAt: Date; | ||
| }; | ||
|
|
||
| type ProductsDelegate = { | ||
| create(args: { data: CreatePrismaDto }): Promise<ProductRecord>; | ||
| findMany(): Promise<ProductRecord[]>; | ||
| findUnique(args: { where: { id: string } }): Promise<ProductRecord | null>; | ||
| update(args: { where: { id: string }; data: UpdatePrismaDto }): Promise<ProductRecord>; | ||
| delete(args: { where: { id: string } }): Promise<ProductRecord>; | ||
| }; | ||
|
|
||
| @Injectable() | ||
| export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { | ||
| constructor() { | ||
| super({ | ||
| adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }), | ||
| }); | ||
| } | ||
|
Comment on lines
+26
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate
Proposed fix constructor() {
+ const connectionString = process.env.DATABASE_URL;
+ if (!connectionString) {
+ throw new Error('DATABASE_URL is not set');
+ }
super({
- adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
+ adapter: new PrismaPg({ connectionString }),
});
}Or, preferably, wire this through Nest's 🤖 Prompt for AI Agents |
||
| async onModuleInit() { | ||
| await this.$connect(); | ||
| } | ||
| async onModuleDestroy() { | ||
| await this.$disconnect(); | ||
| } | ||
|
|
||
| private productsDelegate(): ProductsDelegate { | ||
| const prismaClient = this as unknown as { products: ProductsDelegate }; | ||
| return prismaClient.products; | ||
| } | ||
|
|
||
| create(createPrismaDto: CreatePrismaDto) { | ||
| return this.productsDelegate().create({ | ||
| data: createPrismaDto, | ||
| }); | ||
| } | ||
|
|
||
| findAll() { | ||
| return this.productsDelegate().findMany(); | ||
| } | ||
|
|
||
| findOne(id: string) { | ||
| return this.productsDelegate().findUnique({ | ||
| where: { id }, | ||
| }); | ||
| } | ||
|
|
||
| update(id: string, updatePrismaDto: UpdatePrismaDto) { | ||
| return this.productsDelegate().update({ | ||
| where: { id }, | ||
| data: updatePrismaDto, | ||
| }); | ||
| } | ||
|
|
||
| remove(id: string) { | ||
| return this.productsDelegate().delete({ | ||
| where: { id }, | ||
| }); | ||
| } | ||
|
Comment on lines
+38
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm the generated delegate name and that no @@map renames the table.
fd -t f 'schema.prisma' --exec cat {}
echo '---'
rg -nP '\b(product|products)\s*:' --type=ts -g '!**/generated/**'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 877 🏁 Script executed: # Check the full prisma.service.ts to see all CRUD methods and type definition
fd -t f 'prisma.service.ts' -path '*/src/prisma/*' --exec cat {}Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 243 🏁 Script executed: # Check the test file to see what is actually being tested
fd -t f 'prisma.service.spec.ts' --exec cat {}Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 994 🏁 Script executed: # Check if there are any integration tests that hit the CRUD endpoints
fd -t f '.spec.ts' --exec rg -l 'create|findAll|findOne|update|remove' {} \; | head -20Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 433 🏁 Script executed: # Get full prisma.service.ts content
cat -n src/prisma/prisma.service.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2481 🏁 Script executed: # Check app.e2e-spec.ts to see if it has integration tests covering the CRUD endpoints
cat -n test/app.e2e-spec.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 1002 Critical: The schema defines All five CRUD methods ( Fix: Rename the type and method to singular ( Add an integration test that invokes one of the CRUD methods to catch this in the future. 🤖 Prompt for AI Agents
Comment on lines
+43
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Don't put domain CRUD on
This is also what's producing the 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.