A NestJS controller gains an endpoint
An invoices module in NestJS. The change adds POST /invoices/:id/void, which marks an invoice void and emits an event, makes create take a due date, and injects an event emitter into the service.
The report lists the new handler with the @Post(":id/void") route it serves and the new service method with the database write it performs and the event it publishes through the injected emitter. It flags the widened create signatures and the extra constructor parameter as API changes, and keeps the classes' own reshuffling out of the way as syntax-only.
Configuration
{
"$schema": "https://aburi.dev/schema/aburi.config.v1.json",
"languages": ["@aburi/lang-typescript"],
"frameworks": ["@aburi/framework-nestjs"],
"effects": ["@aburi/effects-prisma", "@aburi/effects-nest"]
}The change
diff --git a/src/invoices/invoices.controller.ts b/src/invoices/invoices.controller.ts
index e91c526..e768796 100644
--- a/src/invoices/invoices.controller.ts
+++ b/src/invoices/invoices.controller.ts
@@ -11,7 +11,12 @@ export class InvoicesController {
}
@Post()
- create(@Body() body: { customerId: string; amountCents: number }) {
- return this.invoices.create(body.customerId, body.amountCents)
+ create(@Body() body: { customerId: string; amountCents: number; dueAt: string }) {
+ return this.invoices.create(body.customerId, body.amountCents, new Date(body.dueAt))
+ }
+
+ @Post(":id/void")
+ void(@Param("id") id: string) {
+ return this.invoices.void(id)
}
}
diff --git a/src/invoices/invoices.service.ts b/src/invoices/invoices.service.ts
index e3dcb9f..32ffd31 100644
--- a/src/invoices/invoices.service.ts
+++ b/src/invoices/invoices.service.ts
@@ -1,15 +1,27 @@
import { Injectable } from "@nestjs/common"
+import { EventEmitter2 } from "@nestjs/event-emitter"
import { PrismaClient } from "@prisma/client"
@Injectable()
export class InvoicesService {
- constructor(private readonly prisma: PrismaClient) {}
+ constructor(
+ private readonly prisma: PrismaClient,
+ private readonly events: EventEmitter2,
+ ) {}
findOne(id: string) {
return this.prisma.invoice.findUniqueOrThrow({ where: { id } })
}
- create(customerId: string, amountCents: number) {
- return this.prisma.invoice.create({ data: { customerId, amountCents, status: "draft" } })
+ create(customerId: string, amountCents: number, dueAt: Date) {
+ return this.prisma.invoice.create({
+ data: { customerId, amountCents, dueAt, status: "draft" },
+ })
+ }
+
+ async void(id: string) {
+ const invoice = await this.prisma.invoice.update({ where: { id }, data: { status: "void" } })
+ this.events.emit("invoice.voided", { id })
+ return invoice
}
}What aburi diff reports
Aburi diff: HEAD~1..HEAD
Summary: +2 added · -0 removed · ~5 changed · 0 moved · 0 moved+changed
⚠ API changes
InvoicesController.create (method)
File: src/invoices/invoices.controller.ts:14
- signature.inputs modified:
body: { customerId: string; amountCents: number }→body: { customerId: string; amountCents: number; dueAt: string } - calls added:
Date(L15)
InvoicesService.constructor (constructor)
File: src/invoices/invoices.service.ts:7
- signature.inputs added:
events: EventEmitter2
InvoicesService.create (method)
File: src/invoices/invoices.service.ts:16
- signature.inputs added:
dueAt: Date
🧵 Slice View
⚠ 2 calls below name a changed symbol in another Slice but were not resolved to it, so those Slices may belong together.
Standalone changes
7 symbols with no resolved call to or from another symbol in this view
InvoicesController— syntax only ·src/invoices/invoices.controller.ts:5InvoicesController.create— API and syntax changed ·src/invoices/invoices.controller.ts:14· ⚠ unresolved call tothis.invoices.createInvoicesController.void— new method ·src/invoices/invoices.controller.ts:19· ⚠ unresolved call tothis.invoices.voidInvoicesService— syntax only ·src/invoices/invoices.service.ts:6InvoicesService.constructor— API and syntax changed ·src/invoices/invoices.service.ts:7InvoicesService.create— API and syntax changed ·src/invoices/invoices.service.ts:16InvoicesService.void— new method with db.write, event.publish ·src/invoices/invoices.service.ts:22
➕ Added
InvoicesController.void (method)
File: src/invoices/invoices.controller.ts:19Boundary: @Post(":id/void")Signature: (id: string)Calls:
this.invoices.void(L20)
InvoicesService.void (method)
File: src/invoices/invoices.service.ts:22Signature: (id: string) ⚡async Effects:
- db.write:
this.prisma.invoice.update(L23) [effects-prisma] - event.publish:
this.events.emit(L24) [effects-nest]
🎨 Syntax-only changes
2 symbols (implementation refactor only, no semantic change)
InvoicesController(src/invoices/invoices.controller.ts:5)InvoicesService(src/invoices/invoices.service.ts:6)