forked from Yara724/api
Merge pull request 'update the user side from the list of the user requests' (#13) from s.hajizadeh/yara724api:main into main
Reviewed-on: Yara724/api#13
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user