user.js 471 B

12345678910111213141516171819202122
  1. const User = require('./schemas/user');
  2. const findByNumber = async (number) => {
  3. return await User.findOne({ number });
  4. };
  5. const findById = async (id) => {
  6. return await User.findById(id);
  7. };
  8. const createUser = async (body) => {
  9. const user = new User({ ...body });
  10. return await user.save();
  11. };
  12. const updateUser = async (id, obj) => {
  13. return await User.updateOne({ _id: id }, { ...obj });
  14. };
  15. module.exports = {
  16. findByNumber,
  17. createUser,
  18. updateUser,
  19. findById,
  20. };