studentService.js 602 B

123456789101112131415161718192021222324
  1. const Student = require('../models/student');
  2. class StudentService {
  3. static async getAll(filter) {
  4. return Student.find(filter);
  5. }
  6. static async findOne(filter) {
  7. return Student.findOne(filter);
  8. }
  9. static async create(StudentData) {
  10. StudentService.validateModel(StudentData);
  11. return new Student(StudentData).save();
  12. }
  13. static validateModel(data) {
  14. const student = new Student(data);
  15. const validation = student.validateSync();
  16. if (validation)
  17. throw validation.errors
  18. }
  19. }
  20. module.exports = StudentService;