Initial commit: NestJS NextJS pnpm monorepo

This commit is contained in:
Marco_205 committed 2026-10-12 07:20:37 +00:00
commit 610dcf202b
175 files changed
+25172

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User } from './entities/user.entity';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
@Injectable()
export class UsersService {
constructor(@InjectModel(User.name) private userModel: Model<User>) { }
async create(createUserDto: CreateUserDto) {
const createdUser = new this.userModel(createUserDto);
return createdUser.save();
}
async findAll() {
return this.userModel.find().exec();
}
async findOne(id: string) {
const user = await this.userModel.findById(id).exec();
if (!user) throw new NotFoundException(`User ${id} not found`);
return user;
}
async update(id: string, updateUserDto: UpdateUserDto) {
const updatedUser = await this.userModel
.findByIdAndUpdate(id, updateUserDto, { new: true })
.exec();
if (!updatedUser) throw new NotFoundException(`User ${id} not found`);
return updatedUser;
}
async remove(id: string):Promise<void> {
const result = await this.userModel.findByIdAndDelete(id).exec();
if (!result) throw new NotFoundException(`User ${id} not found`);
}
}