forked from Yara724/api
Enforce claim beneficiary access and retire unused legacy APIs
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { WorkflowStepModel, WorkflowStepsDB } from '../schema/workflow-step.schema';
|
||||
import { CreateWorkflowStepDto } from '../../dto/create-workflow-step.dto';
|
||||
import { UpdateWorkflowStepDto } from '../../dto/update-workflow-step.dto';
|
||||
import { WorkflowStep } from 'src/Types&Enums/blame-request-management/blameWorkflow-steps.enum';
|
||||
import { ClaimWorkflowStep } from 'src/Types&Enums/claim-request-management/claim-workflow-steps.enum';
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { Model } from "mongoose";
|
||||
import { WorkflowStep } from "src/Types&Enums/blame-request-management/blameWorkflow-steps.enum";
|
||||
import { ClaimWorkflowStep } from "src/Types&Enums/claim-request-management/claim-workflow-steps.enum";
|
||||
import { CreateWorkflowStepDto } from "../../dto/create-workflow-step.dto";
|
||||
import { UpdateWorkflowStepDto } from "../../dto/update-workflow-step.dto";
|
||||
import {
|
||||
WorkflowStepModel,
|
||||
WorkflowStepsDB,
|
||||
} from "../schema/workflow-step.schema";
|
||||
|
||||
// Type alias for combined workflow steps
|
||||
type AnyWorkflowStep = WorkflowStep | ClaimWorkflowStep;
|
||||
@@ -39,10 +42,7 @@ export class WorkflowStepDbService {
|
||||
* Find all workflow steps including inactive ones
|
||||
*/
|
||||
async findAllIncludingInactive(): Promise<WorkflowStepModel[]> {
|
||||
return await this.workflowStepModel
|
||||
.find()
|
||||
.sort({ stepNumber: 1 })
|
||||
.exec();
|
||||
return await this.workflowStepModel.find().sort({ stepNumber: 1 }).exec();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,31 +55,28 @@ export class WorkflowStepDbService {
|
||||
/**
|
||||
* Find a workflow step by step key (supports both blame and claim)
|
||||
*/
|
||||
async findByStepKey(stepKey: AnyWorkflowStep): Promise<WorkflowStepModel | null> {
|
||||
async findByStepKey(
|
||||
stepKey: AnyWorkflowStep,
|
||||
): Promise<WorkflowStepModel | null> {
|
||||
return await this.workflowStepModel.findOne({ stepKey }).exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a workflow step by step number
|
||||
*/
|
||||
async findByStepNumber(stepNumber: number): Promise<WorkflowStepModel | null> {
|
||||
async findByStepNumber(
|
||||
stepNumber: number,
|
||||
): Promise<WorkflowStepModel | null> {
|
||||
return await this.workflowStepModel.findOne({ stepNumber }).exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find steps by category
|
||||
*/
|
||||
async findByCategory(category: string): Promise<WorkflowStepModel[]> {
|
||||
return await this.workflowStepModel
|
||||
.find({ category, isActive: true })
|
||||
.sort({ stepNumber: 1 })
|
||||
.exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a workflow step by ID
|
||||
*/
|
||||
async update(id: string, updateDto: UpdateWorkflowStepDto): Promise<WorkflowStepModel | null> {
|
||||
async update(
|
||||
id: string,
|
||||
updateDto: UpdateWorkflowStepDto,
|
||||
): Promise<WorkflowStepModel | null> {
|
||||
return await this.workflowStepModel
|
||||
.findByIdAndUpdate(id, updateDto, { new: true })
|
||||
.exec();
|
||||
@@ -133,24 +130,13 @@ export class WorkflowStepDbService {
|
||||
return await this.workflowStepModel.bulkWrite(bulkOps as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next step number
|
||||
*/
|
||||
async getNextStepNumber(): Promise<number> {
|
||||
const maxStep = await this.workflowStepModel
|
||||
.findOne()
|
||||
.sort({ stepNumber: -1 })
|
||||
.select('stepNumber')
|
||||
.exec();
|
||||
|
||||
return maxStep ? maxStep.stepNumber + 1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a step exists (supports both blame and claim)
|
||||
*/
|
||||
async exists(stepKey: AnyWorkflowStep): Promise<boolean> {
|
||||
const count = await this.workflowStepModel.countDocuments({ stepKey }).exec();
|
||||
const count = await this.workflowStepModel
|
||||
.countDocuments({ stepKey })
|
||||
.exec();
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user