fix: Managed children event listing for organization members (#13722)

* Fetch event-types by userId for childEvents and filter out those events that dont belong to the user

* Add test
This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-02-16 09:32:05 -03:00
1 parent 36747988e6
commit f29f6632e8
2 files changed
+30 -3

No files matched your search

+20 -2
View File
@@ -88,7 +88,7 @@ export class EventTypeRepository {
}
static async findAllByUpId(
{ upId }: { upId: string },
{ upId, userId }: { upId: string; userId: number },
{
orderBy,
where = {},
@@ -156,6 +156,13 @@ export class EventTypeRepository {
{
profileId,
},
// Fetch children event-types by userId because profileId is wrong
{
userId,
parentId: {
not: null,
},
},
],
...where,
},
@@ -165,7 +172,18 @@ export class EventTypeRepository {
} else {
return await prisma.eventType.findMany({
where: {
profileId,
OR: [
{
profileId,
},
// Fetch children event-types by userId because profileId is wrong
{
userId: userId,
parentId: {
not: null,
},
},
],
...where,
},
select,
@@ -65,6 +65,7 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>
? EventTypeRepository.findAllByUpId(
{
upId: lightProfile.upId,
userId: ctx.user.id,
},
{
where: {
@@ -131,7 +132,15 @@ export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) =>
),
});
const userEventTypes = await Promise.all(profileEventTypes.map(mapEventType));
const userEventTypes = (await Promise.all(profileEventTypes.map(mapEventType))).filter((eventType) => {
const isAChildEvent = eventType.parentId;
// A child event only has one user
const childEventAssignee = eventType.users[0];
if (isAChildEvent && childEventAssignee.id != ctx.user.id) {
return false;
}
return true;
});
type EventTypeGroup = {
teamId?: number | null;