-
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 all 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 |
|---|---|---|
|
|
@@ -19,5 +19,16 @@ CREATE TABLE "Product" ( | |
| CONSTRAINT "Product_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "Order" ( | ||
| "id" UUID NOT NULL DEFAULT gen_random_uuid(), | ||
| "name" TEXT NOT NULL, | ||
| "size" TEXT, | ||
| "costumer" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "Order_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
Comment on lines
+22
to
+31
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. Spelling: The new 🤖 Prompt for AI Agents |
||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,12 @@ model Product { | |
| size String? | ||
| description String? | ||
| createdAt DateTime @default(now()) @db.Timestamptz(6) | ||
| } | ||
| } | ||
|
|
||
| model Order { | ||
|
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. eine Order besteht immer aus mehreren Items eigentlich. Für Order gibt es mehrere Anforderungen:
--> damit du jetzt noch datenbankdesign lernst: Erstelle ein ER Diagram das die datenbank beschreibt entsprechend dem Standard.
Wir haben folgende Tabellen
|
||
| id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
| name String | ||
| size String? | ||
| costumer String | ||
| createdAt DateTime @default(now()) @db.Timestamptz(6) | ||
| } | ||
|
Comment on lines
+26
to
+32
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. Data model: Storing Note: the 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||
| import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator'; | ||||||||||||||||||
|
|
||||||||||||||||||
| export class CreateOrderDto { | ||||||||||||||||||
| @IsString() | ||||||||||||||||||
| @IsNotEmpty() | ||||||||||||||||||
| @MaxLength(128) | ||||||||||||||||||
| name!: string; | ||||||||||||||||||
|
|
||||||||||||||||||
| @IsString() | ||||||||||||||||||
| @IsOptional() | ||||||||||||||||||
| size?: string; | ||||||||||||||||||
|
|
||||||||||||||||||
| @IsString() | ||||||||||||||||||
| @IsNotEmpty() | ||||||||||||||||||
| @MaxLength(128) | ||||||||||||||||||
| costumer!: string; | ||||||||||||||||||
|
Comment on lines
+13
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. Typo: The field name 🛠️ Proposed fix `@IsString`()
`@IsNotEmpty`()
`@MaxLength`(128)
- costumer!: string;
+ customer!: string;Apply the same rename in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { PartialType } from '@nestjs/swagger'; | ||
| import { CreateOrderDto } from './create-order.dto'; | ||
| import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator'; | ||
|
|
||
| export class UpdateOrderDto extends PartialType(CreateOrderDto) { | ||
|
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. wenn du PartialType nutzt (an sich ok - wenn du wirklich alle felder von create auch updaten willst) |
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(128) | ||
| name!: string; | ||
|
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. Außerdem: in Update benutzt du ja "PATCH" und mit patch sollte man auch nur einen Teil der fleder updaten können. Wenn du sie hier aber wieder required machst dann muss man ja immer alle mitgeben. Ich hab zwar des PartialType noch nie verwendet, aber ich glaube es macht das schon korrekt. dementsprechend würde komplett reichen (siehe rabbit comment) Es gibt noch weiter Nestjs tools um zu vermeiden dtos doppelt zu schreiben, die kann man nutzten - aber immer mit bedacht. Zu viel krossreferenzierung macht den code auch nicht lesbarer :-) |
||
|
|
||
| @IsString() | ||
| @IsOptional() | ||
| size?: string; | ||
|
|
||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(128) | ||
| costumer!: string; | ||
| } | ||
|
Comment on lines
+5
to
+19
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. Re-declaring fields nullifies
🛠 Proposed fix import { PartialType } from '@nestjs/swagger';
import { CreateOrderDto } from './create-order.dto';
-import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
-export class UpdateOrderDto extends PartialType(CreateOrderDto) {
- `@IsString`()
- `@IsNotEmpty`()
- `@MaxLength`(128)
- name!: string;
-
- `@IsString`()
- `@IsOptional`()
- size?: string;
-
- `@IsString`()
- `@IsNotEmpty`()
- `@MaxLength`(128)
- costumer!: string;
-}
+export class UpdateOrderDto extends PartialType(CreateOrderDto) {}🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Order } from '../../../generated/prisma/client'; | ||
| import { CreateOrderDto } from '../dto/create-order.dto'; | ||
|
|
||
| export function mapOrderDTO(order: Order): CreateOrderDto { | ||
| return { | ||
| name: order.name, | ||
| size: order.size ?? undefined, | ||
| costumer: order.costumer, | ||
| }; | ||
| } | ||
|
Comment on lines
+4
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. Mapper drops Mapping a persisted Please either introduce an 🤖 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 { OrdersController } from './order.controller'; | ||
| import { OrderService } from './order.service'; | ||
|
|
||
| describe('OrdersController', () => { | ||
| let controller: OrdersController; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [OrdersController], | ||
| providers: [OrderService], | ||
| }).compile(); | ||
|
Comment on lines
+8
to
+12
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 the DI mismatch without running tests.
rg -n -C3 --type=ts 'class OrdersService|constructor\(private readonly prisma: PrismaService\)|controllers:\s*\[OrdersController\]|providers:\s*\[OrdersService\]'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2206 🏁 Script executed: # Check OrdersController to see what OrdersService methods are called
rg -n -A 10 'class OrdersController|@' src/modules/orders/orders.controller.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 1079 Mock
🧪 Proposed fix const module: TestingModule = await Test.createTestingModule({
controllers: [OrdersController],
- providers: [OrdersService],
+ providers: [
+ {
+ provide: OrdersService,
+ useValue: {
+ create: jest.fn(),
+ findAll: jest.fn(),
+ findOne: jest.fn(),
+ update: jest.fn(),
+ remove: jest.fn(),
+ },
+ },
+ ],
}).compile();🤖 Prompt for AI Agents
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. @MCSwainConnor Mocking und test schreiben müssen wir uns denke ich getrennt ma unterhalten
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.
|
||
|
|
||
| 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,25 @@ | ||||||
| import { Body, Controller, Delete, Param, Patch, Post } from '@nestjs/common'; | ||||||
| import { Order } from '../../generated/prisma/client'; | ||||||
| import { CreateOrderDto } from './dto/create-order.dto'; | ||||||
| import { UpdateOrderDto } from './dto/update-order.dto'; | ||||||
| import { OrderService } from './order.service'; | ||||||
|
|
||||||
| @Controller('orders') | ||||||
| export class OrdersController { | ||||||
| constructor(private readonly orderService: OrderService) {} | ||||||
|
|
||||||
| @Post() | ||||||
| create(@Body() createOrderDto: CreateOrderDto): Promise<Order> { | ||||||
| return this.orderService.create(createOrderDto); | ||||||
| } | ||||||
|
|
||||||
| @Patch(':id') | ||||||
| update(@Param('id') id: string, @Body() updateOrderDto: UpdateOrderDto): Promise<Order> { | ||||||
|
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. für die Incoming daten kannst du auch DTOs verwenden, was cooler ist z.b.
Suggested change
Hier gibt es jetzt viele möglichkeiten das zu designen. Wenn du bestimmte ids öfter verwendest kannst du ein gemeinsames Id dto machen. Vorteil im vergleich zu deinem:
|
||||||
| return this.orderService.update(id, updateOrderDto); | ||||||
| } | ||||||
|
|
||||||
| @Delete(':id') | ||||||
| remove(@Param('id') id: string): Promise<Order> { | ||||||
|
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. dann kannst dus hier genauso machen |
||||||
| return this.orderService.remove(id); | ||||||
| } | ||||||
|
ac-tiffi marked this conversation as resolved.
|
||||||
| } | ||||||
|
ac-tiffi marked this conversation as resolved.
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { OrderService } from './order.service'; | ||
| import { OrdersController } from './order.controller'; | ||
| import { PrismaModule } from '../../prisma/prisma.module'; | ||
|
|
||
| @Module({ | ||
| imports: [PrismaModule], | ||
| controllers: [OrdersController], | ||
| providers: [OrderService], | ||
| }) | ||
| export class OrdersModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { OrderService } from './order.service'; | ||
|
|
||
| describe('OrderService', () => { | ||
| let service: OrderService; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [OrderService], | ||
| }).compile(); | ||
|
Comment on lines
+8
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify OrdersService's required dependency and the current spec provider list.
rg -n -C3 --type=ts 'class OrdersService|constructor\(private readonly prisma: PrismaService\)|describe\(.\x27OrdersService.\x27|providers:\s*\[OrdersService\]'Repository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 2119 🏁 Script executed: #!/bin/bash
# Check the import path for PrismaService in orders.service.ts
head -10 src/modules/orders/orders.service.tsRepository: Tiffinger-Thiel-GmbH/Merch-Shop Length of output: 439 Provide a
🧪 Proposed fix import { Test, TestingModule } from '@nestjs/testing';
import { OrdersService } from './orders.service';
+import { PrismaService } from '../../prisma/prisma.service';
describe('OrdersService', () => {
let service: OrdersService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
- providers: [OrdersService],
+ providers: [
+ OrdersService,
+ {
+ provide: PrismaService,
+ useValue: {
+ create: jest.fn(),
+ findAll: jest.fn(),
+ findOne: jest.fn(),
+ update: jest.fn(),
+ remove: jest.fn(),
+ },
+ },
+ ],
}).compile();🤖 Prompt for AI Agents |
||
|
|
||
| service = module.get<OrderService>(OrderService); | ||
| }); | ||
|
|
||
| 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 { Order } from '../../generated/prisma/client'; | ||||||||||||||||||||||||||||
| import { PrismaService } from '../../prisma/prisma.service'; | ||||||||||||||||||||||||||||
| import { CreateOrderDto } from './dto/create-order.dto'; | ||||||||||||||||||||||||||||
| import { UpdateOrderDto } from './dto/update-order.dto'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @Injectable() | ||||||||||||||||||||||||||||
| export class OrderService { | ||||||||||||||||||||||||||||
| constructor(private readonly prisma: PrismaService) {} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async create(order: CreateOrderDto): Promise<Order> { | ||||||||||||||||||||||||||||
| return this.prisma.order.create({ | ||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||
| ...order, | ||||||||||||||||||||||||||||
| createdAt: new Date(), | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+18
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. 🧹 Nitpick | 🔵 Trivial Drop the manual The Prisma schema defines 🛠️ Proposed fix async create(order: CreateOrderDto): Promise<Order> {
return this.prisma.order.create({
- data: {
- ...order,
- createdAt: new Date(),
- },
+ data: { ...order },
});
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async findAll(): Promise<Order[]> { | ||||||||||||||||||||||||||||
| return this.prisma.order.findMany(); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async update(id: string, data: UpdateOrderDto): Promise<Order> { | ||||||||||||||||||||||||||||
| return this.prisma.order.update({ | ||||||||||||||||||||||||||||
| where: { id }, | ||||||||||||||||||||||||||||
| data, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async remove(id: string): Promise<Order> { | ||||||||||||||||||||||||||||
| return this.prisma.order.delete({ where: { id } }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| 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,36 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ApiExcludeController } from '@nestjs/swagger'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { PrismaService } from './prisma.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { CreatePrismaDto } from './dto/create-prisma.dto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UpdatePrismaDto } from './dto/update-prisma.dto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @ApiExcludeController() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @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(); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.