forked from Yara724/api
Fixed registrar and field expert
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
@@ -90,14 +89,6 @@ export class ExpertInitiatedBlameMirrorController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: "[Expert mirror] List my expert-initiated blame files",
|
||||
})
|
||||
async list(@CurrentUser() expert: any) {
|
||||
return this.requestManagementService.getMyExpertInitiatedFilesV2(expert);
|
||||
}
|
||||
|
||||
@Post("send-link/:requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiBody({ type: SendExpertInitiatedLinkV2Dto })
|
||||
@@ -420,14 +411,4 @@ export class ExpertInitiatedBlameMirrorController {
|
||||
fields,
|
||||
);
|
||||
}
|
||||
|
||||
@Get(":requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiOperation({ summary: "[Expert mirror] Get one blame request" })
|
||||
async getOne(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() expert: any,
|
||||
) {
|
||||
return this.requestManagementService.getBlameRequestV2(requestId, expert);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
@@ -86,14 +85,6 @@ export class RegistrarBlameMirrorController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: "[Registrar mirror] List my registrar-initiated blame files",
|
||||
})
|
||||
async list(@CurrentUser() registrar: any) {
|
||||
return this.requestManagementService.getMyExpertInitiatedFilesV2(registrar);
|
||||
}
|
||||
|
||||
@Post("send-party-otp/:requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiBody({ type: SendPartyOtpDto })
|
||||
@@ -402,17 +393,4 @@ export class RegistrarBlameMirrorController {
|
||||
sign,
|
||||
);
|
||||
}
|
||||
|
||||
@Get(":requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiOperation({ summary: "[Registrar mirror] Get one blame request" })
|
||||
async getOne(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() registrar: any,
|
||||
) {
|
||||
return this.requestManagementService.getBlameRequestV2(
|
||||
requestId,
|
||||
registrar,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5022,21 +5022,46 @@ export class RequestManagementService {
|
||||
? { "parties.person.phoneNumber": user.username }
|
||||
: null;
|
||||
|
||||
const filters = [userIdFilter, phoneFilter].filter(Boolean);
|
||||
if (filters.length === 0) {
|
||||
const orConditions: Record<string, unknown>[] = [];
|
||||
if (userIdFilter) orConditions.push(userIdFilter);
|
||||
if (phoneFilter) orConditions.push(phoneFilter);
|
||||
|
||||
if (user?.role === RoleEnum.FIELD_EXPERT && user?.sub) {
|
||||
orConditions.push({
|
||||
expertInitiated: true,
|
||||
initiatedByFieldExpertId: new Types.ObjectId(user.sub),
|
||||
});
|
||||
} else if (user?.role === RoleEnum.REGISTRAR && user?.sub) {
|
||||
orConditions.push({
|
||||
registrarInitiated: true,
|
||||
initiatedByRegistrarId: new Types.ObjectId(user.sub),
|
||||
});
|
||||
}
|
||||
|
||||
if (orConditions.length === 0) {
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
|
||||
const requests = await this.blameRequestDbService.find(
|
||||
filters.length === 1 ? (filters[0] as any) : ({ $or: filters } as any),
|
||||
orConditions.length === 1
|
||||
? (orConditions[0] as any)
|
||||
: ({ $or: orConditions } as any),
|
||||
{
|
||||
select:
|
||||
"publicId requestNo type status blameStatus createdAt updatedAt parties",
|
||||
"publicId requestNo type status blameStatus createdAt updatedAt parties expertInitiated registrarInitiated initiatedByFieldExpertId initiatedByRegistrarId creationMethod",
|
||||
},
|
||||
);
|
||||
|
||||
const enriched = requests.map((req: any) => {
|
||||
const party = req.parties.find(
|
||||
const isInitiator =
|
||||
(user?.role === RoleEnum.FIELD_EXPERT &&
|
||||
req.expertInitiated &&
|
||||
String(req.initiatedByFieldExpertId) === String(user.sub)) ||
|
||||
(user?.role === RoleEnum.REGISTRAR &&
|
||||
req.registrarInitiated &&
|
||||
String(req.initiatedByRegistrarId) === String(user.sub));
|
||||
|
||||
const party = req.parties?.find(
|
||||
(p: any) =>
|
||||
(p?.person?.userId &&
|
||||
String(p.person.userId) === String(user.sub)) ||
|
||||
@@ -5045,11 +5070,12 @@ export class RequestManagementService {
|
||||
|
||||
const obj = req.toObject();
|
||||
|
||||
delete obj.parties; // remove parties completely
|
||||
delete obj.parties;
|
||||
|
||||
return {
|
||||
...obj,
|
||||
userSide: party?.role ?? null,
|
||||
initiatedByMe: isInitiator,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -77,11 +77,11 @@ export class RequestManagementV2Controller {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Roles(RoleEnum.USER, RoleEnum.FIELD_EXPERT)
|
||||
@Roles(RoleEnum.USER, RoleEnum.FIELD_EXPERT, RoleEnum.REGISTRAR)
|
||||
@ApiOperation({
|
||||
summary: "List my blame requests (V2)",
|
||||
description:
|
||||
"All blame files for the current user. Optional query: `search`, `sortBy` (publicId | createdAt | requestNo | status), `sortOrder`, `page`, `limit`. Without `page`/`limit`, returns the full filtered list.",
|
||||
"Party-owned blame files, or files initiated by the current FIELD_EXPERT / REGISTRAR. Optional query: `search`, `sortBy` (publicId | createdAt | requestNo | status), `sortOrder`, `page`, `limit`.",
|
||||
})
|
||||
async getAllBlameRequestsV2(
|
||||
@CurrentUser() user: any,
|
||||
@@ -91,16 +91,16 @@ export class RequestManagementV2Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one blame request by id. Allowed for the request owner (party) or the initiating field expert.
|
||||
* Get one blame request by id. Allowed for a party, or the initiating field expert / registrar.
|
||||
*/
|
||||
@Get(":requestId")
|
||||
@ApiOperation({
|
||||
summary: "Get one blame request (v2)",
|
||||
description:
|
||||
"Returns a minimal, user-safe payload: requestNo, publicId, type, status, blameStatus, workflow, parties (PII stripped), expert (with **expertName**), carBodyInsuranceDetail, plus **claimCreation** ({ hasClaim, shouldGuideToCreateClaim }). History and other internal fields are omitted.",
|
||||
"Returns a minimal payload for parties or the initiating FIELD_EXPERT / REGISTRAR: requestNo, publicId, type, status, blameStatus, workflow, parties (PII stripped for parties; full for initiator), expert, carBodyInsuranceDetail, plus **claimCreation**.",
|
||||
})
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@Roles(RoleEnum.USER, RoleEnum.FIELD_EXPERT)
|
||||
@Roles(RoleEnum.USER, RoleEnum.FIELD_EXPERT, RoleEnum.REGISTRAR)
|
||||
async getBlameRequestV2(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() user: any,
|
||||
|
||||
Reference in New Issue
Block a user