-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CreateUserDto } from '../types/CreateUserDto' | ||
import { IUser } from '../types/IUser' | ||
import { UserDto } from '../types/UserDto' | ||
import userModel from './user.model' | ||
|
||
export async function findAllUsers(): Promise<IUser[]> { | ||
return userModel.find() | ||
} | ||
|
||
export async function findOneUserById(id: string): Promise<IUser | null> { | ||
return userModel.findById(id) | ||
} | ||
|
||
export async function findOneUserByUsername(username: string): Promise<IUser | null> { | ||
return userModel.findOne({ username }) | ||
} | ||
|
||
export async function findOneUserByEmail(email: string): Promise<IUser | null> { | ||
return userModel.findOne({ email }) | ||
} | ||
|
||
export async function createUser(dto: CreateUserDto): Promise<IUser> { | ||
return userModel.create(dto) | ||
} | ||
|
||
export async function updateUser(id: string, dto: UserDto): Promise<IUser | null> { | ||
return userModel.findByIdAndUpdate(id, dto, { new: true }) | ||
} | ||
|
||
export async function deleteUser(id: string): Promise<void> { | ||
await userModel.findByIdAndDelete(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters