Skip to content

Feat/add walker from user#29

Merged
dm94 merged 6 commits intomainfrom
feat/addWalkerFromUser
Mar 17, 2026
Merged

Feat/add walker from user#29
dm94 merged 6 commits intomainfrom
feat/addWalkerFromUser

Conversation

@dm94
Copy link
Copy Markdown
Owner

@dm94 dm94 commented Mar 16, 2026

Summary by Sourcery

Add an authenticated endpoint for users to create walkers and extend walker usage classifications.

New Features:

  • Introduce a POST /walkers endpoint allowing authenticated users to add new walkers tied to their clan/discord server.

Enhancements:

  • Expand the WalkerUse enum with additional usage types such as scout, raider, support, hauler, craft, and storage.
  • Wire up typed AddWalkersRequest payload handling for walker creation requests.
  • Return standardized 400 responses for invalid walker creation payloads.

dm94 added 2 commits March 16, 2026 01:10
Implement a new POST /walkers endpoint that allows authenticated users to add new walkers to their clan. The endpoint accepts optional fields like owner, type, use, ready status, and description, with sensible defaults. This enables clans to programmatically add walkers to their inventory through the API.
The endpoint summary and operationId were changed from 'addWalker' to 'addWalkerFromUser' to better reflect its specific purpose and distinguish it from other potential walker creation methods.
@dm94 dm94 self-assigned this Mar 16, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 16, 2026

Reviewer's Guide

Adds a new authenticated POST /walkers endpoint that lets a user create a walker record tied to their clan/Discord server, extends walker usage enum values, and wires the new request type into the API while also standardizing string literals and error handling in the walkers routes.

Updated class diagram for walker request types and WalkerUse enum

classDiagram
  class WalkerUse {
    <<enumeration>>
    PVP
    FARMING
    PERSONAL
    RAM
    SCOUT
    RAIDER
    SUPPORT
    HAULER
    CRAFT
    STORAGE
  }

  class WalkerType {
    <<enumeration>>
  }

  class AddWalkersRequest {
    +Body body
  }

  class Body {
    +string name
    +string owner
    +WalkerUse use
    +boolean ready
    +WalkerType type
    +string description
  }

  AddWalkersRequest --> Body : has
  Body --> WalkerUse : uses
  Body --> WalkerType : uses
Loading

File-Level Changes

Change Details Files
Add POST /walkers endpoint to allow authenticated users to create walkers
  • Register a new POST route on the root walkers path with authenticate hook and OpenAPI schema metadata
  • Define request body schema with fields for name (required), owner, use, ready, type, and description using WalkerUse and WalkerType enums
  • Add 201, 400, 401, 405, and 503 response schemas, including a simple success payload with a message field
  • Implement handler that validates dbuser and clan/server presence and returns appropriate HTTP status codes for auth/clan errors and missing name
src/routes/walkers/index.ts
Persist newly created walkers to the database with sensible defaults derived from the authenticated user
  • Generate a walkerID via randomUUID and use the authenticated user’s serverdiscord as the walker discord id
  • Populate owner and lastuser from request body or dbuser fields with fallback to user nickname/discordid
  • Derive datelastuse as current date, default walker_use to PERSONAL and type to DINGHY, and default optional fields (ready, description) when not provided
  • Execute an INSERT into the walkers table and map success/failure to 201 or 503 responses
src/routes/walkers/index.ts
Extend walker usage classifications to support more use cases
  • Add additional WalkerUse enum values (SCOUT, RAIDER, SUPPORT, HAULER, CRAFT, STORAGE) so they can be used in request validation and persistence
  • Reuse WalkerUse enum for both query filtering on GET /walkers and body validation on POST /walkers
src/types/walkers.ts
src/routes/walkers/index.ts
Introduce typed AddWalkersRequest interface to model the POST body
  • Create AddWalkersRequest interface with Body fields matching the POST /walkers schema, using WalkerUse and WalkerType types
  • Use AddWalkersRequest as the generic parameter for the new POST route for better type safety on request.body
