feat(recipes): add recipe visibility and sharing features

- Implemented functionality to set recipe visibility (public/private) with appropriate checks for user permissions.
- Added ability to share recipes with other users, including validation for existing users and permissions.
- Introduced new DTOs for setting visibility and sharing recipes.
- Updated RecipesController and RecipesService to handle new endpoints for visibility and sharing.
- Enhanced inventory preview to consider user permissions and shared recipes.
- Updated front-end to support new sharing and visibility features, including UI changes for recipe detail and admin user management.
This commit is contained in:
Nils-Johan Gynther
2026-05-02 09:19:59 +02:00
parent f67bf8baef
commit 41ae7d4d06
17 changed files with 742 additions and 124 deletions
+15
View File
@@ -14,6 +14,11 @@ class SetPremiumDto {
isPremium: boolean;
}
class SetRecipeSharingDto {
@IsBoolean()
canShareRecipes: boolean;
}
class AdminCreateUserDto {
@IsString()
@MinLength(2)
@@ -113,6 +118,16 @@ export class UsersController {
return { id: updated.id, username: updated.username, isPremium: updated.isPremium };
}
@Roles('admin')
@Patch(':id/recipe-sharing')
async setRecipeSharing(
@Param('id', ParseIntPipe) id: number,
@Body() dto: SetRecipeSharingDto,
) {
const updated = await this.usersService.setRecipeSharing(id, dto.canShareRecipes);
return { id: updated.id, username: updated.username, canShareRecipes: updated.canShareRecipes };
}
@Roles('admin')
@Post()
async adminCreateUser(
+15 -1
View File
@@ -25,7 +25,17 @@ export class UsersService {
findAll() {
return this.prisma.user.findMany({
select: { id: true, username: true, email: true, firstName: true, lastName: true, role: true, isPremium: true, createdAt: true },
select: {
id: true,
username: true,
email: true,
firstName: true,
lastName: true,
role: true,
isPremium: true,
canShareRecipes: true,
createdAt: true,
},
orderBy: { username: 'asc' },
});
}
@@ -38,6 +48,10 @@ export class UsersService {
return this.prisma.user.update({ where: { id }, data: { isPremium } });
}
setRecipeSharing(id: number, canShareRecipes: boolean) {
return this.prisma.user.update({ where: { id }, data: { canShareRecipes } });
}
async adminCreate(data: { username: string; email: string; password: string; role?: string }) {
const existing = await this.prisma.user.findFirst({
where: { OR: [{ username: data.username }, { email: data.email }] },