MAJOR UPPDATE: "First Ai"
feat: add AI categorization for products and enhance user management - Integrated AI service for category suggestions in receipt import and product management. - Added premium subscription feature for users with corresponding API endpoints. - Implemented admin interface for managing pending product suggestions. - Enhanced user management to include premium status and corresponding UI updates. - Updated database schema to support new fields for premium status and product status.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Controller, Get, Patch, Post, Delete, Body, Param, ParseIntPipe, BadRequestException } from '@nestjs/common';
|
||||
import { IsEmail, IsIn, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
import { IsBoolean, IsEmail, IsIn, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
import { UsersService } from './users.service';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
@@ -9,6 +9,11 @@ class SetRoleDto {
|
||||
role: string;
|
||||
}
|
||||
|
||||
class SetPremiumDto {
|
||||
@IsBoolean()
|
||||
isPremium: boolean;
|
||||
}
|
||||
|
||||
class AdminCreateUserDto {
|
||||
@IsString()
|
||||
@MinLength(2)
|
||||
@@ -98,6 +103,16 @@ export class UsersController {
|
||||
return { id: updated.id, username: updated.username, role: updated.role };
|
||||
}
|
||||
|
||||
@Roles('admin')
|
||||
@Patch(':id/premium')
|
||||
async setPremium(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() dto: SetPremiumDto,
|
||||
) {
|
||||
const updated = await this.usersService.setPremium(id, dto.isPremium);
|
||||
return { id: updated.id, username: updated.username, isPremium: updated.isPremium };
|
||||
}
|
||||
|
||||
@Roles('admin')
|
||||
@Post()
|
||||
async adminCreateUser(
|
||||
|
||||
@@ -25,7 +25,7 @@ export class UsersService {
|
||||
|
||||
findAll() {
|
||||
return this.prisma.user.findMany({
|
||||
select: { id: true, username: true, email: true, firstName: true, lastName: true, role: true, createdAt: true },
|
||||
select: { id: true, username: true, email: true, firstName: true, lastName: true, role: true, isPremium: true, createdAt: true },
|
||||
orderBy: { username: 'asc' },
|
||||
});
|
||||
}
|
||||
@@ -34,6 +34,10 @@ export class UsersService {
|
||||
return this.prisma.user.update({ where: { id }, data: { role } });
|
||||
}
|
||||
|
||||
setPremium(id: number, isPremium: boolean) {
|
||||
return this.prisma.user.update({ where: { id }, data: { isPremium } });
|
||||
}
|
||||
|
||||
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 }] },
|
||||
|
||||
Reference in New Issue
Block a user