Browse Source

Change tags in user endpoint

pull/3859/head
Matej Gerek 11 months ago
committed by Thomas Kaul
parent
commit
4e4ef30e89
  1. 2
      apps/api/src/app/user/user.service.ts
  2. 27
      apps/api/src/services/tag/tag.service.ts

2
apps/api/src/app/user/user.service.ts

@ -70,7 +70,7 @@ export class UserService {
}, },
where: { userId: id } where: { userId: id }
}), }),
this.tagService.getInUseByUser(id) this.tagService.getTagsForUser(id)
]); ]);
const access = accessesResult[0]; const access = accessesResult[0];
const firstActivity = accessesResult[1]; const firstActivity = accessesResult[1];

27
apps/api/src/services/tag/tag.service.ts

@ -17,18 +17,41 @@ export class TagService {
}); });
} }
public async getInUseByUser(userId: string) { public async getTagsForUser(userId: string) {
return this.prismaService.tag.findMany({ const tags = await this.prismaService.tag.findMany({
orderBy: { orderBy: {
name: 'asc' name: 'asc'
}, },
where: { where: {
OR: [
{
orders: { orders: {
some: { some: {
userId userId
} }
} }
},
{
userId: null
}
]
},
include: {
orders: {
where: {
userId
},
select: {
id: true
}
}
} }
}); });
return tags.map((tag) => ({
...tag,
isUsed: tag.orders.length > 0,
orders: undefined
}));
} }
} }

Loading…
Cancel
Save