src/types/requests/walkers.ts
src/routes/walkers/index.ts
Minor refactors for consistency and readability in walkers routes
  • Switch imports and literals in walkers route file to double-quoted strings
  • Reformat query parameter parsing and SQL building for better readability while preserving behavior
  • Add Error400Default to imports to support 400 responses in the new POST route
src/routes/walkers/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Add SCOUT, RAIDER, SUPPORT, HAULER, CRAFT, and STORAGE to WalkerUse enum to expand walker functionality classification.
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The POST /walkers handler mixes callback-style server.mysql.query with early return from the route without always guaranteeing a single response; consider making the handler async and using the promise API (or wrapping in a promise) so you can await the insert and return exactly once on all paths.
  • The manual if (!request?.body?.name) 400 response returns an empty body, which conflicts with the documented Error400Default schema; either rely on Fastify's schema validation for the name requirement or return an error object that matches the 400 schema.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The POST `/walkers` handler mixes callback-style `server.mysql.query` with early `return` from the route without always guaranteeing a single response; consider making the handler `async` and using the promise API (or wrapping in a promise) so you can `await` the insert and `return` exactly once on all paths.
- The manual `if (!request?.body?.name)` 400 response returns an empty body, which conflicts with the documented `Error400Default` schema; either rely on Fastify's schema validation for the `name` requirement or return an error object that matches the 400 schema.

## Individual Comments

### Comment 1
<location path="src/routes/walkers/index.ts" line_range="229-238" />
<code_context>
+          201: Type.Object({
+            message: Type.String(),
+          }),
+          400: Error400Default,
+          401: Error401Default,
+          405: Error405Default,
+          503: Error503Default,
+        },
+      },
+    },
+    (request, reply) => {
+      if (!request?.dbuser) {
+        reply.code(401);
+        return new Error("Invalid token JWT");
+      }
+      if (!request?.dbuser.clanid || !request?.dbuser.serverdiscord) {
+        reply.code(405);
+        return new Error("No clan");
+      }
+      if (!request?.body?.name) {
+        return reply.code(400).send();
+      }
</code_context>
<issue_to_address>
**issue (bug_risk):** Align 400 error handling with the declared Error400Default schema

The 400 response is documented as `Error400Default`, but the missing `name` case sends a 400 with no body. This mismatch can break clients expecting the structured error. Please return an `Error400Default`-shaped payload here (and in any other 400 paths).
</issue_to_address>

### Comment 2
<location path="src/routes/walkers/index.ts" line_range="276-285" />
<code_context>
+          ready,
+          description,
+        ],
+        (insertErr, insertResult) => {
+          if (insertResult) {
+            return reply.code(201).send({
+              message: "Walker created",
+            });
+          }
+          if (insertErr) {
+            return reply.code(503).send();
+          }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Prioritize handling `insertErr` before checking `insertResult` in the insert callback

Right now the callback returns a 201 whenever `insertResult` is truthy, even if `insertErr` is also set. To avoid returning success on error and to follow common Node.js patterns, handle `insertErr` first and return early, then handle the success case in the `else` branch.

```suggestion
        ],
        (insertErr, insertResult) => {
          if (insertErr) {
            return reply.code(503).send();
          }

          if (insertResult) {
            return reply.code(201).send({
              message: "Walker created",
            });
          }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

dm94 and others added 3 commits March 17, 2026 22:48
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Previously, when the request body lacked a 'name' field, the endpoint would send an empty 400 response. This change adds a descriptive "Bad Request" message to improve API clarity and client-side debugging.
Update the package version from 3.6.0 to 3.7.0 in preparation for a new release.
Also reformat the keywords array for improved readability.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
9.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@dm94 dm94 merged commit d3d4fa7 into main Mar 17, 2026
7 of 9 checks passed
@dm94 dm94 deleted the feat/addWalkerFromUser branch March 17, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant