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 }
}),
this.tagService.getInUseByUser(id)
this.tagService.getTagsForUser(id)
]);
const access = accessesResult[0];
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) {
return this.prismaService.tag.findMany({
public async getTagsForUser(userId: string) {
const tags = await this.prismaService.tag.findMany({
orderBy: {
name: 'asc'
},
where: {
OR: [
{
orders: {
some: {
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