Skip to content

feat: add project and associations image management#39

Open
BIA3IA wants to merge 2 commits into
mainfrom
web/images
Open

feat: add project and associations image management#39
BIA3IA wants to merge 2 commits into
mainfrom
web/images

Conversation

@BIA3IA

@BIA3IA BIA3IA commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Introduce functionality for uploading and validating logos in both project and association management

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The addAssociation, editAssociation, addProject, and editProject TRPC procedures now accept FormData instead of JSON inputs. New Zod schemas validate form fields and optional logo image files. Provided logo files are uploaded via uploadBlob using a new getImageExtension helper, storing the resulting blob URL instead of a raw string.

Changes

FormData-based logo uploads

Layer / File(s) Summary
Image extension helper
src/utils/web.ts
Adds exported getImageExtension(file: File) mapping PNG/JPEG/SVG MIME types to extensions, throwing on unsupported types.
Association logo upload
src/routers/web/associations.ts
Adds logoFileSchema and associationFormSchema; reworks addAssociation/editAssociation to parse FormData, coerce numeric fields, upload logo files via uploadBlob, and persist the blob URL or null.
Project logo upload
src/routers/web/projects.ts
Adds logoFileSchema and projectFormSchema (with link normalization); reworks addProject/editProject to parse FormData, coerce numeric fields, upload logo files via uploadBlob, and persist the blob URL or null.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Router
  participant FormSchema
  participant BlobStorage
  participant Database

  Client->>Router: submit FormData (fields + optional logo)
  Router->>FormSchema: validate and coerce fields
  alt logo file provided
    Router->>BlobStorage: uploadBlob(logo, getImageExtension)
    BlobStorage-->>Router: uploaded logo URL
  else no logo
    Router->>Router: use null for logo
  end
  Router->>Database: insert or update record with logo URL/null
Loading

Compact metadata

  • Lines changed: +120/-37 across three files
  • Estimated review effort: High

Related issues: None specified
Related PRs: None specified
Suggested labels: enhancement, backend
Suggested reviewers: None specified

Poem
A rabbit hops with FormData in paw,
No more plain strings, just files and blob-law,
PNG, JPEG, SVG take flight,
Uploaded to storage, URLs shining bright,
Associations and projects, logos anew—
Hop, hop, hooray, the schema rings true!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding image management for projects and associations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BIA3IA BIA3IA marked this pull request as ready for review July 1, 2026 08:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routers/web/associations.ts`:
- Around line 88-89: The blob upload mutations currently run through
publicProcedure and can call uploadBlob without auth, so switch these handlers
to an authenticated/admin-only procedure before any upload logic. Update the
relevant association mutation(s) in associations.ts that build uploadedLogo and
the other uploadBlob call so only authorized callers can reach Buffer.from(...),
getImageExtension(...), and uploadBlob.
- Around line 120-129: The edit flow in associations.ts currently clears the
existing logo when no new file is uploaded. Update the update path around the
uploadBlob handling and DB.update(ASSOCIATIONS).set(...) so logo is only changed
when a new file is provided, and otherwise left untouched; if intentional
removal is needed, add an explicit remove flag in the same update logic.
- Around line 29-34: The associationFormSchema currently allows empty strings
for name, descriptionIt, and descriptionEn because it uses z.string() directly.
Update associationFormSchema in associations.ts to trim these fields and enforce
non-empty content (for example by using nonempty/min length after trimming) so
blank association text cannot be submitted, while leaving logo optional as-is.

In `@src/routers/web/projects.ts`:
- Around line 55-56: The project mutation(s) in projects.ts are uploading blobs
from publicProcedure, so unauthenticated callers can reach uploadBlob and write
to Azure Blob storage. Move these upload paths behind an
authenticated/admin-only procedure before the uploadBlob call, and keep the
existing logo/image validation intact while ensuring only authorized users can
trigger the mutation.
- Around line 88-97: The edit flow in the project update logic is overwriting an
existing logo with null when no new file is uploaded. Update the PROJECTS update
path in the project router so the logo field is only changed when a new upload
is present, or add a dedicated removal flag to explicitly clear it; keep the
current logo unchanged for text-only edits. Use the existing uploadBlob handling
and the DB.update(PROJECTS) call as the place to gate the logo assignment.
- Around line 17-24: Project form validation still allows empty required text
fields and whitespace-only links; update projectFormSchema to trim title,
descriptionIt, and descriptionEn before validation so empty values are rejected,
and normalize link by trimming whitespace before converting an empty result to
null. Keep the change localized to the projectFormSchema in projects.ts and
preserve the existing logo and category handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 887f11a6-da90-4ae8-b39f-f63468db396c

📥 Commits

Reviewing files that changed from the base of the PR and between 7a1fda9 and 5de88ff.

📒 Files selected for processing (3)
  • src/routers/web/associations.ts
  • src/routers/web/projects.ts
  • src/utils/web.ts

Comment thread src/routers/web/associations.ts
Comment thread src/routers/web/associations.ts
Comment on lines +120 to +129
const uploadedLogo = logo
? await uploadBlob(Buffer.from(await logo.arrayBuffer()), getImageExtension(logo), logo.type)
: null

const [res] = await DB.update(ASSOCIATIONS)
.set({
name,
descriptionIt,
descriptionEn,
logo,
logo: uploadedLogo?.url ?? null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the existing logo on edit when no new file is uploaded.

logo is optional, but the edit path writes null when omitted, so text-only edits delete the current logo. Only set logo when replacing it, or add an explicit removal flag.

Proposed fix
-      const uploadedLogo = logo
-        ? await uploadBlob(Buffer.from(await logo.arrayBuffer()), getImageExtension(logo), logo.type)
-        : null
+      const uploadedLogoUrl = logo
+        ? (await uploadBlob(Buffer.from(await logo.arrayBuffer()), getImageExtension(logo), logo.type)).url
+        : undefined
 
       const [res] = await DB.update(ASSOCIATIONS)
         .set({
           name,
           descriptionIt,
           descriptionEn,
-          logo: uploadedLogo?.url ?? null,
+          ...(uploadedLogoUrl !== undefined ? { logo: uploadedLogoUrl } : {}),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const uploadedLogo = logo
? await uploadBlob(Buffer.from(await logo.arrayBuffer()), getImageExtension(logo), logo.type)
: null
const [res] = await DB.update(ASSOCIATIONS)
.set({
name,
descriptionIt,
descriptionEn,
logo,
logo: uploadedLogo?.url ?? null,
const uploadedLogoUrl = logo
? (await uploadBlob(Buffer.from(await logo.arrayBuffer()), getImageExtension(logo), logo.type)).url
: undefined
const [res] = await DB.update(ASSOCIATIONS)
.set({
name,
descriptionIt,
descriptionEn,
...(uploadedLogoUrl !== undefined ? { logo: uploadedLogoUrl } : {}),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routers/web/associations.ts` around lines 120 - 129, The edit flow in
associations.ts currently clears the existing logo when no new file is uploaded.
Update the update path around the uploadBlob handling and
DB.update(ASSOCIATIONS).set(...) so logo is only changed when a new file is
provided, and otherwise left untouched; if intentional removal is needed, add an
explicit remove flag in the same update logic.

Comment thread src/routers/web/projects.ts
Comment thread src/routers/web/projects.ts
Comment thread src/routers/web/projects.ts
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