forked from Yara724/api
Tidied up the packages and unused modules
This commit is contained in:
@@ -113,33 +113,33 @@ export class ExpertInitiatedController {
|
||||
);
|
||||
}
|
||||
|
||||
@ApiOperation({ deprecated: true })
|
||||
@Post("create")
|
||||
@ApiOperation({
|
||||
summary: "Create expert-initiated blame file",
|
||||
description:
|
||||
"Expert creates an initial incomplete blame file. Can be IN_PERSON (expert fills all info) or LINK (expert sends link to users).",
|
||||
})
|
||||
@ApiBody({ type: CreateExpertInitiatedFileDto })
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: "File created successfully",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
requestId: { type: "string" },
|
||||
},
|
||||
},
|
||||
})
|
||||
async createExpertInitiatedFile(
|
||||
@CurrentUser() expert: any,
|
||||
@Body() dto: CreateExpertInitiatedFileDto,
|
||||
) {
|
||||
return await this.requestManagementService.createExpertInitiatedFile(
|
||||
expert,
|
||||
dto,
|
||||
);
|
||||
}
|
||||
// @ApiOperation({ deprecated: true })
|
||||
// @Post("create")
|
||||
// @ApiOperation({
|
||||
// summary: "Create expert-initiated blame file",
|
||||
// description:
|
||||
// "Expert creates an initial incomplete blame file. Can be IN_PERSON (expert fills all info) or LINK (expert sends link to users).",
|
||||
// })
|
||||
// @ApiBody({ type: CreateExpertInitiatedFileDto })
|
||||
// @ApiResponse({
|
||||
// status: 201,
|
||||
// description: "File created successfully",
|
||||
// schema: {
|
||||
// type: "object",
|
||||
// properties: {
|
||||
// requestId: { type: "string" },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// async createExpertInitiatedFile(
|
||||
// @CurrentUser() expert: any,
|
||||
// @Body() dto: CreateExpertInitiatedFileDto,
|
||||
// ) {
|
||||
// return await this.requestManagementService.createExpertInitiatedFile(
|
||||
// expert,
|
||||
// dto,
|
||||
// );
|
||||
// }
|
||||
|
||||
@ApiOperation({ deprecated: true })
|
||||
@Post("complete-form-third-party/:requestId")
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
} from "@nestjs/common";
|
||||
import { ExternalExceptionFilter } from "@nestjs/core/exceptions/external-exception-filter";
|
||||
import { Types } from "mongoose";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
import { ClientService } from "src/client/client.service";
|
||||
import { AddPlateDto } from "src/profile/dto/user/AddPlateDto";
|
||||
import {
|
||||
@@ -1588,28 +1587,28 @@ export class RequestManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
async createRequest(user, type) {
|
||||
const reqNumber = new ShortUniqueId({ counter: 1 });
|
||||
const publicId = await this.publicIdService.generateRequestPublicId();
|
||||
const createRequest = await this.requestManagementDbService.create({
|
||||
firstPartyDetails: {
|
||||
firstPartyId: user.sub,
|
||||
firstPartyPhoneNumber: user.username,
|
||||
firstPartyCertificate: null,
|
||||
},
|
||||
currentStep: StepsEnum.createRequest,
|
||||
nextStep:
|
||||
type === "THIRD_PARTY"
|
||||
? StepsEnum.F_InitialForm
|
||||
: StepsEnum.CarBodyForm,
|
||||
requestNumber: reqNumber.rnd(),
|
||||
publicId,
|
||||
blameStatus: ReqBlameStatus.PendingForFirstParty,
|
||||
lockFile: false,
|
||||
type,
|
||||
});
|
||||
return { requestId: createRequest["_id"] };
|
||||
}
|
||||
// async createRequest(user, type) {
|
||||
// const reqNumber = new ShortUniqueId({ counter: 1 });
|
||||
// const publicId = await this.publicIdService.generateRequestPublicId();
|
||||
// const createRequest = await this.requestManagementDbService.create({
|
||||
// firstPartyDetails: {
|
||||
// firstPartyId: user.sub,
|
||||
// firstPartyPhoneNumber: user.username,
|
||||
// firstPartyCertificate: null,
|
||||
// },
|
||||
// currentStep: StepsEnum.createRequest,
|
||||
// nextStep:
|
||||
// type === "THIRD_PARTY"
|
||||
// ? StepsEnum.F_InitialForm
|
||||
// : StepsEnum.CarBodyForm,
|
||||
// requestNumber: reqNumber.rnd(),
|
||||
// publicId,
|
||||
// blameStatus: ReqBlameStatus.PendingForFirstParty,
|
||||
// lockFile: false,
|
||||
// type,
|
||||
// });
|
||||
// return { requestId: createRequest["_id"] };
|
||||
// }
|
||||
|
||||
async initialFormStep(
|
||||
reqBody: InitialFormDto,
|
||||
@@ -3617,106 +3616,106 @@ export class RequestManagementService {
|
||||
/**
|
||||
* Expert creates an initial blame file (incomplete, waiting for completion)
|
||||
*/
|
||||
async createExpertInitiatedFile(
|
||||
expert: any,
|
||||
dto: CreateExpertInitiatedFileDto,
|
||||
): Promise<{ requestId: string }> {
|
||||
const reqNumber = new ShortUniqueId({ counter: 1 });
|
||||
const expertId = new Types.ObjectId(expert.sub);
|
||||
const publicId = await this.publicIdService.generateRequestPublicId();
|
||||
// async createExpertInitiatedFile(
|
||||
// expert: any,
|
||||
// dto: CreateExpertInitiatedFileDto,
|
||||
// ): Promise<{ requestId: string }> {
|
||||
// const reqNumber = new ShortUniqueId({ counter: 1 });
|
||||
// const expertId = new Types.ObjectId(expert.sub);
|
||||
// const publicId = await this.publicIdService.generateRequestPublicId();
|
||||
|
||||
// For LINK method, validate phone numbers are provided
|
||||
if (dto.creationMethod === CreationMethod.LINK) {
|
||||
if (!dto.firstPartyPhoneNumber) {
|
||||
throw new BadRequestException(
|
||||
"First party phone number is required for LINK method",
|
||||
);
|
||||
}
|
||||
if (dto.type === "THIRD_PARTY" && !dto.secondPartyPhoneNumber) {
|
||||
throw new BadRequestException(
|
||||
"Second party phone number is required for LINK method with THIRD_PARTY type",
|
||||
);
|
||||
}
|
||||
if (
|
||||
dto.type === "THIRD_PARTY" &&
|
||||
dto.firstPartyPhoneNumber === dto.secondPartyPhoneNumber
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"First and second party phone numbers must be different",
|
||||
);
|
||||
}
|
||||
}
|
||||
// // For LINK method, validate phone numbers are provided
|
||||
// if (dto.creationMethod === CreationMethod.LINK) {
|
||||
// if (!dto.firstPartyPhoneNumber) {
|
||||
// throw new BadRequestException(
|
||||
// "First party phone number is required for LINK method",
|
||||
// );
|
||||
// }
|
||||
// if (dto.type === "THIRD_PARTY" && !dto.secondPartyPhoneNumber) {
|
||||
// throw new BadRequestException(
|
||||
// "Second party phone number is required for LINK method with THIRD_PARTY type",
|
||||
// );
|
||||
// }
|
||||
// if (
|
||||
// dto.type === "THIRD_PARTY" &&
|
||||
// dto.firstPartyPhoneNumber === dto.secondPartyPhoneNumber
|
||||
// ) {
|
||||
// throw new BadRequestException(
|
||||
// "First and second party phone numbers must be different",
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// For LINK method, create/get users and set their IDs
|
||||
let firstPartyUserId: Types.ObjectId | undefined;
|
||||
let secondPartyUserId: Types.ObjectId | undefined;
|
||||
let firstPartyDetails: any = {};
|
||||
let secondPartyDetails: any = {};
|
||||
// // For LINK method, create/get users and set their IDs
|
||||
// let firstPartyUserId: Types.ObjectId | undefined;
|
||||
// let secondPartyUserId: Types.ObjectId | undefined;
|
||||
// let firstPartyDetails: any = {};
|
||||
// let secondPartyDetails: any = {};
|
||||
|
||||
if (dto.creationMethod === CreationMethod.LINK) {
|
||||
// Get or create first party user
|
||||
firstPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
dto.firstPartyPhoneNumber,
|
||||
);
|
||||
firstPartyDetails = {
|
||||
firstPartyId: firstPartyUserId,
|
||||
firstPartyPhoneNumber: dto.firstPartyPhoneNumber,
|
||||
};
|
||||
// if (dto.creationMethod === CreationMethod.LINK) {
|
||||
// // Get or create first party user
|
||||
// firstPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
// dto.firstPartyPhoneNumber,
|
||||
// );
|
||||
// firstPartyDetails = {
|
||||
// firstPartyId: firstPartyUserId,
|
||||
// firstPartyPhoneNumber: dto.firstPartyPhoneNumber,
|
||||
// };
|
||||
|
||||
// Get or create second party user for THIRD_PARTY
|
||||
if (dto.type === "THIRD_PARTY" && dto.secondPartyPhoneNumber) {
|
||||
secondPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
dto.secondPartyPhoneNumber,
|
||||
);
|
||||
secondPartyDetails = {
|
||||
secondPartyId: secondPartyUserId,
|
||||
secondPartyPhoneNumber: dto.secondPartyPhoneNumber,
|
||||
};
|
||||
}
|
||||
}
|
||||
// // Get or create second party user for THIRD_PARTY
|
||||
// if (dto.type === "THIRD_PARTY" && dto.secondPartyPhoneNumber) {
|
||||
// secondPartyUserId = await this.getOrCreateUserByPhoneNumber(
|
||||
// dto.secondPartyPhoneNumber,
|
||||
// );
|
||||
// secondPartyDetails = {
|
||||
// secondPartyId: secondPartyUserId,
|
||||
// secondPartyPhoneNumber: dto.secondPartyPhoneNumber,
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
const createRequest = await this.requestManagementDbService.create({
|
||||
requestNumber: reqNumber.rnd(),
|
||||
publicId,
|
||||
type: dto.type,
|
||||
expertInitiated: true,
|
||||
initiatedBy: expertId,
|
||||
creationMethod: dto.creationMethod,
|
||||
filledBy: dto.creationMethod === CreationMethod.IN_PERSON ? FilledBy.EXPERT : FilledBy.CUSTOMER,
|
||||
currentStep: StepsEnum.createRequest,
|
||||
nextStep:
|
||||
dto.type === "THIRD_PARTY"
|
||||
? StepsEnum.F_InitialForm
|
||||
: StepsEnum.CarBodyForm,
|
||||
blameStatus: ReqBlameStatus.PendingForFirstParty,
|
||||
lockFile: false,
|
||||
history: [],
|
||||
assignedExpertId: expertId, // Auto-assign to initiating expert
|
||||
...(dto.creationMethod === CreationMethod.LINK && {
|
||||
firstPartyDetails,
|
||||
...(dto.type === "THIRD_PARTY" && { secondPartyDetails }),
|
||||
}),
|
||||
});
|
||||
// const createRequest = await this.requestManagementDbService.create({
|
||||
// requestNumber: reqNumber.rnd(),
|
||||
// publicId,
|
||||
// type: dto.type,
|
||||
// expertInitiated: true,
|
||||
// initiatedBy: expertId,
|
||||
// creationMethod: dto.creationMethod,
|
||||
// filledBy: dto.creationMethod === CreationMethod.IN_PERSON ? FilledBy.EXPERT : FilledBy.CUSTOMER,
|
||||
// currentStep: StepsEnum.createRequest,
|
||||
// nextStep:
|
||||
// dto.type === "THIRD_PARTY"
|
||||
// ? StepsEnum.F_InitialForm
|
||||
// : StepsEnum.CarBodyForm,
|
||||
// blameStatus: ReqBlameStatus.PendingForFirstParty,
|
||||
// lockFile: false,
|
||||
// history: [],
|
||||
// assignedExpertId: expertId, // Auto-assign to initiating expert
|
||||
// ...(dto.creationMethod === CreationMethod.LINK && {
|
||||
// firstPartyDetails,
|
||||
// ...(dto.type === "THIRD_PARTY" && { secondPartyDetails }),
|
||||
// }),
|
||||
// });
|
||||
|
||||
const requestId = (createRequest as any)._id.toString();
|
||||
// const requestId = (createRequest as any)._id.toString();
|
||||
|
||||
// Add history event
|
||||
await this.addHistoryEvent(
|
||||
requestId,
|
||||
"FILE_CREATED_BY_EXPERT",
|
||||
expertId,
|
||||
`${expert.firstName} ${expert.lastName}`,
|
||||
"expert",
|
||||
{
|
||||
creationMethod: dto.creationMethod,
|
||||
type: dto.type,
|
||||
},
|
||||
);
|
||||
// // Add history event
|
||||
// await this.addHistoryEvent(
|
||||
// requestId,
|
||||
// "FILE_CREATED_BY_EXPERT",
|
||||
// expertId,
|
||||
// `${expert.firstName} ${expert.lastName}`,
|
||||
// "expert",
|
||||
// {
|
||||
// creationMethod: dto.creationMethod,
|
||||
// type: dto.type,
|
||||
// },
|
||||
// );
|
||||
|
||||
return {
|
||||
requestId,
|
||||
};
|
||||
}
|
||||
// return {
|
||||
// requestId,
|
||||
// };
|
||||
// }
|
||||
|
||||
/**
|
||||
* V2: Field expert creates an expert-initiated blame file (BlameRequest with workflow).
|
||||
|
||||
Reference in New Issue
Block a user