Skip to content

Dev: fix Type error related for admin user updates of parent organization name #2555

Description

@SAUMILDHANKAR

Overview

We need to fix the type error related to admin user updates of the parent organization name, so that we don't have either failed requests or possible security vunerability.

Details

  • There is a type error related to PR added schema and route #2529, and a missing validation check in the parentOrganizationController.update method.
    As noted in the review comment, the handler should include a required field check (id, name, tenantId) at the start, returning a 400 error if any are missing.
    The type definition should also follow the pattern used in the insert handler for consistent type safety.

parent organization example:
Salvation army has several listing with local chapters


Action Items

  • Add a required field checker to parentOrganizationController.update for id, name, and tenantId
  • Update the type definition to align with the insert handler pattern
  • Test the update endpoint for both valid and invalid inputs
  • Verify type safety and proper error handling

Example Implementation

const update: RequestHandler<
  { id: string },
  { success: boolean } | { error: string },
  ParentOrganization,
  never
> = async (req, res) => {
  const { id, name, tenantId } = req.body;
  if (!id || !name || !tenantId) {
    return res.status(400).json({ error: "Missing required fields." });
  }

  try {
    await parentOrganizationService.update(req.body);
    res.status(200).json({ success: true });
  } catch (err: any) {
    console.error(err);
    res.status(500).json({ error: "Internal server error." });
  }
};

Resources/Instructions


Metadata

Metadata

Assignees

Type

No type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions