WIP
This commit is contained in:
committed by
Ulises Gascon
parent
91ba1f5054
commit
9dd233c371
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
User
|
||||
} from '../database.js'
|
||||
|
||||
const create = async (username, password, email) => {
|
||||
const user = new User({ username, password, email })
|
||||
await user.save()
|
||||
return user
|
||||
}
|
||||
|
||||
const getUserByCredentials = async (username, password) => {
|
||||
const user = await User.findOne({ username })
|
||||
if (!user) {
|
||||
throw new Error('User not found')
|
||||
}
|
||||
const isMatch = await user.comparePassword(password)
|
||||
if (!isMatch) {
|
||||
throw new Error('Password is incorrect')
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
export { create, getUserByCredentials }
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
Whisper
|
||||
} from '../database.js'
|
||||
|
||||
const getAll = () => Whisper.find().populate('author', 'username')
|
||||
const getById = id => Whisper.findById({ _id: id }).populate('author', 'username')
|
||||
const create = async (message, authorId) => {
|
||||
const whisper = new Whisper({ message, author: authorId })
|
||||
await whisper.save()
|
||||
return whisper
|
||||
}
|
||||
const updateById = async (id, message) => Whisper.findOneAndUpdate({ _id: id }, { message }, { new: false })
|
||||
const deleteById = async (id) => Whisper.deleteOne({ _id: id })
|
||||
|
||||
export { getAll, getById, create, updateById, deleteById }
|
||||
Reference in New Issue
Block a user