-
Notifications
You must be signed in to change notification settings - Fork 0
/
radstaskCremainingTestDataInsertions.mongo.js
executable file
·198 lines (155 loc) · 4.06 KB
/
radstaskCremainingTestDataInsertions.mongo.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env mongo
// create all additional reqd sample data
// gather exisiting ObjectId(s) for
// user - test.student
// user - test.faculty
// student - test.student
// faculty - test.faculty
// school - Management
// programme - BBA
var testStudentUserObjectId = db.users.findOne({
username: 'test.student'
})._id, testFacultyUserObjectId = db.users.findOne({
username: 'test.faculty'
})._id
var testStudentStudentObjectId = db.students.findOne({
user: testStudentUserObjectId
})._id, testFacultyFacultyObjectId = db.faculties.findOne({
user: testFacultyUserObjectId
})._id
var somSchoolObjectId = db.schools.findOne({
name: 'Management'
})._id, bbaProgrammeObjectId = db.programmes.findOne({
name: 'BBA'
})._id
// create objectIds array
var objectIds = [testStudentUserObjectId,
testStudentStudentObjectId,
bbaProgrammeObjectId,
somSchoolObjectId,
undefined,
testFacultyFacultyObjectId,
testFacultyUserObjectId,
]
// required is a total of 14 objectIds
// use new ObjectId() wherever required
const refsTotal = 14
objectIds[refsTotal] = undefined
const refs = objectIds.map((objectId) => (objectId == undefined) ? new ObjectId() : objectId)
// new objects that are to be inserted with appropriate ObjectId(s) wherever required (for reference)
var newSemester = {
_id: refs[4],
number: 1,
programme: refs[2],
session: refs[7],
course: [
refs[8],
refs[9]
]
}
var newSession = {
_id: refs[7],
code: "2018-19"
}
var newEngCourse = {
_id: refs[8],
code: "ENG1512",
name: "English II",
credits: 2,
programme: refs[2]
}
var newItmCourse = {
_id: refs[9],
code: "ITM1002",
name: "Information Systems",
credits: 3,
programme: refs[2]
}
var newNotice = {
dateTime: new Date(),
content: "A sample notice that is only intended for SoM students.",
school: refs[3]
}
var newNotice2 = {
dateTime: new Date(),
content: "A sample notice that is only intended for ITM1002 students.",
courses: [
refs[9]
]
}
var newCourseMaterial = {
richText: null,
document: refs[10],
publishDate: new Date(),
course: refs[9],
publishFaculty: refs[5]
}
var newDocument = {
_id: refs[10],
content: null,
mimeType: 'application/pdf'
}
var newDocument2 = {
_id: refs[11],
content: null,
mimeType: 'image/png'
}
var newItmAssignment = {
_id: refs[12],
course: refs[9],
publishDate: new Date(),
submitDate: new Date(),
document: refs[11]
}
var newAssignmentSubmission = {
assignment: refs[12],
submitDateTime: new Date(),
student: refs[1]
}
var newGrade = {
_id: refs[13],
marksObtained: 50,
maximumMarks: 60
}
var newAssignmentGrade = {
assignment: refs[12],
grade: refs[13],
student: refs[1],
byFaculty: refs[5]
}
// insert the objects
db.sessions.insertOne(newSession)
db.semesters.insertOne(newSemester)
db.courses.insertOne(newEngCourse)
db.courses.insertOne(newItmCourse)
db.notices.insertOne(newNotice)
db.notices.insertOne(newNotice2)
db.courseMaterials.insertOne(newCourseMaterial)
db.documents.insertOne(newDocument)
db.documents.insertOne(newDocument2)
db.assignments.insertOne(newItmAssignment)
db.assignmentSubmissions.insertOne(newAssignmentSubmission)
db.grades.insertOne(newGrade)
db.assignmentGrades.insertOne(newAssignmentGrade)
// update objects for
// student - test.student
// update keys semesters, currentSemester with necessary ObjectId
// faculty - test.faculty
// update key currentSession with necessary ObjectId
var testStudentStudent = db.students.findOne({
_id: testStudentStudentObjectId
})
var testFacultyFaculty = db.faculties.findOne({
_id: testFacultyFacultyObjectId
})
testStudentStudent.semesters = [
refs[4]
]
testStudentStudent.currentSemester = refs[4]
db.students.update({
_id: testStudentStudentObjectId
}, testStudentStudent)
testFacultyFaculty.currentSession = refs[7]
db.faculties.update({
_id: testFacultyFacultyObjectId
}, testFacultyFaculty)