-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.js
117 lines (99 loc) · 4 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var Student=require('./models/students.js');
var Company=require('./models/companies.js');
var CompanyStudentRelation=require('./models/companyStudentRelation.js');
function registerCompany(company){
return Company.create({
name: company.name,
position: company.position,
package: company.package,
location: company.location
});
}
function unregisterCompany(companyId){
return Company.remove({_id: companyId});
}
function removeRelationCompany(companyId){
return CompanyStudentRelation.remove({company: companyId});
}
function registerStudent(companyId,studentId){
return CompanyStudentRelation.create({
company: companyId,
student: studentId
});
}
function unregisterStudent(companyId,studentId){
return CompanyStudentRelation.remove({company: companyId, student: studentId});
}
function removeStudent(studentId){
return Student.remove({_id: studentId});
}
function removeRelationStudent(studentId){
return CompanyStudentRelation.remove({student: studentId});
}
function addStudent(student){
return Student.create({
name: student.name,
department: student.department,
rollNo: student.rollNo,
cgpa: student.cgpa
});
}
function getCompanies(){
return Company.find({});
}
function getAllStudents(){
return Student.find({});
}
function getStudentsByCompany(id){
return CompanyStudentRelation.find({company: id}).populate('student');
}
function getStudentIdByRollNo(rollNo){
return Student.findOne({rollNo: rollNo});
}
function findRelation(companyId,studentId){
return CompanyStudentRelation.findOne({company: companyId,student: studentId});
}
function getStudentById(studentId){
return Student.findById(studentId);
}
function getCompanyById(companyId){
return Company.findById(companyId);
}
function editStudent(student){
return Student.findByIdAndUpdate(student.id,
{
name: student.name,
department: student.department,
rollNo: student.rollNo,
cgpa: student.cgpa
});
}
function editCompany(company){
return Company.findByIdAndUpdate(company._id,
{
name: company.name,
department: company.position,
rollNo: company.package,
cgpa: company.location
});
}
//in case of returned promise, instead of err,doc...then(doc),catch(err) should be used
module.exports={ //all return an err as first argument
registerCompany, //returns promise with created doc
unregisterCompany, //returns query with nothing
removeRelationCompany, //returns query with nothing
registerStudent, //returns promise with created doc
unregisterStudent, //returns query with nothing
removeStudent, //returns query with nothing
removeRelationStudent, //returns query with nothing
addStudent, //returns promise with created doc
getCompanies, //returns query with an array of docs
getAllStudents, //returns query with an array of docs
getStudentsByCompany, //returns query with array of docs
getStudentIdByRollNo, //returns query with found doc
findRelation, //returns query with found doc
getStudentById, //returns query with found doc
getCompanyById, //returns query with found doc
editStudent, //returns query with found doc
editCompany //returns query with found doc
}