Skip to content

Commit 5fd69e0

Browse files
refactor:resolved PR comments
1 parent 925f875 commit 5fd69e0

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

api/src/services/migration.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ const deleteTestStack = async (req: Request): Promise<LoginServiceType> => {
279279
const startTestMigration = async (req: Request): Promise<any> => {
280280
const { orgId, projectId } = req?.params ?? {};
281281
const { region, user_id, is_sso } = req?.body?.token_payload ?? {};
282+
283+
284+
if (is_sso !== true && is_sso !== false) {
285+
throw new BadRequestError(
286+
'Invalid token_payload.is_sso; expected a boolean value.',
287+
);
288+
}
289+
282290
await ProjectModelLowdb.read();
283291
const project: any = ProjectModelLowdb.chain
284292
.get('projects')
@@ -654,6 +662,13 @@ const startTestMigration = async (req: Request): Promise<any> => {
654662
const startMigration = async (req: Request): Promise<any> => {
655663
const { orgId, projectId } = req?.params ?? {};
656664
const { region, user_id, is_sso } = req?.body?.token_payload ?? {};
665+
666+
if (typeof is_sso !== 'boolean') {
667+
throw new BadRequestError(
668+
'Missing or invalid SSO flag in token payload: expected boolean "is_sso".',
669+
);
670+
}
671+
657672
await ProjectModelLowdb.read();
658673
const project: any = ProjectModelLowdb.chain
659674
.get('projects')

api/src/utils/content-type-creator.utils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,27 @@ const writeGlobalField = async (schema: any, globalSave: string) => {
10261026
}
10271027
};
10281028

1029+
const resolveIsSsoFlag = (is_sso: any): boolean => {
1030+
if (typeof is_sso === 'boolean') {
1031+
return is_sso;
1032+
}
1033+
1034+
if (is_sso === 'true') {
1035+
return true;
1036+
}
1037+
1038+
if (is_sso === 'false') {
1039+
return false;
1040+
}
1041+
1042+
throw new Error(
1043+
`Invalid token_payload.is_sso in existingCtMapper; expected boolean, received: ${JSON.stringify(is_sso)}`
1044+
);
1045+
};
1046+
10291047
const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region, user_id, is_sso, type}: any) => {
10301048
try {
1049+
const normalizedIsSso = resolveIsSsoFlag(is_sso);
10311050
const ctUid = keyMapper?.[contentTypeUid];
10321051

10331052
if(type === 'global_field') {
@@ -1041,7 +1060,7 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
10411060
token_payload: {
10421061
region,
10431062
user_id,
1044-
is_sso
1063+
is_sso: normalizedIsSso
10451064
}
10461065
}
10471066
}
@@ -1057,7 +1076,7 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
10571076
token_payload: {
10581077
region,
10591078
user_id,
1060-
is_sso
1079+
is_sso: normalizedIsSso
10611080
}
10621081
}
10631082
}

0 commit comments

Comments
 (0)