|
@ -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 |
|
|
|
|
|
})); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|