-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from schulcloud/master
Release v0.3.0 Crystallite
- Loading branch information
Showing
127 changed files
with
3,894 additions
and
1,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,69 @@ | ||
import { Permissions, Server } from '../../core/helpers/'; | ||
|
||
const classService = Server.service('/classes'); | ||
const courseService = Server.service('/courses'); | ||
const schoolService = Server.service('/schools'); | ||
const userService = Server.service('/users'); | ||
const classService = Server.service('/classes'); | ||
|
||
export default { | ||
updateSchool: (schoolId, data) => { | ||
schoolService.patch(schoolId, data); | ||
}, | ||
|
||
|
||
updateCourse: (data) => { | ||
if(data._id) return courseService.update(data._id, data); | ||
|
||
return courseService.create(data); | ||
}, | ||
|
||
removeCourse: (data) => { | ||
return courseService.remove(data._id); | ||
}, | ||
|
||
const indexArrayByKey = (array, key) => { | ||
const result = {}; | ||
array.forEach((obj) => { | ||
result[obj[key]] = obj; | ||
}); | ||
return result; | ||
}; | ||
|
||
updateClass: (data) => { | ||
if(data._id) return classService.update(data._id, data); | ||
export default { | ||
|
||
return classService.create(data); | ||
loadContent: (serviceName, query) => { | ||
const service = Server.service(serviceName); | ||
return service.find({query}) | ||
.then(result => { | ||
return Promise.resolve({ | ||
records: indexArrayByKey(result.data, '_id'), | ||
pagination: {total: result.total, skip: result.skip} | ||
}); | ||
}); | ||
}, | ||
|
||
removeClass: (data) => { | ||
return classService.remove(data._id); | ||
updateRecord: (serviceName, data) => { | ||
const service = Server.service(serviceName); | ||
if(data._id) return service.patch(data._id, data); | ||
return service.create(data); | ||
}, | ||
|
||
|
||
updateStudent: (data) => { | ||
if(data._id) return userService.update(data._id, data); | ||
|
||
return userService.create(data); | ||
removeRecord: (serviceName, data) => { | ||
const id = data._id; | ||
if(!id) throw new Error("_id not set!"); | ||
const service = Server.service(serviceName); | ||
return service.remove(id); | ||
}, | ||
|
||
removeStudent: (data) => { | ||
return userService.remove(data._id); | ||
populateFields: (serviceName, _id, fields) => { | ||
const service = Server.service(serviceName); | ||
return service.find({query: { | ||
_id, | ||
$populate: fields | ||
}}) | ||
.then(result => Promise.resolve(result.data[0])); | ||
}, | ||
|
||
|
||
updateTeacher: (data) => { | ||
if(data._id) return userService.update(data._id, data); | ||
|
||
return userService.create(data); | ||
_loadTeachers: (schoolId) => { | ||
return userService.find({ | ||
query: { | ||
schoolId, | ||
roles: ['teacher'], | ||
$limit: 1000 | ||
} | ||
}) | ||
.then(result => Promise.resolve(result.data)); | ||
}, | ||
|
||
removeTeacher: (data) => { | ||
return userService.remove(data._id); | ||
_loadClasses: (schoolId) => { | ||
return classService.find({ | ||
query: { | ||
schoolId, | ||
$limit: 1000 | ||
} | ||
}) | ||
.then(result => Promise.resolve(result.data)); | ||
} | ||
}; |
Oops, something went wrong.