Skip to content

Commit

Permalink
TSC
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfarrell76 committed Nov 27, 2024
1 parent b15c31b commit 1279b04
Show file tree
Hide file tree
Showing 12 changed files with 1,195 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@transcend-io/handlebars-utils": "^1.1.0",
"@transcend-io/internationalization": "^1.6.0",
"@transcend-io/persisted-state": "^1.0.4",
"@transcend-io/privacy-types": "^4.93.0",
"@transcend-io/privacy-types": "^4.94.0",
"@transcend-io/secret-value": "^1.2.0",
"@transcend-io/type-utils": "^1.5.0",
"bluebird": "^3.7.2",
Expand Down
40 changes: 21 additions & 19 deletions src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,18 +1526,6 @@ export const RiskAssignmentInput = t.partial({
/** Type override */
export type RiskAssignmentInput = t.TypeOf<typeof RiskAssignmentInput>;

export const RiskLogicInput = t.type({
/** The risk to assign to this question if the response matches the provided logic */
'risk-assignment': RiskAssignmentInput,
/** The operator to use when comparing the response to the operands */
'comparison-operator': valuesOf(ComparisonOperator),
/** The values to compare the response to */
'comparison-operands': t.array(t.string),
});

/** Type override */
export type RiskLogicInput = t.TypeOf<typeof RiskLogicInput>;

export const AssessmentAnswerOptionInput = t.type({
/** Value of answer */
value: t.string,
Expand Down Expand Up @@ -1569,7 +1557,7 @@ export const AssessmentSectionQuestionInput = t.intersection([
/** Display logic for the question */
'display-logic': AssessmentDisplayLogicInput,
/** Risk logic for the question */
'risk-logic': t.array(RiskLogicInput),
'risk-logic': t.array(t.string),
/** Risk category titles for the question */
'risk-categories': t.array(t.string),
/** Risk framework titles for the question */
Expand Down Expand Up @@ -1598,12 +1586,24 @@ export type AssessmentSectionQuestionInput = t.TypeOf<
typeof AssessmentSectionQuestionInput
>;

export const AssessmentSectionInput = t.type({
/** The title of the assessment section */
title: t.string,
/** The questions in the assessment section */
questions: t.array(AssessmentSectionQuestionInput),
});
export const AssessmentSectionInput = t.intersection([
t.type({
/** The title of the assessment section */
title: t.string,
/** The questions in the assessment section */
questions: t.array(AssessmentSectionQuestionInput),
}),
t.partial({
/** Email address of those assigned */
assignees: t.array(t.string),
/** Email address of those externally assigned */
'external-assignees': t.array(t.string),
/** Status of section */
status: t.string,
/** Whether assessment is reviewed */
'is-reviewed': t.boolean,
}),
]);

/** Type override */
export type AssessmentSectionInput = t.TypeOf<typeof AssessmentSectionInput>;
Expand Down Expand Up @@ -1640,6 +1640,8 @@ export const AssessmentTemplateInput = t.intersection([
creator: t.string,
/** Whether the template is in a locked status */
locked: t.boolean,
/** ID of parent template this was cloned from */
'parent-id': t.string,
/** Whether the template is archived */
archived: t.boolean,
/** The date that the assessment was created */
Expand Down
83 changes: 83 additions & 0 deletions src/graphql/fetchAllAssessmentTemplates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { GraphQLClient } from 'graphql-request';
import { ASSESSMENT_TEMPLATES } from './gqls';
import { makeGraphQLRequest } from './makeGraphQLRequest';
import type {
AssessmentSection,
RetentionSchedule,
UserPreview,
} from './fetchAllAssessments';
import {
AssessmentFormTemplateSource,
AssessmentFormTemplateStatus,
} from '@transcend-io/privacy-types';

/**
* Represents an assessment template with various properties and metadata.
*/
export interface AssessmentTemplate {
/** The ID of the assessment template */
id: string;
/** The user who created the assessment template */
creator: UserPreview;
/** The user who last edited the assessment template */
lastEditor: UserPreview;
/** The title of the assessment template */
title: string;
/** The description of the assessment template */
description: string;
/** The current status of the assessment template */
status: AssessmentFormTemplateStatus;
/** The source fo the form template */
source: AssessmentFormTemplateSource;
/** ID of parent template */
parentId: string;
/** Indicates if the assessment template is locked */
isLocked: boolean;
/** Indicates if the assessment template is archived */
isArchived: boolean;
/** The date when the assessment template was created */
createdAt: string;
/** The date when the assessment template was last updated */
updatedAt: string;
/** The retention schedule of the assessment template */
retentionSchedule: RetentionSchedule;
/** The sections of the assessment template */
sections: AssessmentSection[];
}

const PAGE_SIZE = 20;

/**
* Fetch all assessment templates in the organization
*
* @param client - GraphQL client
* @returns All assessment templates in the organization
*/
export async function fetchAllAssessmentTemplates(
client: GraphQLClient,
): Promise<AssessmentTemplate[]> {
const assessmentTemplates: AssessmentTemplate[] = [];
let offset = 0;

let shouldContinue = false;
do {
const {
assessmentFormTemplates: { nodes },
// eslint-disable-next-line no-await-in-loop
} = await makeGraphQLRequest<{
/** Templates */
assessmentFormTemplates: {
/** Nodes */
nodes: AssessmentTemplate[];
};
}>(client, ASSESSMENT_TEMPLATES, {
first: PAGE_SIZE,
offset,
});
assessmentTemplates.push(...nodes);
offset += PAGE_SIZE;
shouldContinue = nodes.length === PAGE_SIZE;
} while (shouldContinue);

return assessmentTemplates.sort((a, b) => a.title.localeCompare(b.title));
}
Loading

0 comments on commit 1279b04

Please sign in to comment.