-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PER-9866 [back-end] Endpoint for admins to update environment configu…
…ration New endpoint to update a feature-flag. There are validations on the globallyEnabled and description fields Unit and functional tests are covering all scenarios
- Loading branch information
iuliandanea
committed
Oct 28, 2024
1 parent
d78b2b5
commit 83cd2a3
Showing
7 changed files
with
434 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/api/src/feature_flag/queries/update_feature_flag.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
UPDATE feature_flag | ||
SET | ||
description = :description, | ||
globally_enabled = :globally_enabled, | ||
updated_at = CURRENT_TIMESTAMP | ||
WHERE ( | ||
id = :id | ||
) RETURNING | ||
id, | ||
name, | ||
description, | ||
globally_enabled AS "globallyEnabled", | ||
created_at AS "createdAt", | ||
updated_at AS "updatedAt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { logger } from "@stela/logger"; | ||
import createError from "http-errors"; | ||
import type { FeatureFlagRow, UpdateFeatureFlagRequest } from "../models"; | ||
import { db } from "../../database"; | ||
|
||
export const updateFeatureFlag = async ( | ||
featureFlagId: string, | ||
featureFlagData: UpdateFeatureFlagRequest | ||
): Promise<FeatureFlagRow> => { | ||
const result = await db | ||
.sql<FeatureFlagRow>("feature_flag.queries.update_feature_flag", { | ||
id: featureFlagId, | ||
description: featureFlagData.description, | ||
globally_enabled: featureFlagData.globallyEnabled, | ||
}) | ||
.catch((err) => { | ||
logger.error(err); | ||
throw new createError.InternalServerError( | ||
"Failed to update feature flag" | ||
); | ||
}); | ||
|
||
if (result.rows[0] === undefined) { | ||
throw new createError.NotFound("Feature flag not found"); | ||
} | ||
|
||
return result.rows[0]; | ||
}; | ||
|
||
export const updateFeatureService = { | ||
updateFeatureFlag, | ||
}; |
Oops, something went wrong.