# Turn Linear Issues Into Pull Requests for a NestJS API

An agent adds the missing favorited flag to a NestJS API's article list and feed, with four Jest tests against a real MariaDB, all passing.

[Run this on Rush](https://cloud.getrush.ai/run/linear-issue-to-pr/nestjs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the issue, then `src/article/article.service.ts`, `article.controller.ts`, `article.interface.ts`, the entities and `user.service.ts`. `findAll` and `findFeed` returned bare `ArticleEntity` rows with no `favorited`, and the controller's `findAll` never read the current user. `findOne`, the single-article read, has no `favorited` either.

The fix passes `@User('id')` into `findAll` and adds one private `withFavorited` that loads the user's `favorites` once and marks each article, used by both list and feed. A new `ArticleWithFavorited` type in `article.interface.ts` carries the field. The four tests in a new `article.service.spec.ts` cover the user's own favorites, an anonymous request, someone else's favorites and the feed.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Implement the Linear issue supplied after this prompt in this NestJS application's article module. Read the issue, then the controller, service, interfaces, TypeORM entities and Jest configuration, and check which endpoints already behave as the issue asks. Reproduce the gap with Jest tests against a real disposable MySQL or MariaDB, not a mocked repository, make the narrow change, and run tsc and the Jest suite before and after. Report any setup the repository needs to build. Open a pull request linking the issue with the exact results. If no issue follows this prompt, stop and say so.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on lujakob/nestjs-realworld-example-app at c1c2cc4: issue #99, 4 files changed, 96 insertions(+), 7 deletions(-) across `article.controller.ts`, `article.interface.ts`, `article.service.ts` and a new `article.service.spec.ts`. `npx tsc --noEmit -p .` was clean and `npx jest --config=jest.json --forceExit` ended `Tests:       5 passed, 5 total`, up from 1. A live `GET /api/articles`, with and without a token, carried `favorited` on each article.

For the reviewer: whether `GET /articles/:slug` should get `favorited` too; the run left `findOne` alone. The raw clone does not build: `src/config.ts` and `ormconfig.json` are gitignored, so `tsc` failed with `Cannot find module '../config'` until the agent copied the `.example` files, and the tests need a running MariaDB. Jest never exits on its own because the database connection stays open, already true before the change, hence `--forceExit`.

## Run it on every Linear issue labelled api

An automation with a `linear` trigger on `linear.issue.labeled` and the label `api` runs this prompt when someone in your Rush org labels an issue. #99 itself is a GitHub issue; for those, a `github` trigger on `issues.labeled` adds the issue after the prompt the same way, but only for an issue filed by an owner, member or collaborator, which #99's author is not. Give it the frontend's expectation in the issue, as #99 did, and the agent checks every endpoint that should match, not only the one named.

## Why run it on Rush?

Beyond the fix, the run reported three bugs it left alone: `GET /articles` returns each author's argon2 password hash, `favorite()` reads `user.favorites` without loading the relation, and the `?favorited=` filter compares `authorId` against favorited article ids. Those belong in their own issues, and now they have the evidence for one.

## Frequently asked questions

### Why did install take more than npm ci?

`npm ci` crashed with "Exit handler never called", so the agent used `yarn install` from the repository's `yarn.lock`, rebuilt the native `argon2` binding, and restored `yarn.lock` so the diff stays clean.

### What does an anonymous request get?

`favorited: false` on every article. `favoritesCount` still comes from the existing `favoriteCount` column, unchanged.

## More NestJS jobs

- [Migrate a NestJS Project from Jest to Vitest](https://getrush.ai/run/migrate-jest-to-vitest/nestjs/)
- [Review Pull Requests Automatically in a NestJS API](https://getrush.ai/run/review-pull-requests/nestjs/)
- [Run a Security Audit on a NestJS API](https://getrush.ai/run/security-audit/nestjs/)

## The same job on other stacks

- [Turn Linear Issues into Pull Requests for a Next.js App](https://getrush.ai/run/linear-issue-to-pr/nextjs/)
- [Turn Linear Issues Into Pull Requests for a Nuxt App](https://getrush.ai/run/linear-issue-to-pr/nuxt/)
- [Turn Linear Issues Into Pull Requests for a Phoenix App](https://getrush.ai/run/linear-issue-to-pr/phoenix/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
