1
0
forked from Yara724/api

update the user side for the requests list

This commit is contained in:
Soheil Hajizadeh
2026-03-29 12:21:01 +03:30
parent 672ec25438
commit b2391751f0

View File

@@ -3854,24 +3854,40 @@ export class RequestManagementService {
}
async getAllBlameRequestsV2(user: any): Promise<any> {
console.log(user)
try {
const requests = await this.blameRequestDbService.find({
parties: {
$elemMatch: {
'person.userId': new Types.ObjectId(user.sub)
}
const requests = await this.blameRequestDbService.find(
{
"parties.person.userId": new Types.ObjectId(user.sub),
},
{
select: "requestNo type status blameStatus createdAt updatedAt parties",
}
}, { select: "requestNo type status blameStatus createdAt updatedAt" });
return requests;
);
const enriched = requests.map((req: any) => {
const party = req.parties.find(
(p: any) => String(p.person.userId) === String(user.sub)
);
const obj = req.toObject();
delete obj.parties; // remove parties completely
return {
...obj,
userSide: party?.role ?? null,
};
});
return enriched;
} catch (err) {
this.logger.error("Error: ", err);
throw new InternalServerErrorException(
"Something Went Wrong",
);
throw new InternalServerErrorException("Something Went Wrong");
}
}
/**
* V2: Get one blame request by id. Access allowed if current user is a party (by userId or phone)
* or the initiating field expert. For expert-initiated LINK, party access by phone is sufficient.