feat: backend API NestJS + Prisma + JWT auth + todos los módulos
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Controller, Get, Patch, Param, Body, UseGuards, Req } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { UsersService } from './users.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
|
||||
@ApiTags('Users')
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private users: UsersService) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
findAll() {
|
||||
return this.users.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
findById(@Param('id') id: string) {
|
||||
return this.users.findById(id);
|
||||
}
|
||||
|
||||
@Patch('me')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
update(@Req() req, @Body() data: any) {
|
||||
return this.users.update(req.user.sub, data);
|
||||
}
|
||||
|
||||
@Patch('fcm-token')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
updateFcmToken(@Req() req, @Body() dto: { token: string }) {
|
||||
return this.users.updateFcmToken(req.user.sub, dto.token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { UsersController } from './users.controller';
|
||||
|
||||
@Module({
|
||||
providers: [UsersService],
|
||||
controllers: [UsersController],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
findAll() {
|
||||
return this.prisma.users.findMany({ orderBy: { created_at: 'desc' } });
|
||||
}
|
||||
|
||||
findById(id: string) {
|
||||
return this.prisma.users.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
professionals: { include: { schedules: true, specializations: true } },
|
||||
reputations: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
update(id: string, data: any) {
|
||||
return this.prisma.users.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
updateFcmToken(id: string, fcm_token: string) {
|
||||
return this.prisma.users.update({ where: { id }, data: { fcm_token } });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user