Skip to content
5 changes: 3 additions & 2 deletions src/backend/src/controllers/rules.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,16 @@ export default class RulesController {

static async parseRuleset(req: Request, res: Response, next: NextFunction) {
try {
const { fileId, parserType } = req.body;
const { fileId, parserType, firstRulePage } = req.body;
const { rulesetId } = req.params as Record<string, string>;

const parseResult = await RulesService.parseRuleset(
req.currentUser,
req.organization.organizationId,
fileId,
rulesetId,
parserType
parserType,
firstRulePage
);

res.status(200).json(parseResult);
Expand Down
1 change: 1 addition & 0 deletions src/backend/src/routes/rules.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ rulesRouter.post(
'/ruleset/:rulesetId/parse',
nonEmptyString(body('fileId')),
nonEmptyString(body('parserType')), // 'FSAE' or 'FHE'
body('firstRulePage').optional().isInt({ min: 1 }),
validateInputs,
RulesController.parseRuleset
);
Expand Down
6 changes: 4 additions & 2 deletions src/backend/src/services/rules.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ export default class RulesService {
* @param fileId google drive file id of the ruleset pdf
* @param rulesetId id of the ruleset to save the parsed rules into
* @param parserType type of parser to use (FSAE or FHE)
* @param firstRulePage 1-indexed page rules start on; pages before this are skipped instead of parsed
* @returns array of saved rules with parent relationships established
* @throws AccessDeniedException if user lacks permissions or ruleset belongs to another organization
* @throws NotFoundException if ruleset doesn't exist
Expand All @@ -1566,7 +1567,8 @@ export default class RulesService {
organizationId: string,
fileId: string,
rulesetId: string,
parserType: 'FSAE' | 'FHE'
parserType: 'FSAE' | 'FHE',
firstRulePage?: number
): Promise<SharedRule[]> {
if (!(await userHasPermission(user.userId, organizationId, isLeadership))) {
throw new AccessDeniedException('You do not have permissions to upload and parse rulesets');
Expand Down Expand Up @@ -1604,7 +1606,7 @@ export default class RulesService {
}
let parsedRules: ParsedRule[];
try {
parsedRules = await parseRulesFromPdf(buffer, parserType);
parsedRules = await parseRulesFromPdf(buffer, parserType, firstRulePage);
if (parsedRules.length === 0) {
throw new HttpException(400, 'No rules found in provided file');
}
Expand Down
Loading
Loading